Skip to content

Upgrade ua-parser version to 1.0.0 #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
ua-parser==0.10.0
PyYAML==5.4; python_version != '3.4'
PyYAML==5.4; python_version == '3.4' # the last version support py34
ua-parser==1.0.0
PyYAML==5.4
14 changes: 6 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,20 @@
zip_safe=False,
include_package_data=True,
package_data={'': ['README.rst']},
install_requires=['ua-parser>=0.10.0'],
install_requires=['ua-parser>=1.0.0'],
python_requires='>=3.9',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Software Development :: Libraries :: Python Modules',
]
Expand Down
14 changes: 0 additions & 14 deletions user_agents/compat.py

This file was deleted.

16 changes: 6 additions & 10 deletions user_agents/parsers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collections import namedtuple

from ua_parser import user_agent_parser
from .compat import string_types
from ua_parser import parser


MOBILE_DEVICE_FAMILIES = (
Expand Down Expand Up @@ -93,7 +92,7 @@
))

def verify_attribute(attribute):
if isinstance(attribute, string_types) and attribute.isdigit():
if isinstance(attribute, str) and attribute.isdigit():
return int(attribute)

return attribute
Expand Down Expand Up @@ -140,11 +139,11 @@ def parse_device(family, brand, model):
class UserAgent(object):

def __init__(self, user_agent_string):
ua_dict = user_agent_parser.Parse(user_agent_string)
ua = parser.parse(user_agent_string).with_defaults()
self.ua_string = user_agent_string
self.os = parse_operating_system(**ua_dict['os'])
self.browser = parse_browser(**ua_dict['user_agent'])
self.device = parse_device(**ua_dict['device'])
self.os = parse_operating_system(ua.os.family, ua.os.major, ua.os.minor, ua.os.patch)
self.browser = parse_browser(ua.user_agent.family, ua.user_agent.major, ua.user_agent.minor, ua.user_agent.patch)
self.device = parse_device(ua.device.family, ua.device.brand, ua.device.model)

def __str__(self):
return "{device} / {os} / {browser}".format(
Expand All @@ -153,9 +152,6 @@ def __str__(self):
browser=self.get_browser()
)

def __unicode__(self):
return unicode(str(self))

def _is_android_tablet(self):
# Newer Android tablets don't have "Mobile" in their user agent string,
# older ones like Galaxy Tab still have "Mobile" though they're not
Expand Down
16 changes: 3 additions & 13 deletions user_agents/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import unittest

from ua_parser import user_agent_parser
from . import compat
from .parsers import parse


Expand Down Expand Up @@ -242,17 +241,8 @@ def test_strings(self):
self.assertEqual(str(android_firefox_aurora_ua), "Generic Smartphone / Android / Firefox Mobile 27.0")

def test_unicode_strings(self):
try:
# Python 2
unicode_ua_str = unicode(devices['iphone']['user_agent'])
self.assertEqual(unicode_ua_str,
u"iPhone / iOS 5.1 / Mobile Safari 5.1")
self.assertTrue(isinstance(unicode_ua_str, unicode))
except NameError:
# Python 3
unicode_ua_str = str(devices['iphone']['user_agent'])
self.assertEqual(unicode_ua_str,
"iPhone / iOS 5.1 / Mobile Safari 5.1")
unicode_ua_str = str(devices['iphone']['user_agent'])
self.assertEqual(unicode_ua_str, "iPhone / iOS 5.1 / Mobile Safari 5.1")


with open(os.path.join(os.path.dirname(__file__), 'devices.json')) as f:
Expand All @@ -271,6 +261,6 @@ def test_func(self):
# self.assertEqual(str(items['user_agent']), items['str'])
return test_func

for device, items in compat.iteritems(devices):
for device, items in devices.items():
items['user_agent'] = parse(items['ua_string'])
setattr(UserAgentsTest, 'test_' + device, test_wrapper(items))