32
32
# Python 2/3 compatibility
33
33
from .lib import six
34
34
from .lib import sgsix
35
+ from .lib import sgutils
35
36
from .lib .six import BytesIO # used for attachment upload
36
37
from .lib .six .moves import map
37
38
@@ -665,7 +666,7 @@ def __init__(self,
665
666
# the lowercase version of the credentials.
666
667
auth , self .config .server = self ._split_url (base_url )
667
668
if auth :
668
- auth = base64encode (six .ensure_binary (
669
+ auth = base64encode (sgutils .ensure_binary (
669
670
urllib .parse .unquote (auth ))).decode ("utf-8" )
670
671
self .config .authorization = "Basic " + auth .strip ()
671
672
@@ -2440,7 +2441,7 @@ def upload(self, entity_type, entity_id, path, field_name=None, display_name=Non
2440
2441
# have to raise a sane exception. This will always work for ascii and utf-8
2441
2442
# encoded strings, but will fail on some others if the string includes non
2442
2443
# ascii characters.
2443
- if not isinstance (path , six . text_type ):
2444
+ if not isinstance (path , str ):
2444
2445
try :
2445
2446
path = path .decode ("utf-8" )
2446
2447
except UnicodeDecodeError :
@@ -2721,7 +2722,7 @@ def download_attachment(self, attachment=False, file_path=None, attachment_id=No
2721
2722
elif e .code == 403 :
2722
2723
# Only parse the body if it is an Amazon S3 url.
2723
2724
if url .find ("s3.amazonaws.com" ) != - 1 and e .headers ["content-type" ] == "application/xml" :
2724
- body = [six .ensure_text (line ) for line in e .readlines ()]
2725
+ body = [sgutils .ensure_text (line ) for line in e .readlines ()]
2725
2726
if body :
2726
2727
xml = "" .join (body )
2727
2728
# Once python 2.4 support is not needed we can think about using
@@ -3545,7 +3546,7 @@ def _encode_payload(self, payload):
3545
3546
"""
3546
3547
3547
3548
wire = json .dumps (payload , ensure_ascii = False )
3548
- return six .ensure_binary (wire )
3549
+ return sgutils .ensure_binary (wire )
3549
3550
3550
3551
def _make_call (self , verb , path , body , headers ):
3551
3552
"""
@@ -3720,8 +3721,8 @@ def _json_loads_ascii(self, body):
3720
3721
def _decode_list (lst ):
3721
3722
newlist = []
3722
3723
for i in lst :
3723
- if isinstance (i , six . text_type ):
3724
- i = six .ensure_str (i )
3724
+ if isinstance (i , str ):
3725
+ i = sgutils .ensure_str (i )
3725
3726
elif isinstance (i , list ):
3726
3727
i = _decode_list (i )
3727
3728
newlist .append (i )
@@ -3730,10 +3731,10 @@ def _decode_list(lst):
3730
3731
def _decode_dict (dct ):
3731
3732
newdict = {}
3732
3733
for k , v in six .iteritems (dct ):
3733
- if isinstance (k , six . text_type ):
3734
- k = six .ensure_str (k )
3735
- if isinstance (v , six . text_type ):
3736
- v = six .ensure_str (v )
3734
+ if isinstance (k , str ):
3735
+ k = sgutils .ensure_str (k )
3736
+ if isinstance (v , str ):
3737
+ v = sgutils .ensure_str (v )
3737
3738
elif isinstance (v , list ):
3738
3739
v = _decode_list (v )
3739
3740
newdict [k ] = v
@@ -3844,8 +3845,8 @@ def _outbound_visitor(value):
3844
3845
return value .strftime ("%Y-%m-%dT%H:%M:%SZ" )
3845
3846
3846
3847
# ensure return is six.text_type
3847
- if isinstance (value , six . string_types ):
3848
- return six .ensure_text (value )
3848
+ if isinstance (value , str ):
3849
+ return sgutils .ensure_text (value )
3849
3850
3850
3851
return value
3851
3852
@@ -3865,7 +3866,7 @@ def _change_tz(x):
3865
3866
_change_tz = None
3866
3867
3867
3868
def _inbound_visitor (value ):
3868
- if isinstance (value , six . string_types ):
3869
+ if isinstance (value , str ):
3869
3870
if len (value ) == 20 and self ._DATE_TIME_PATTERN .match (value ):
3870
3871
try :
3871
3872
# strptime was not on datetime in python2.4
@@ -4266,7 +4267,7 @@ def _send_form(self, url, params):
4266
4267
else :
4267
4268
raise ShotgunError ("Unanticipated error occurred %s" % (e ))
4268
4269
4269
- return six .ensure_text (result )
4270
+ return sgutils .ensure_text (result )
4270
4271
else :
4271
4272
raise ShotgunError ("Max attemps limit reached." )
4272
4273
@@ -4339,7 +4340,7 @@ def http_request(self, request):
4339
4340
data = request .data
4340
4341
else :
4341
4342
data = request .get_data ()
4342
- if data is not None and not isinstance (data , six . string_types ):
4343
+ if data is not None and not isinstance (data , str ):
4343
4344
files = []
4344
4345
params = []
4345
4346
for key , value in data .items ():
@@ -4348,7 +4349,7 @@ def http_request(self, request):
4348
4349
else :
4349
4350
params .append ((key , value ))
4350
4351
if not files :
4351
- data = six .ensure_binary (urllib .parse .urlencode (params , True )) # sequencing on
4352
+ data = sgutils .ensure_binary (urllib .parse .urlencode (params , True )) # sequencing on
4352
4353
else :
4353
4354
boundary , data = self .encode (params , files )
4354
4355
content_type = "multipart/form-data; boundary=%s" % boundary
@@ -4371,40 +4372,40 @@ def encode(self, params, files, boundary=None, buffer=None):
4371
4372
if buffer is None :
4372
4373
buffer = BytesIO ()
4373
4374
for (key , value ) in params :
4374
- if not isinstance (value , six . string_types ):
4375
+ if not isinstance (value , str ):
4375
4376
# If value is not a string (e.g. int) cast to text
4376
- value = six . text_type (value )
4377
- value = six .ensure_text (value )
4378
- key = six .ensure_text (key )
4377
+ value = str (value )
4378
+ value = sgutils .ensure_text (value )
4379
+ key = sgutils .ensure_text (key )
4379
4380
4380
- buffer .write (six .ensure_binary ("--%s\r \n " % boundary ))
4381
- buffer .write (six .ensure_binary ("Content-Disposition: form-data; name=\" %s\" " % key ))
4382
- buffer .write (six .ensure_binary ("\r \n \r \n %s\r \n " % value ))
4381
+ buffer .write (sgutils .ensure_binary ("--%s\r \n " % boundary ))
4382
+ buffer .write (sgutils .ensure_binary ("Content-Disposition: form-data; name=\" %s\" " % key ))
4383
+ buffer .write (sgutils .ensure_binary ("\r \n \r \n %s\r \n " % value ))
4383
4384
for (key , fd ) in files :
4384
4385
# On Windows, it's possible that we were forced to open a file
4385
4386
# with non-ascii characters as unicode. In that case, we need to
4386
4387
# encode it as a utf-8 string to remove unicode from the equation.
4387
4388
# If we don't, the mix of unicode and strings going into the
4388
4389
# buffer can cause UnicodeEncodeErrors to be raised.
4389
4390
filename = fd .name
4390
- filename = six .ensure_text (filename )
4391
+ filename = sgutils .ensure_text (filename )
4391
4392
filename = filename .split ("/" )[- 1 ]
4392
- key = six .ensure_text (key )
4393
+ key = sgutils .ensure_text (key )
4393
4394
content_type = mimetypes .guess_type (filename )[0 ]
4394
4395
content_type = content_type or "application/octet-stream"
4395
4396
file_size = os .fstat (fd .fileno ())[stat .ST_SIZE ]
4396
- buffer .write (six .ensure_binary ("--%s\r \n " % boundary ))
4397
+ buffer .write (sgutils .ensure_binary ("--%s\r \n " % boundary ))
4397
4398
c_dis = "Content-Disposition: form-data; name=\" %s\" ; filename=\" %s\" %s"
4398
4399
content_disposition = c_dis % (key , filename , "\r \n " )
4399
- buffer .write (six .ensure_binary (content_disposition ))
4400
- buffer .write (six .ensure_binary ("Content-Type: %s\r \n " % content_type ))
4401
- buffer .write (six .ensure_binary ("Content-Length: %s\r \n " % file_size ))
4400
+ buffer .write (sgutils .ensure_binary (content_disposition ))
4401
+ buffer .write (sgutils .ensure_binary ("Content-Type: %s\r \n " % content_type ))
4402
+ buffer .write (sgutils .ensure_binary ("Content-Length: %s\r \n " % file_size ))
4402
4403
4403
- buffer .write (six .ensure_binary ("\r \n " ))
4404
+ buffer .write (sgutils .ensure_binary ("\r \n " ))
4404
4405
fd .seek (0 )
4405
4406
shutil .copyfileobj (fd , buffer )
4406
- buffer .write (six .ensure_binary ("\r \n " ))
4407
- buffer .write (six .ensure_binary ("--%s--\r \n \r \n " % boundary ))
4407
+ buffer .write (sgutils .ensure_binary ("\r \n " ))
4408
+ buffer .write (sgutils .ensure_binary ("--%s--\r \n \r \n " % boundary ))
4408
4409
buffer = buffer .getvalue ()
4409
4410
return boundary , buffer
4410
4411
0 commit comments