-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_parser.py
More file actions
37 lines (26 loc) · 1.82 KB
/
Copy pathfix_parser.py
File metadata and controls
37 lines (26 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
"""
Script to fix the LIFTRangesParser to include both 'description' and 'descriptions' fields
for backward compatibility with tests.
"""
import re
def fix_lift_parser():
"""Fix the LIFTRangesParser by adding backward compatibility fields."""
# Read the file
with open('app/parsers/lift_parser.py', 'r', encoding='utf-8') as f:
content = f.read()
# Pattern 1: Find the _parse_range_element method and add backward compatibility
pattern1 = r"(element_data\['descriptions'\] = self\._parse_multilingual_content\(elem, \['description'\]\)\s*\n\n\s*# Parse child elements)"
replacement1 = r"element_data['descriptions'] = self._parse_multilingual_content(elem, ['description'])\n \n # Add backward compatibility field for tests\n element_data['description'] = element_data['descriptions'].copy()\n\n \1"
# Pattern 2: Find the _parse_range_element_full method and add backward compatibility
pattern2 = r"(element_data\['descriptions'\] = self\._parse_multilingual_content\(elem, \['description'\]\)\s*\n\n\s*# Parse abbreviation)"
replacement2 = r"element_data['descriptions'] = self._parse_multilingual_content(elem, ['description'])\n \n # Add backward compatibility field for tests\n element_data['description'] = element_data['descriptions'].copy()\n\n \1"
# Apply the fixes
content = re.sub(pattern1, replacement1, content, flags=re.MULTILINE)
content = re.sub(pattern2, replacement2, content, flags=re.MULTILINE)
# Write the updated file
with open('app/parsers/lift_parser.py', 'w', encoding='utf-8') as f:
f.write(content)
print("Successfully fixed LIFTRangesParser to include backward compatibility fields")
if __name__ == "__main__":
fix_lift_parser()