diff --git a/.gitmodules b/.gitmodules index 6d61431..fd375d2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "uap-core"] path = uap-core - url = https://github.com/ua-parser/uap-core.git + url = https://github.com/ua-parser/uap-core branch = master diff --git a/.travis.yml b/.travis.yml index 3ec68a6..5780377 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,18 @@ sudo: false language: python -python: - - "3.6" - -env: - - TOX_ENV=py26 - - TOX_ENV=py27 - - TOX_ENV=py36 - - TOX_ENV=docs - - TOX_ENV=py27-flake8 - - TOX_ENV=py36-flake8 - install: - - pip install tox + - pip install -r requirements_dev.txt + +matrix: + include: + - python: 2.7 + env: + - TOX_ENV=py27 + - TOX_ENV=py27-flake8 + - python: 3.6 + env: + - TOX_ENV=py36 + - TOX_ENV=py36-flake8 + - TOX_ENV=docs -script: - - tox -e $TOX_ENV +script: tox -e $TOX_ENV diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6c05a61 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pyyaml==5.1 diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000..eb111cc --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1 @@ +tox==3.9.0 diff --git a/tox.ini b/tox.ini index cfce717..479012c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,9 @@ [tox] -envlist = py26, py27, py36, docs, py27-flake8, py36-flake8 +envlist = py27, py36, docs, py27-flake8, py36-flake8 [testenv] deps = - pyyaml + -rrequirements.txt commands = python setup.py develop python ua_parser/user_agent_parser_test.py diff --git a/ua_parser/user_agent_parser.py b/ua_parser/user_agent_parser.py index 68824cf..05875f2 100644 --- a/ua_parser/user_agent_parser.py +++ b/ua_parser/user_agent_parser.py @@ -61,15 +61,15 @@ def Parse(self, user_agent_string): if self.v1_replacement: v1 = self.v1_replacement elif match.lastindex and match.lastindex >= 2: - v1 = match.group(2) + v1 = match.group(2) or None if self.v2_replacement: v2 = self.v2_replacement elif match.lastindex and match.lastindex >= 3: - v2 = match.group(3) + v2 = match.group(3) or None if match.lastindex and match.lastindex >= 4: - v3 = match.group(4) + v3 = match.group(4) or None return family, v1, v2, v3 @@ -125,17 +125,26 @@ def Parse(self, user_agent_string): os_v1 = match.group(2) if self.os_v2_replacement: - os_v2 = self.os_v2_replacement + if re.search(r'\$2', self.os_v2_replacement): + os_v2 = re.sub(r'\$2', match.group(2), self.os_v2_replacement) + else: + os_v2 = self.os_v2_replacement elif match.lastindex and match.lastindex >= 3: os_v2 = match.group(3) if self.os_v3_replacement: - os_v3 = self.os_v3_replacement + if re.search(r'\$3', self.os_v3_replacement): + os_v3 = re.sub(r'\$3', match.group(3), self.os_v3_replacement) + else: + os_v3 = self.os_v3_replacement elif match.lastindex and match.lastindex >= 4: os_v3 = match.group(4) if self.os_v4_replacement: - os_v4 = self.os_v4_replacement + if re.search(r'\$4', self.os_v4_replacement): + os_v4 = re.sub(r'\$4', match.group(4), self.os_v4_replacement) + else: + os_v4 = self.os_v4_replacement elif match.lastindex and match.lastindex >= 5: os_v4 = match.group(5) diff --git a/uap-core b/uap-core index fc570f3..71ec72c 160000 --- a/uap-core +++ b/uap-core @@ -1 +1 @@ -Subproject commit fc570f378e41063bad3bdf0532967743efc75b4b +Subproject commit 71ec72cd37a940683cd40af3f7ab738ecbdcc45b