1818and their .encode/.decode methods as needed.
1919"""
2020
21- import re
2221import sys
2322import threading
23+ import urllib .parse
24+ import http .client
2425
25- import six
26- from six .moves import urllib
2726
28-
29- if six .PY3 :
27+ if True :
3028 def ntob (n , encoding = 'ISO-8859-1' ):
3129 """Return the given native string as a byte string in the given
3230 encoding.
@@ -49,43 +47,6 @@ def tonative(n, encoding='ISO-8859-1'):
4947 if isinstance (n , bytes ):
5048 return n .decode (encoding )
5149 return n
52- else :
53- # Python 2
54- def ntob (n , encoding = 'ISO-8859-1' ):
55- """Return the given native string as a byte string in the given
56- encoding.
57- """
58- assert_native (n )
59- # In Python 2, the native string type is bytes. Assume it's already
60- # in the given encoding, which for ISO-8859-1 is almost always what
61- # was intended.
62- return n
63-
64- def ntou (n , encoding = 'ISO-8859-1' ):
65- """Return the given native string as a unicode string with the given
66- encoding.
67- """
68- assert_native (n )
69- # In Python 2, the native string type is bytes.
70- # First, check for the special encoding 'escape'. The test suite uses
71- # this to signal that it wants to pass a string with embedded \uXXXX
72- # escapes, but without having to prefix it with u'' for Python 2,
73- # but no prefix for Python 3.
74- if encoding == 'escape' :
75- return six .text_type ( # unicode for Python 2
76- re .sub (r'\\u([0-9a-zA-Z]{4})' ,
77- lambda m : six .unichr (int (m .group (1 ), 16 )),
78- n .decode ('ISO-8859-1' )))
79- # Assume it's already in the given encoding, which for ISO-8859-1
80- # is almost always what was intended.
81- return n .decode (encoding )
82-
83- def tonative (n , encoding = 'ISO-8859-1' ):
84- """Return the given string as a native string in the given encoding."""
85- # In Python 2, the native string type is bytes.
86- if isinstance (n , six .text_type ): # unicode for Python 2
87- return n .encode (encoding )
88- return n
8950
9051
9152def assert_native (n ):
@@ -94,24 +55,12 @@ def assert_native(n):
9455
9556
9657# Some platforms don't expose HTTPSConnection, so handle it separately
97- HTTPSConnection = getattr (six .moves .http_client , 'HTTPSConnection' , None )
98-
58+ HTTPSConnection = getattr (http .client , 'HTTPSConnection' , None )
9959
100- def _unquote_plus_compat (string , encoding = 'utf-8' , errors = 'replace' ):
101- return urllib .parse .unquote_plus (string ).decode (encoding , errors )
10260
103-
104- def _unquote_compat (string , encoding = 'utf-8' , errors = 'replace' ):
105- return urllib .parse .unquote (string ).decode (encoding , errors )
106-
107-
108- def _quote_compat (string , encoding = 'utf-8' , errors = 'replace' ):
109- return urllib .parse .quote (string .encode (encoding , errors ))
110-
111-
112- unquote_plus = urllib .parse .unquote_plus if six .PY3 else _unquote_plus_compat
113- unquote = urllib .parse .unquote if six .PY3 else _unquote_compat
114- quote = urllib .parse .quote if six .PY3 else _quote_compat
61+ unquote_plus = urllib .parse .unquote_plus
62+ unquote = urllib .parse .unquote
63+ quote = urllib .parse .quote
11564
11665try :
11766 # Prefer simplejson
@@ -124,16 +73,14 @@ def _quote_compat(string, encoding='utf-8', errors='replace'):
12473_json_encode = json .JSONEncoder ().iterencode
12574
12675
127- if six . PY3 :
76+ if True :
12877 # Encode to bytes on Python 3
12978 def json_encode (value ):
13079 for chunk in _json_encode (value ):
13180 yield chunk .encode ('utf-8' )
132- else :
133- json_encode = _json_encode
13481
13582
136- text_or_bytes = six . text_type , bytes
83+ text_or_bytes = str , bytes
13784
13885
13986if sys .version_info >= (3 , 3 ):
0 commit comments