summaryrefslogtreecommitdiff
path: root/devel/py-omnijson/files/patch-2to3
blob: 72fcd402ce7abdbef2306fe5a94d2e0fa2c0c249 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
--- omnijson/packages/simplejson/decoder.py.orig	2011-06-19 16:43:47 UTC
+++ omnijson/packages/simplejson/decoder.py
@@ -87,8 +87,8 @@ _CONSTANTS = {
 
 STRINGCHUNK = re.compile(r'(.*?)(["\\\x00-\x1f])', FLAGS)
 BACKSLASH = {
-    '"': u'"', '\\': u'\\', '/': u'/',
-    'b': u'\b', 'f': u'\f', 'n': u'\n', 'r': u'\r', 't': u'\t',
+    '"': '"', '\\': '\\', '/': '/',
+    'b': '\b', 'f': '\f', 'n': '\n', 'r': '\r', 't': '\t',
 }
 
 DEFAULT_ENCODING = "utf-8"
@@ -117,8 +117,8 @@ def py_scanstring(s, end, encoding=None, strict=True,
         content, terminator = chunk.groups()
         # Content is contains zero or more unescaped string characters
         if content:
-            if not isinstance(content, unicode):
-                content = unicode(content, encoding)
+            if not isinstance(content, str):
+                content = str(content, encoding)
             _append(content)
         # Terminator is the end of string, a literal control character,
         # or a backslash denoting that an escape sequence follows
@@ -164,11 +164,11 @@ def py_scanstring(s, end, encoding=None, strict=True,
                 uni2 = int(esc2, 16)
                 uni = 0x10000 + (((uni - 0xd800) << 10) | (uni2 - 0xdc00))
                 next_end += 6
-            char = unichr(uni)
+            char = chr(uni)
             end = next_end
         # Append the unescaped character
         _append(char)
-    return u''.join(chunks), end
+    return ''.join(chunks), end
 
 
 # Use speedup if available
@@ -177,10 +177,11 @@ scanstring = c_scanstring or py_scanstring
 WHITESPACE = re.compile(r'[ \t\n\r]*', FLAGS)
 WHITESPACE_STR = ' \t\n\r'
 
-def JSONObject((s, end), encoding, strict, scan_once, object_hook,
+def JSONObject(xxx_todo_changeme, encoding, strict, scan_once, object_hook,
         object_pairs_hook, memo=None,
         _w=WHITESPACE.match, _ws=WHITESPACE_STR):
     # Backwards compatibility
+    (s, end) = xxx_todo_changeme
     if memo is None:
         memo = {}
     memo_get = memo.setdefault
@@ -269,7 +270,8 @@ def JSONObject((s, end), encoding, strict, scan_once, 
         pairs = object_hook(pairs)
     return pairs, end
 
-def JSONArray((s, end), scan_once, _w=WHITESPACE.match, _ws=WHITESPACE_STR):
+def JSONArray(xxx_todo_changeme1, scan_once, _w=WHITESPACE.match, _ws=WHITESPACE_STR):
+    (s, end) = xxx_todo_changeme1
     values = []
     nextchar = s[end:end + 1]
     if nextchar in _ws:
--- omnijson/packages/simplejson/encoder.py.orig	2011-06-19 16:43:47 UTC
+++ omnijson/packages/simplejson/encoder.py
@@ -39,7 +39,7 @@ def encode_basestring(s):
         s = s.decode('utf-8')
     def replace(match):
         return ESCAPE_DCT[match.group(0)]
-    return u'"' + ESCAPE.sub(replace, s) + u'"'
+    return '"' + ESCAPE.sub(replace, s) + '"'
 
 
 def py_encode_basestring_ascii(s):
@@ -160,7 +160,7 @@ class JSONEncoder(object):
         self.allow_nan = allow_nan
         self.sort_keys = sort_keys
         self.use_decimal = use_decimal
-        if isinstance(indent, (int, long)):
+        if isinstance(indent, int):
             indent = ' ' * indent
         self.indent = indent
         if separators is not None:
@@ -200,7 +200,7 @@ class JSONEncoder(object):
 
         """
         # This is for extremely simple cases and benchmarks.
-        if isinstance(o, basestring):
+        if isinstance(o, str):
             if isinstance(o, str):
                 _encoding = self.encoding
                 if (_encoding is not None
@@ -219,7 +219,7 @@ class JSONEncoder(object):
         if self.ensure_ascii:
             return ''.join(chunks)
         else:
-            return u''.join(chunks)
+            return ''.join(chunks)
 
     def iterencode(self, o, _one_shot=False):
         """Encode the given object and yield each string
@@ -302,7 +302,7 @@ class JSONEncoderForHTML(JSONEncoder):
         if self.ensure_ascii:
             return ''.join(chunks)
         else:
-            return u''.join(chunks)
+            return ''.join(chunks)
 
     def iterencode(self, o, _one_shot=False):
         chunks = super(JSONEncoderForHTML, self).iterencode(o, _one_shot)
@@ -317,10 +317,8 @@ def _make_iterencode(markers, _default, _encoder, _ind
         _key_separator, _item_separator, _sort_keys, _skipkeys, _one_shot,
         _use_decimal,
         ## HACK: hand-optimized bytecode; turn globals into locals
-        False=False,
-        True=True,
         ValueError=ValueError,
-        basestring=basestring,
+        str=str,
         Decimal=Decimal,
         dict=dict,
         float=float,
@@ -328,8 +326,7 @@ def _make_iterencode(markers, _default, _encoder, _ind
         int=int,
         isinstance=isinstance,
         list=list,
-        long=long,
-        str=str,
+        long=int,
         tuple=tuple,
     ):
 
@@ -357,7 +354,7 @@ def _make_iterencode(markers, _default, _encoder, _ind
                 first = False
             else:
                 buf = separator
-            if isinstance(value, basestring):
+            if isinstance(value, str):
                 yield buf + _encoder(value)
             elif value is None:
                 yield buf + 'null'
@@ -365,7 +362,7 @@ def _make_iterencode(markers, _default, _encoder, _ind
                 yield buf + 'true'
             elif value is False:
                 yield buf + 'false'
-            elif isinstance(value, (int, long)):
+            elif isinstance(value, int):
                 yield buf + str(value)
             elif isinstance(value, float):
                 yield buf + _floatstr(value)
@@ -408,12 +405,12 @@ def _make_iterencode(markers, _default, _encoder, _ind
             item_separator = _item_separator
         first = True
         if _sort_keys:
-            items = dct.items()
+            items = list(dct.items())
             items.sort(key=lambda kv: kv[0])
         else:
-            items = dct.iteritems()
+            items = iter(dct.items())
         for key, value in items:
-            if isinstance(key, basestring):
+            if isinstance(key, str):
                 pass
             # JavaScript is weakly typed for these, so it makes sense to
             # also allow them.  Many encoders seem to do something like this.
@@ -425,7 +422,7 @@ def _make_iterencode(markers, _default, _encoder, _ind
                 key = 'false'
             elif key is None:
                 key = 'null'
-            elif isinstance(key, (int, long)):
+            elif isinstance(key, int):
                 key = str(key)
             elif _skipkeys:
                 continue
@@ -437,7 +434,7 @@ def _make_iterencode(markers, _default, _encoder, _ind
                 yield item_separator
             yield _encoder(key)
             yield _key_separator
-            if isinstance(value, basestring):
+            if isinstance(value, str):
                 yield _encoder(value)
             elif value is None:
                 yield 'null'
@@ -445,7 +442,7 @@ def _make_iterencode(markers, _default, _encoder, _ind
                 yield 'true'
             elif value is False:
                 yield 'false'
-            elif isinstance(value, (int, long)):
+            elif isinstance(value, int):
                 yield str(value)
             elif isinstance(value, float):
                 yield _floatstr(value)
@@ -468,7 +465,7 @@ def _make_iterencode(markers, _default, _encoder, _ind
             del markers[markerid]
 
     def _iterencode(o, _current_indent_level):
-        if isinstance(o, basestring):
+        if isinstance(o, str):
             yield _encoder(o)
         elif o is None:
             yield 'null'
@@ -476,7 +473,7 @@ def _make_iterencode(markers, _default, _encoder, _ind
             yield 'true'
         elif o is False:
             yield 'false'
-        elif isinstance(o, (int, long)):
+        elif isinstance(o, int):
             yield str(o)
         elif isinstance(o, float):
             yield _floatstr(o)