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

Skip to content

Commit e2b51a2

Browse files
committed
Merge branch 'master' of git://github.com/tobie/ua-parser
Conflicts: py/ua_parser/user_agent_parser.py
2 parents a540485 + 782a88f commit e2b51a2

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

ua_parser/user_agent_parser.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
DATA_DIR = os.path.abspath(os.path.join(ROOT_DIR, '..', 'data'))
3333
regex_dir = ROOT_DIR if os.path.exists(os.path.join(ROOT_DIR, 'regexes.yaml')) else DATA_DIR
3434

35+
from pkg_resources import resource_filename
36+
3537

3638
class UserAgentParser(object):
3739
def __init__(self, pattern, family_replacement=None, v1_replacement=None):
@@ -165,10 +167,10 @@ def Parse(user_agent_string, **jsParseBits):
165167
"""
166168
jsParseBits = jsParseBits or {}
167169
return {
168-
'user_agent': ParseUserAgent(user_agent_string, **jsParseBits),
169-
'os': ParseOS(user_agent_string, **jsParseBits),
170-
'device': ParseDevice(user_agent_string, **jsParseBits),
171-
'string': user_agent_string
170+
'user_agent': ParseUserAgent(user_agent_string, **jsParseBits),
171+
'os': ParseOS(user_agent_string, **jsParseBits),
172+
'device': ParseDevice(user_agent_string, **jsParseBits),
173+
'string': user_agent_string
172174
}
173175

174176

@@ -251,7 +253,7 @@ def ParseDevice(user_agent_string):
251253
break
252254

253255
return {
254-
'family': device
256+
'family': device
255257
}
256258

257259

@@ -386,8 +388,8 @@ def GetFilters(user_agent_string, js_user_agent_string=None,
386388
regexes = None
387389

388390
if not UA_PARSER_YAML:
389-
yamlPath = os.path.join(regex_dir, 'regexes.yaml')
390-
json_path = os.path.join(regex_dir, 'regexes.json')
391+
yamlPath = resource_filename(__name__, 'regexes.yaml')
392+
json_path = resource_filename(__name__, 'regexes.json')
391393
else:
392394
yamlFile = open(UA_PARSER_YAML)
393395
regexes = yaml.load(yamlFile)

0 commit comments

Comments
 (0)