|
32 | 32 | DATA_DIR = os.path.abspath(os.path.join(ROOT_DIR, '..', 'data'))
|
33 | 33 | regex_dir = ROOT_DIR if os.path.exists(os.path.join(ROOT_DIR, 'regexes.yaml')) else DATA_DIR
|
34 | 34 |
|
| 35 | +from pkg_resources import resource_filename |
| 36 | + |
35 | 37 |
|
36 | 38 | class UserAgentParser(object):
|
37 | 39 | def __init__(self, pattern, family_replacement=None, v1_replacement=None):
|
@@ -165,10 +167,10 @@ def Parse(user_agent_string, **jsParseBits):
|
165 | 167 | """
|
166 | 168 | jsParseBits = jsParseBits or {}
|
167 | 169 | 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 |
172 | 174 | }
|
173 | 175 |
|
174 | 176 |
|
@@ -251,7 +253,7 @@ def ParseDevice(user_agent_string):
|
251 | 253 | break
|
252 | 254 |
|
253 | 255 | return {
|
254 |
| - 'family': device |
| 256 | + 'family': device |
255 | 257 | }
|
256 | 258 |
|
257 | 259 |
|
@@ -386,8 +388,8 @@ def GetFilters(user_agent_string, js_user_agent_string=None,
|
386 | 388 | regexes = None
|
387 | 389 |
|
388 | 390 | 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') |
391 | 393 | else:
|
392 | 394 | yamlFile = open(UA_PARSER_YAML)
|
393 | 395 | regexes = yaml.load(yamlFile)
|
|
0 commit comments