@@ -169,7 +169,7 @@ def _repl(m):
169
169
if index < len (group ):
170
170
return group [index ]
171
171
return ''
172
-
172
+
173
173
_string = re .sub (r'\$(\d)' , _repl , string )
174
174
_string = re .sub (r'^\s+|\s+$' , '' , _string )
175
175
if _string == '' :
@@ -179,7 +179,7 @@ def _repl(m):
179
179
def Parse (self , user_agent_string ):
180
180
device , brand , model = None , None , None
181
181
match = self .user_agent_re .search (user_agent_string )
182
- if match :
182
+ if match :
183
183
if self .device_replacement :
184
184
device = self .MultiReplace (self .device_replacement , match )
185
185
else :
@@ -442,9 +442,9 @@ def GetFilters(user_agent_string, js_user_agent_string=None,
442
442
else :
443
443
import yaml
444
444
445
- yamlFile = open (UA_PARSER_YAML )
446
- regexes = yaml .load (yamlFile )
447
- yamlFile . close ()
445
+ with open (UA_PARSER_YAML ) as yamlFile :
446
+ regexes = yaml .safe_load (yamlFile )
447
+
448
448
449
449
# If UA_PARSER_YAML is not specified, load regexes from regexes.json before
450
450
# falling back to yaml format
@@ -458,7 +458,7 @@ def GetFilters(user_agent_string, js_user_agent_string=None,
458
458
import yaml
459
459
460
460
with open (yamlPath ) as fp :
461
- regexes = yaml .load (fp )
461
+ regexes = yaml .safe_load (fp )
462
462
463
463
464
464
USER_AGENT_PARSERS = []
0 commit comments