From b78e14b85c950287415796d236eac67ba8c8fbcb Mon Sep 17 00:00:00 2001 From: Zoran Simic Date: Mon, 16 Nov 2020 17:41:10 -0800 Subject: [PATCH 1/2] Ensure all files are py2/py3 syntactically compatible --- shotgun_api3/lib/httplib2/python3/__init__.py | 4 ++++ shotgun_api3/lib/httplib2/python3/socks.py | 2 +- shotgun_api3/lib/mimetypes.py | 14 +++++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/shotgun_api3/lib/httplib2/python3/__init__.py b/shotgun_api3/lib/httplib2/python3/__init__.py index 3c61aac8a..9a9f9e55a 100644 --- a/shotgun_api3/lib/httplib2/python3/__init__.py +++ b/shotgun_api3/lib/httplib2/python3/__init__.py @@ -1,6 +1,10 @@ # -*- coding: utf-8 -*- """Small, fast HTTP client library for Python.""" +# TODO: remove __future__ import when support for py2 is completely dropped +# Needed until then to avoid py2 packaging barking on things of the form: print(..., end=...) +from __future__ import print_function + __author__ = "Joe Gregorio (joe@bitworking.org)" __copyright__ = "Copyright 2006, Joe Gregorio" __contributors__ = [ diff --git a/shotgun_api3/lib/httplib2/python3/socks.py b/shotgun_api3/lib/httplib2/python3/socks.py index cc68e634c..26bfc5de0 100644 --- a/shotgun_api3/lib/httplib2/python3/socks.py +++ b/shotgun_api3/lib/httplib2/python3/socks.py @@ -434,7 +434,7 @@ def __negotiatehttp(self, destaddr, destport): wrote_host_header = False wrote_auth_header = False if self.__proxy[6] != None: - for key, val in self.__proxy[6].iteritems(): + for key, val in self.__proxy[6].items(): headers += [key, ": ", val, "\r\n"] wrote_host_header = key.lower() == "host" wrote_auth_header = key.lower() == "proxy-authorization" diff --git a/shotgun_api3/lib/mimetypes.py b/shotgun_api3/lib/mimetypes.py index bc8488535..cbd3fe875 100644 --- a/shotgun_api3/lib/mimetypes.py +++ b/shotgun_api3/lib/mimetypes.py @@ -568,14 +568,14 @@ def _default_mime_types(): """ def usage(code, msg=''): - print USAGE - if msg: print msg + print(USAGE) + if msg: print(msg) sys.exit(code) try: opts, args = getopt.getopt(sys.argv[1:], 'hle', ['help', 'lenient', 'extension']) - except getopt.error, msg: + except getopt.error as msg: usage(1, msg) strict = 1 @@ -590,9 +590,9 @@ def usage(code, msg=''): for gtype in args: if extension: guess = guess_extension(gtype, strict) - if not guess: print "I don't know anything about type", gtype - else: print guess + if not guess: print("I don't know anything about type %s" % gtype) + else: print(guess) else: guess, encoding = guess_type(gtype, strict) - if not guess: print "I don't know anything about type", gtype - else: print 'type:', guess, 'encoding:', encoding \ No newline at end of file + if not guess: print("I don't know anything about type %s" % gtype) + else: print('type: %s encoding: %s' % (guess, encoding)) From e3585d1440df604a5b99bba95109c8a187ce7733 Mon Sep 17 00:00:00 2001 From: Zoran Simic Date: Mon, 16 Nov 2020 18:01:21 -0800 Subject: [PATCH 2/2] Ensure all files are py2/py3 syntactically compatible --- shotgun_api3/lib/xmlrpclib.py | 69 +++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/shotgun_api3/lib/xmlrpclib.py b/shotgun_api3/lib/xmlrpclib.py index ed2a90c1c..1e66d2064 100644 --- a/shotgun_api3/lib/xmlrpclib.py +++ b/shotgun_api3/lib/xmlrpclib.py @@ -1,5 +1,5 @@ #! /opt/local/bin/python - + # XML-RPC CLIENT LIBRARY # $Id: xmlrpclib.py 41594 2005-12-04 19:11:17Z andrew.kuchling $ # @@ -98,23 +98,23 @@ implement XML-RPC servers. Exported exceptions: - + Error Base class for client errors ProtocolError Indicates an HTTP protocol error ResponseError Indicates a broken response package Fault Indicates an XML-RPC fault package Exported classes: - + ServerProxy Represents a logical connection to an XML-RPC server - + MultiCall Executor of boxcared xmlrpc requests Boolean boolean wrapper to generate a "boolean" XML-RPC value DateTime dateTime wrapper for an ISO 8601 string or time tuple or localtime integer value to generate a "dateTime.iso8601" XML-RPC value Binary binary data wrapper - + SlowParser Slow but safe standard parser (based on xmllib) Marshaller Generate an XML-RPC params chunk from a Python data structure Unmarshaller Unmarshal an XML-RPC response from incoming XML event message @@ -122,12 +122,12 @@ SafeTransport Handles an HTTPS transaction to an XML-RPC server Exported constants: - + True False Exported functions: - + boolean Convert any Python value to an XML-RPC boolean getparser Create instance of the fastest available parser & attach to an unmarshalling object @@ -142,7 +142,6 @@ from types import * import socket import errno -import httplib # -------------------------------------------------------------------- # Internal stuff @@ -150,6 +149,8 @@ try: unicode except NameError: + # TODO: this could be simply 'unicode = str' + # as in py3 there is no more special 'unicode' type (everything is unicode...) unicode = None # unicode support not available try: @@ -188,8 +189,8 @@ def _stringify(string): #__version__ = "1.0.1" # xmlrpc integer limits -MAXINT = 2L**31-1 -MININT = -2L**31 +MAXINT = 2**31-1 +MININT = -2**31 # -------------------------------------------------------------------- # Error constants (from Dan Libby's specification at @@ -289,40 +290,60 @@ def __repr__(self): if _bool_is_builtin: boolean = Boolean = bool - # to avoid breaking code which references xmlrpclib.{True,False} - True, False = True, False + try: + # TODO: remove this when py2 support is completely dropped + # to avoid breaking code which references xmlrpclib.{True,False} + True, False = True, False + + except SyntaxError: + pass # We're in py3 + else: class Boolean: """Boolean-value wrapper. - + Use True or False to generate a "boolean" XML-RPC value. """ - + def __init__(self, value = 0): self.value = operator.truth(value) - + def encode(self, out): out.write("%d\n" % self.value) - + def __cmp__(self, other): + # cmp() is not part of py3: https://python-future.org/compatible_idioms.html#cmp if isinstance(other, Boolean): other = other.value - return cmp(self.value, other) - + + if self.value is None: + return 0 if other is None else -1 + + if other is None: + return 1 + + return self.value.__cmp__(other) + def __repr__(self): if self.value: return "" % id(self) else: return "" % id(self) - + def __int__(self): return self.value - + def __nonzero__(self): return self.value - - True, False = Boolean(1), Boolean(0) - + + try: + # TODO: remove this when py2 support is completely dropped + # to avoid breaking code which references xmlrpclib.{True,False} + True, False = Boolean(1), Boolean(0) + + except SyntaxError: + pass # We're in py3 + ## # Map true or false value to XML-RPC boolean values. # @@ -333,7 +354,7 @@ def __nonzero__(self): # @see Boolean # @see True # @see False - + def boolean(value, _truefalse=(False, True)): """Convert any Python value to XML-RPC 'boolean'.""" return _truefalse[operator.truth(value)]