@@ -105,12 +105,8 @@ def getargspec(func):
105
105
kwargs = makelist (spec [0 ]) + makelist (spec .kwonlyargs )
106
106
return kwargs , spec [1 ], spec [2 ], spec [3 ]
107
107
108
- basestring = str
109
- unicode = str
110
108
json_loads = lambda s : json_lds (touni (s ))
111
109
callable = lambda x : hasattr (x , '__call__' )
112
- imap = map
113
-
114
110
115
111
def _wsgi_recode (src ):
116
112
""" Translate a PEP-3333 latin1-string to utf8+surrogateescape """
@@ -125,7 +121,7 @@ def _raise(*a):
125
121
126
122
# Some helpers for string/byte handling
127
123
def tob (s , enc = 'utf8' ):
128
- if isinstance (s , unicode ):
124
+ if isinstance (s , str ):
129
125
return s .encode (enc )
130
126
return b'' if s is None else bytes (s )
131
127
@@ -878,7 +874,7 @@ def hello(name):
878
874
skiplist = makelist (skip )
879
875
880
876
def decorator (callback ):
881
- if isinstance (callback , basestring ): callback = load (callback )
877
+ if isinstance (callback , str ): callback = load (callback )
882
878
for rule in makelist (path ) or yieldroutes (callback ):
883
879
for verb in makelist (method ):
884
880
verb = verb .upper ()
@@ -927,7 +923,7 @@ def error_handler_404(error):
927
923
"""
928
924
929
925
def decorator (callback ):
930
- if isinstance (callback , basestring ): callback = load (callback )
926
+ if isinstance (callback , str ): callback = load (callback )
931
927
self .error_handler [int (code )] = callback
932
928
return callback
933
929
@@ -979,8 +975,8 @@ def _handle(self, environ):
979
975
def _cast (self , out , peek = None ):
980
976
""" Try to convert the parameter into something WSGI compatible and set
981
977
correct HTTP headers when possible.
982
- Support: False, str, unicode , dict, HTTPResponse, HTTPError, file-like,
983
- iterable of strings and iterable of unicodes
978
+ Support: False, bytes/bytearray, str , dict, HTTPResponse, HTTPError, file-like,
979
+ iterable of bytes/bytearray or str instances.
984
980
"""
985
981
986
982
# Empty output is done here
@@ -990,10 +986,10 @@ def _cast(self, out, peek=None):
990
986
return []
991
987
# Join lists of byte or unicode strings. Mixed lists are NOT supported
992
988
if isinstance (out , (tuple , list ))\
993
- and isinstance (out [0 ], (bytes , unicode )):
989
+ and isinstance (out [0 ], (bytes , str )):
994
990
out = out [0 ][0 :0 ].join (out ) # b'abc'[0:0] -> b''
995
991
# Encode unicode strings
996
- if isinstance (out , unicode ):
992
+ if isinstance (out , str ):
997
993
out = out .encode (response .charset )
998
994
# Byte Strings are just returned
999
995
if isinstance (out , bytes ):
@@ -1039,9 +1035,9 @@ def _cast(self, out, peek=None):
1039
1035
return self ._cast (first )
1040
1036
elif isinstance (first , bytes ):
1041
1037
new_iter = itertools .chain ([first ], iout )
1042
- elif isinstance (first , unicode ):
1038
+ elif isinstance (first , str ):
1043
1039
encoder = lambda x : x .encode (response .charset )
1044
- new_iter = imap (encoder , itertools .chain ([first ], iout ))
1040
+ new_iter = map (encoder , itertools .chain ([first ], iout ))
1045
1041
else :
1046
1042
msg = 'Unsupported response type: %s' % type (first )
1047
1043
return self ._cast (HTTPError (500 , msg ))
@@ -1809,15 +1805,15 @@ def set_cookie(self, name, value, secret=None, digestmod=hashlib.sha256, **optio
1809
1805
Morsel ._reserved .setdefault ('samesite' , 'SameSite' )
1810
1806
1811
1807
if secret :
1812
- if not isinstance (value , basestring ):
1808
+ if not isinstance (value , str ):
1813
1809
depr (0 , 13 , "Pickling of arbitrary objects into cookies is "
1814
1810
"deprecated." , "Only store strings in cookies. "
1815
1811
"JSON strings are fine, too." )
1816
1812
encoded = base64 .b64encode (pickle .dumps ([name , value ], - 1 ))
1817
1813
sig = base64 .b64encode (hmac .new (tob (secret ), encoded ,
1818
1814
digestmod = digestmod ).digest ())
1819
1815
value = touni (b'!' + sig + b'?' + encoded )
1820
- elif not isinstance (value , basestring ):
1816
+ elif not isinstance (value , str ):
1821
1817
raise TypeError ('Secret key required for non-string cookies.' )
1822
1818
1823
1819
# Cookie size plus options must not exceed 4kb.
@@ -2157,7 +2153,7 @@ def getunicode(self, name, default=None, encoding=None):
2157
2153
""" (deprecated) Return the value as a unicode string, or the default. """
2158
2154
return self .get (name , default )
2159
2155
2160
- def __getattr__ (self , name , default = unicode ()):
2156
+ def __getattr__ (self , name , default = str ()):
2161
2157
# Without this guard, pickle generates a cryptic TypeError:
2162
2158
if name .startswith ('__' ) and name .endswith ('__' ):
2163
2159
return super (FormsDict , self ).__getattr__ (name )
@@ -2326,7 +2322,7 @@ def load_dict(self, source, namespace=''):
2326
2322
{'some.namespace.key': 'value'}
2327
2323
"""
2328
2324
for key , value in source .items ():
2329
- if isinstance (key , basestring ):
2325
+ if isinstance (key , str ):
2330
2326
nskey = (namespace + '.' + key ).strip ('.' )
2331
2327
if isinstance (value , dict ):
2332
2328
self .load_dict (value , namespace = nskey )
@@ -2344,7 +2340,7 @@ def update(self, *a, **ka):
2344
2340
>>> c.update('some.namespace', key='value')
2345
2341
"""
2346
2342
prefix = ''
2347
- if a and isinstance (a [0 ], basestring ):
2343
+ if a and isinstance (a [0 ], str ):
2348
2344
prefix = a [0 ].strip ('.' ) + '.'
2349
2345
a = a [1 :]
2350
2346
for key , value in dict (* a , ** ka ).items ():
@@ -2356,7 +2352,7 @@ def setdefault(self, key, value=None):
2356
2352
return self [key ]
2357
2353
2358
2354
def __setitem__ (self , key , value ):
2359
- if not isinstance (key , basestring ):
2355
+ if not isinstance (key , str ):
2360
2356
raise TypeError ('Key has type %r (not a string)' % type (key ))
2361
2357
2362
2358
self ._virtual_keys .discard (key )
@@ -2681,7 +2677,7 @@ def save(self, destination, overwrite=False, chunk_size=2 ** 16):
2681
2677
:param overwrite: If True, replace existing files. (default: False)
2682
2678
:param chunk_size: Bytes to read at a time. (default: 64kb)
2683
2679
"""
2684
- if isinstance (destination , basestring ): # Except file-likes here
2680
+ if isinstance (destination , str ): # Except file-likes here
2685
2681
if os .path .isdir (destination ):
2686
2682
destination = os .path .join (destination , self .filename )
2687
2683
if not overwrite and os .path .exists (destination ):
@@ -2847,7 +2843,7 @@ def debug(mode=True):
2847
2843
2848
2844
2849
2845
def http_date (value ):
2850
- if isinstance (value , basestring ):
2846
+ if isinstance (value , str ):
2851
2847
return value
2852
2848
if isinstance (value , datetime ):
2853
2849
# aware datetime.datetime is converted to UTC time
@@ -3836,13 +3832,13 @@ def run(app=None,
3836
3832
try :
3837
3833
if debug is not None : _debug (debug )
3838
3834
app = app or default_app ()
3839
- if isinstance (app , basestring ):
3835
+ if isinstance (app , str ):
3840
3836
app = load_app (app )
3841
3837
if not callable (app ):
3842
3838
raise ValueError ("Application is not callable: %r" % app )
3843
3839
3844
3840
for plugin in plugins or []:
3845
- if isinstance (plugin , basestring ):
3841
+ if isinstance (plugin , str ):
3846
3842
plugin = load (plugin )
3847
3843
app .install (plugin )
3848
3844
@@ -3851,7 +3847,7 @@ def run(app=None,
3851
3847
3852
3848
if server in server_names :
3853
3849
server = server_names .get (server )
3854
- if isinstance (server , basestring ):
3850
+ if isinstance (server , str ):
3855
3851
server = load (server )
3856
3852
if isinstance (server , type ):
3857
3853
server = server (host = host , port = port , ** kargs )
0 commit comments