32
32
import unittest
33
33
import yaml
34
34
35
+ try :
36
+ # Try and use libyaml bindings if available since faster
37
+ from yaml import CSafeLoader as SafeLoader
38
+ except ImportError :
39
+ from yaml import SafeLoader
40
+
35
41
from ua_parser import user_agent_parser
36
42
37
43
TEST_RESOURCES_DIR = os .path .join (
@@ -113,7 +119,7 @@ def makePGTSComparisonYAML(self):
113
119
print >> outfile , "test_cases:"
114
120
115
121
yamlFile = open (os .path .join (TEST_RESOURCES_DIR , "pgts_browser_list.yaml" ))
116
- yamlContents = yaml .load (yamlFile )
122
+ yamlContents = yaml .load (yamlFile , Loader = SafeLoader )
117
123
yamlFile .close ()
118
124
119
125
for test_case in yamlContents ["test_cases" ]:
@@ -140,7 +146,7 @@ def makePGTSComparisonYAML(self):
140
146
# Run a set of test cases from a YAML file
141
147
def runUserAgentTestsFromYAML (self , file_name ):
142
148
yamlFile = open (os .path .join (TEST_RESOURCES_DIR , file_name ))
143
- yamlContents = yaml .load (yamlFile )
149
+ yamlContents = yaml .load (yamlFile , Loader = SafeLoader )
144
150
yamlFile .close ()
145
151
146
152
for test_case in yamlContents ["test_cases" ]:
@@ -178,7 +184,7 @@ def runUserAgentTestsFromYAML(self, file_name):
178
184
179
185
def runOSTestsFromYAML (self , file_name ):
180
186
yamlFile = open (os .path .join (TEST_RESOURCES_DIR , file_name ))
181
- yamlContents = yaml .load (yamlFile )
187
+ yamlContents = yaml .load (yamlFile , Loader = SafeLoader )
182
188
yamlFile .close ()
183
189
184
190
for test_case in yamlContents ["test_cases" ]:
@@ -218,7 +224,7 @@ def runOSTestsFromYAML(self, file_name):
218
224
219
225
def runDeviceTestsFromYAML (self , file_name ):
220
226
yamlFile = open (os .path .join (TEST_RESOURCES_DIR , file_name ))
221
- yamlContents = yaml .load (yamlFile )
227
+ yamlContents = yaml .load (yamlFile , Loader = SafeLoader )
222
228
yamlFile .close ()
223
229
224
230
for test_case in yamlContents ["test_cases" ]:
0 commit comments