Skip to content

Commit b004ea0

Browse files
committed
Added unicode support, version bump
1 parent 0a64e98 commit b004ea0

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎README.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Changelog
142142

143143
Version 0.3.0
144144
-------------
145-
* Added __str__ method for convenience of pretty string
145+
* Added __str__/__unicode__ methods for convenience of pretty string
146146

147147
Version 0.2.0
148148
-------------

‎user_agents/parsers.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ def __str__(self):
111111
os = ("%s %s" % (self.os.family, self.os.version_string)).strip()
112112
browser = ("%s %s" % (self.browser.family, self.browser.version_string)).strip()
113113
return " / ".join([device, os, browser])
114-
114+
115+
def __unicode__(self):
116+
return unicode(str(self))
117+
115118
def _is_android_tablet(self):
116119
# Newer Android tablets don't have "Mobile" in their user agent string,
117120
# older ones like Galaxy Tab still have "Mobile" though they're not

‎user_agents/tests.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,8 @@ def test_strings(self):
200200
self.assertEqual(str(google_bot_ua), "Spider / Other / Googlebot 2.1")
201201
self.assertEqual(str(nokia_n97_ua), "Nokia N97 / Symbian OS 9.4 / Nokia Browser 7.1.12344")
202202
self.assertEqual(str(android_firefox_aurora_ua), "Other / Android / Firefox Mobile 27")
203+
204+
def test_unicode_strings(self):
205+
unicode_ua_str = unicode(iphone_ua)
206+
self.assertEqual(unicode_ua_str, u"iPhone / iOS 5.1 / Mobile Safari 5.1")
207+
self.assertTrue(isinstance(unicode_ua_str, unicode))

0 commit comments

Comments
 (0)