3232# Python 2/3 compatibility
3333from .lib import six
3434from .lib import sgsix
35+ from .lib import sgutils
3536from .lib .six import BytesIO # used for attachment upload
3637from .lib .six .moves import map
3738
@@ -115,7 +116,7 @@ def _is_mimetypes_broken():
115116
116117# ----------------------------------------------------------------------------
117118# Version
118- __version__ = "3.6.1 "
119+ __version__ = "3.6.2 "
119120
120121# ----------------------------------------------------------------------------
121122# Errors
@@ -665,7 +666,7 @@ def __init__(self,
665666 # the lowercase version of the credentials.
666667 auth , self .config .server = self ._split_url (base_url )
667668 if auth :
668- auth = base64encode (six .ensure_binary (
669+ auth = base64encode (sgutils .ensure_binary (
669670 urllib .parse .unquote (auth ))).decode ("utf-8" )
670671 self .config .authorization = "Basic " + auth .strip ()
671672
@@ -2440,7 +2441,7 @@ def upload(self, entity_type, entity_id, path, field_name=None, display_name=Non
24402441 # have to raise a sane exception. This will always work for ascii and utf-8
24412442 # encoded strings, but will fail on some others if the string includes non
24422443 # ascii characters.
2443- if not isinstance (path , six . text_type ):
2444+ if not isinstance (path , str ):
24442445 try :
24452446 path = path .decode ("utf-8" )
24462447 except UnicodeDecodeError :
@@ -2721,7 +2722,7 @@ def download_attachment(self, attachment=False, file_path=None, attachment_id=No
27212722 elif e .code == 403 :
27222723 # Only parse the body if it is an Amazon S3 url.
27232724 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 ()]
27252726 if body :
27262727 xml = "" .join (body )
27272728 # Once python 2.4 support is not needed we can think about using
@@ -3545,7 +3546,7 @@ def _encode_payload(self, payload):
35453546 """
35463547
35473548 wire = json .dumps (payload , ensure_ascii = False )
3548- return six .ensure_binary (wire )
3549+ return sgutils .ensure_binary (wire )
35493550
35503551 def _make_call (self , verb , path , body , headers ):
35513552 """
@@ -3720,8 +3721,8 @@ def _json_loads_ascii(self, body):
37203721 def _decode_list (lst ):
37213722 newlist = []
37223723 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 )
37253726 elif isinstance (i , list ):
37263727 i = _decode_list (i )
37273728 newlist .append (i )
@@ -3730,10 +3731,10 @@ def _decode_list(lst):
37303731 def _decode_dict (dct ):
37313732 newdict = {}
37323733 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 )
37373738 elif isinstance (v , list ):
37383739 v = _decode_list (v )
37393740 newdict [k ] = v
@@ -3844,8 +3845,8 @@ def _outbound_visitor(value):
38443845 return value .strftime ("%Y-%m-%dT%H:%M:%SZ" )
38453846
38463847 # 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 )
38493850
38503851 return value
38513852
@@ -3865,7 +3866,7 @@ def _change_tz(x):
38653866 _change_tz = None
38663867
38673868 def _inbound_visitor (value ):
3868- if isinstance (value , six . string_types ):
3869+ if isinstance (value , str ):
38693870 if len (value ) == 20 and self ._DATE_TIME_PATTERN .match (value ):
38703871 try :
38713872 # strptime was not on datetime in python2.4
@@ -4266,7 +4267,7 @@ def _send_form(self, url, params):
42664267 else :
42674268 raise ShotgunError ("Unanticipated error occurred %s" % (e ))
42684269
4269- return six .ensure_text (result )
4270+ return sgutils .ensure_text (result )
42704271 else :
42714272 raise ShotgunError ("Max attemps limit reached." )
42724273
@@ -4339,7 +4340,7 @@ def http_request(self, request):
43394340 data = request .data
43404341 else :
43414342 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 ):
43434344 files = []
43444345 params = []
43454346 for key , value in data .items ():
@@ -4348,7 +4349,7 @@ def http_request(self, request):
43484349 else :
43494350 params .append ((key , value ))
43504351 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
43524353 else :
43534354 boundary , data = self .encode (params , files )
43544355 content_type = "multipart/form-data; boundary=%s" % boundary
@@ -4371,40 +4372,40 @@ def encode(self, params, files, boundary=None, buffer=None):
43714372 if buffer is None :
43724373 buffer = BytesIO ()
43734374 for (key , value ) in params :
4374- if not isinstance (value , six . string_types ):
4375+ if not isinstance (value , str ):
43754376 # 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 )
43794380
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 ))
43834384 for (key , fd ) in files :
43844385 # On Windows, it's possible that we were forced to open a file
43854386 # with non-ascii characters as unicode. In that case, we need to
43864387 # encode it as a utf-8 string to remove unicode from the equation.
43874388 # If we don't, the mix of unicode and strings going into the
43884389 # buffer can cause UnicodeEncodeErrors to be raised.
43894390 filename = fd .name
4390- filename = six .ensure_text (filename )
4391+ filename = sgutils .ensure_text (filename )
43914392 filename = filename .split ("/" )[- 1 ]
4392- key = six .ensure_text (key )
4393+ key = sgutils .ensure_text (key )
43934394 content_type = mimetypes .guess_type (filename )[0 ]
43944395 content_type = content_type or "application/octet-stream"
43954396 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 ))
43974398 c_dis = "Content-Disposition: form-data; name=\" %s\" ; filename=\" %s\" %s"
43984399 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 ))
44024403
4403- buffer .write (six .ensure_binary ("\r \n " ))
4404+ buffer .write (sgutils .ensure_binary ("\r \n " ))
44044405 fd .seek (0 )
44054406 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 ))
44084409 buffer = buffer .getvalue ()
44094410 return boundary , buffer
44104411
0 commit comments