35
35
import urllib .request
36
36
from collections import Counter
37
37
from pathlib import Path
38
-
39
- try :
40
- import yaml
41
-
42
- HAS_YAML = True
43
- except ImportError :
44
- HAS_YAML = False
38
+ import yaml
45
39
46
40
47
41
def load_endpoint_list_from_yaml (url , endpoint_type = "endpoints" ):
@@ -60,21 +54,17 @@ def load_endpoint_list_from_yaml(url, endpoint_type="endpoints"):
60
54
with urllib .request .urlopen (url , timeout = 30 ) as response :
61
55
content = response .read ().decode ()
62
56
63
- # Parse YAML content - use PyYAML if available, otherwise manual parsing
64
- if HAS_YAML :
65
- try :
66
- yaml_data = yaml .safe_load (content )
67
- return _process_yaml_data (yaml_data , endpoint_type )
68
- except yaml .YAMLError as e :
69
- print (f"Error: Failed to parse YAML content from { url } " )
70
- print (f"YAML parsing error: { e } " )
71
- print (f"Content preview (first 500 chars):" )
72
- print (content [:500 ])
73
- print (f"Cannot proceed with malformed YAML for { endpoint_type } " )
74
- sys .exit (1 )
75
- else :
76
- print (f"Warning: PyYAML not available, using manual YAML parsing for { endpoint_type } " )
77
- return _manual_yaml_parse (content , endpoint_type )
57
+ # Parse YAML content using PyYAML
58
+ try :
59
+ yaml_data = yaml .safe_load (content )
60
+ return _process_yaml_data (yaml_data , endpoint_type )
61
+ except yaml .YAMLError as e :
62
+ print (f"Error: Failed to parse YAML content from { url } " )
63
+ print (f"YAML parsing error: { e } " )
64
+ print (f"Content preview (first 500 chars):" )
65
+ print (content [:500 ])
66
+ print (f"Cannot proceed with malformed YAML for { endpoint_type } " )
67
+ sys .exit (1 )
78
68
79
69
except urllib .error .URLError as e :
80
70
print (f"Error: Failed to download { endpoint_type } from { url } " )
@@ -121,50 +111,6 @@ def _process_yaml_data(yaml_data, endpoint_type):
121
111
return endpoints
122
112
123
113
124
- def _manual_yaml_parse (content , endpoint_type ):
125
- """
126
- Manual YAML parsing for simple structures when PyYAML is not available.
127
-
128
- Handles two formats:
129
- 1. List of objects: - endpoint: name
130
- 2. Simple list: - name
131
-
132
- Args:
133
- content (str): YAML content as string
134
- endpoint_type (str): Type of endpoints being loaded
135
-
136
- Returns:
137
- set: Set of endpoint operation IDs
138
- """
139
- endpoints = set ()
140
-
141
- for line in content .split ('\n ' ):
142
- line = line .strip ()
143
-
144
- # Skip empty lines, comments, and document separators
145
- if not line or line .startswith ('#' ) or line == '---' :
146
- continue
147
-
148
- if line .startswith ('- endpoint:' ):
149
- # Format: - endpoint: endpointName (ineligible_endpoints.yaml)
150
- endpoint = line .replace ('- endpoint:' , '' ).strip ()
151
- if endpoint :
152
- endpoints .add (endpoint )
153
- elif line .startswith ('- ' ) and ':' not in line :
154
- # Format: - endpointName (pending_eligible_endpoints.yaml)
155
- # Only if no colon (to avoid matching other object keys)
156
- endpoint = line .replace ('- ' , '' ).strip ()
157
- if endpoint :
158
- endpoints .add (endpoint )
159
-
160
- if not endpoints :
161
- print (f"Warning: No endpoints found using manual YAML parsing for { endpoint_type } " )
162
- print ("This might indicate a parsing issue or unexpected YAML format" )
163
-
164
- print (f"Loaded { len (endpoints )} { endpoint_type } (manual parsing)" )
165
- return endpoints
166
-
167
-
168
114
def load_ineligible_endpoints (ineligible_endpoints_url = None ):
169
115
"""
170
116
Load the list of ineligible endpoints from URL or local file.
0 commit comments