Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 898cf81

Browse files
committed
Always use yaml SafeLoader
1 parent c007bdc commit 898cf81

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

ua_parser/user_agent_parser_test.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
import unittest
3333
import yaml
3434

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+
3541
from ua_parser import user_agent_parser
3642

3743
TEST_RESOURCES_DIR = os.path.join(
@@ -113,7 +119,7 @@ def makePGTSComparisonYAML(self):
113119
print >> outfile, "test_cases:"
114120

115121
yamlFile = open(os.path.join(TEST_RESOURCES_DIR, "pgts_browser_list.yaml"))
116-
yamlContents = yaml.load(yamlFile)
122+
yamlContents = yaml.load(yamlFile, Loader=SafeLoader)
117123
yamlFile.close()
118124

119125
for test_case in yamlContents["test_cases"]:
@@ -140,7 +146,7 @@ def makePGTSComparisonYAML(self):
140146
# Run a set of test cases from a YAML file
141147
def runUserAgentTestsFromYAML(self, file_name):
142148
yamlFile = open(os.path.join(TEST_RESOURCES_DIR, file_name))
143-
yamlContents = yaml.load(yamlFile)
149+
yamlContents = yaml.load(yamlFile, Loader=SafeLoader)
144150
yamlFile.close()
145151

146152
for test_case in yamlContents["test_cases"]:
@@ -178,7 +184,7 @@ def runUserAgentTestsFromYAML(self, file_name):
178184

179185
def runOSTestsFromYAML(self, file_name):
180186
yamlFile = open(os.path.join(TEST_RESOURCES_DIR, file_name))
181-
yamlContents = yaml.load(yamlFile)
187+
yamlContents = yaml.load(yamlFile, Loader=SafeLoader)
182188
yamlFile.close()
183189

184190
for test_case in yamlContents["test_cases"]:
@@ -218,7 +224,7 @@ def runOSTestsFromYAML(self, file_name):
218224

219225
def runDeviceTestsFromYAML(self, file_name):
220226
yamlFile = open(os.path.join(TEST_RESOURCES_DIR, file_name))
221-
yamlContents = yaml.load(yamlFile)
227+
yamlContents = yaml.load(yamlFile, Loader=SafeLoader)
222228
yamlFile.close()
223229

224230
for test_case in yamlContents["test_cases"]:

0 commit comments

Comments
 (0)