Permalink
Browse files

Dropping b() and u() in favor of unicode_literals. Thanks to Mikhail …

…Korobov (@kmike)!
  • Loading branch information...
1 parent 641f592 commit 4a07b200a4d7124d98590fc237cecf306be46ed9 @isagalaev committed Oct 26, 2012
Showing with 15 additions and 18 deletions.
  1. +1 −7 ijson/compat.py
  2. +14 −11 tests.py
View
@@ -9,13 +9,7 @@
if IS_PY2:
- def u(s):
- return s.decode('utf-8')
- b = lambda s: s
- b2s = b
+ b2s = lambda s: s
else:
- u = lambda s: s
- def b(s):
- return s.encode('utf-8')
def b2s(b):
return b.decode('utf-8')
View
@@ -1,4 +1,5 @@
# -*- coding:utf-8 -*-
+from __future__ import unicode_literals
import unittest
from io import BytesIO
from decimal import Decimal
@@ -7,10 +8,10 @@
from ijson import common
from ijson.backends.python import basic_parse
-from ijson.compat import u, b
+from ijson.compat import IS_PY2
-JSON = b(r'''
+JSON = br'''
{
"docs": [
{
@@ -33,19 +34,19 @@
}
]
}
-''')
-SCALAR_JSON = b('0')
-EMPTY_JSON = b('')
-INVALID_JSON = b('{"key": "value",}')
-INCOMPLETE_JSON = b('"test')
-STRINGS_JSON = b(r'''
+'''
+SCALAR_JSON = b'0'
+EMPTY_JSON = b''
+INVALID_JSON = b'{"key": "value",}'
+INCOMPLETE_JSON = b'"test'
+STRINGS_JSON = br'''
{
"str1": "",
"str2": "\"",
"str3": "\\",
"str4": "\\\\"
}
-''')
+'''
class Parse(object):
'''
@@ -60,7 +61,7 @@ def test_basic_parse(self):
('start_array', None),
('start_map', None),
('map_key', 'string'),
- ('string', u('строка')),
+ ('string', 'строка'),
('map_key', 'null'),
('null', None),
('map_key', 'boolean'),
@@ -142,6 +143,8 @@ def test_lazy(self):
for name in ['python', 'yajl', 'yajl2']:
try:
classname = '%sParse' % name.capitalize()
+ if IS_PY2:
+ classname = classname.encode('ascii')
locals()[classname] = type(
classname,
(unittest.TestCase, Parse),
@@ -162,7 +165,7 @@ def test_object_builder(self):
self.assertEqual(builder.value, {
'docs': [
{
- 'string': u('строка'),
+ 'string': 'строка',
'null': None,
'boolean': False,
'integer': 0,

0 comments on commit 4a07b20

Please sign in to comment.