Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit for dropping old python 2, fixes #6 #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,27 +574,6 @@ def _test_cmd_string(self):
extra_setup_params["obsoletes"] = ["suds"]


# -----------------------------------------------------------------------------
# Integrate py2to3 into our build operation.
# -----------------------------------------------------------------------------

if sys.version_info >= (3,):
# Integrate the py2to3 step into our build.
if using_setuptools:
extra_setup_params["use_2to3"] = True
else:
from distutils.command.build_py import build_py_2to3
distutils_cmdclass["build_py"] = build_py_2to3

# Teach Python's urllib lib2to3 fixer that the old urllib2.__version__ data
# member is now stored in the urllib.request module.
import lib2to3.fixes.fix_urllib
for x in lib2to3.fixes.fix_urllib.MAPPING["urllib2"]:
if x[0] == "urllib.request":
x[1].append("__version__")
break


# -----------------------------------------------------------------------------
# Avoid setup warnings when constructing a list of all project sources.
# -----------------------------------------------------------------------------
Expand Down
28 changes: 14 additions & 14 deletions suds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Project properties
#

from version import __build__, __version__
from .version import __build__, __version__


#
Expand All @@ -34,23 +34,23 @@

class MethodNotFound(Exception):
def __init__(self, name):
Exception.__init__(self, u"Method not found: '%s'" % (name,))
Exception.__init__(self, "Method not found: '%s'" % (name,))

class PortNotFound(Exception):
def __init__(self, name):
Exception.__init__(self, u"Port not found: '%s'" % (name,))
Exception.__init__(self, "Port not found: '%s'" % (name,))

class ServiceNotFound(Exception):
def __init__(self, name):
Exception.__init__(self, u"Service not found: '%s'" % (name,))
Exception.__init__(self, "Service not found: '%s'" % (name,))

class TypeNotFound(Exception):
def __init__(self, name):
Exception.__init__(self, u"Type not found: '%s'" % (tostr(name),))
Exception.__init__(self, "Type not found: '%s'" % (tostr(name),))

class BuildError(Exception):
def __init__(self, name, exception):
Exception.__init__(self, u"An error occurred while building an "
Exception.__init__(self, "An error occurred while building an "
"instance of (%s). As a result the object you requested could not "
"be constructed. It is recommended that you construct the type "
"manually using a Suds object. Please open a ticket with a "
Expand All @@ -59,7 +59,7 @@ def __init__(self, name, exception):
class WebFault(Exception):
def __init__(self, fault, document):
if hasattr(fault, "faultstring"):
Exception.__init__(self, u"Server raised fault: '%s'" %
Exception.__init__(self, "Server raised fault: '%s'" %
(fault.faultstring,))
self.fault = fault
self.document = document
Expand Down Expand Up @@ -89,7 +89,7 @@ def objid(obj):

def tostr(object, encoding=None):
"""Get a unicode safe string representation of an object."""
if isinstance(object, basestring):
if isinstance(object, str):
if encoding is None:
return object
return object.encode(encoding)
Expand All @@ -109,15 +109,15 @@ def tostr(object, encoding=None):
return "".join(s)
if isinstance(object, dict):
s = ["{"]
for item in object.items():
for item in list(object.items()):
s.append(tostr(item[0]))
s.append(" = ")
s.append(tostr(item[1]))
s.append(", ")
s.append("}")
return "".join(s)
try:
return unicode(object)
return str(object)
except Exception:
return str(object)

Expand All @@ -127,7 +127,7 @@ def tostr(object, encoding=None):
#

if sys.version_info < (3, 0):
from cStringIO import StringIO as BytesIO
from io import StringIO as BytesIO
else:
from io import BytesIO

Expand All @@ -137,7 +137,7 @@ class UnicodeMixin(object):
# For Python 3, __str__() and __unicode__() should be identical.
__str__ = lambda x: x.__unicode__()
else:
__str__ = lambda x: unicode(x).encode("utf-8")
__str__ = lambda x: str(x).encode("utf-8")

# Used instead of byte literals as they are not supported on Python versions
# prior to 2.6.
Expand All @@ -149,8 +149,8 @@ def byte_str(s="", encoding="utf-8", input_encoding="utf-8", errors="strict"):
strings encoded using the given input encoding.

"""
assert isinstance(s, basestring)
if isinstance(s, unicode):
assert isinstance(s, str)
if isinstance(s, str):
return s.encode(encoding, errors)
if s and encoding != input_encoding:
return s.decode(input_encoding, errors).encode(encoding, errors)
Expand Down
50 changes: 25 additions & 25 deletions suds/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
import suds.transport.https
from suds.umx.basic import Basic as UmxBasic
from suds.wsdl import Definitions
import sudsobject
from . import sudsobject

from cookielib import CookieJar
from http.cookiejar import CookieJar
from copy import deepcopy
import httplib
import http.client

from logging import getLogger
log = getLogger(__name__)
Expand Down Expand Up @@ -192,7 +192,7 @@ def __unicode__(self):
if suds.__build__:
s.append(" build: %s" % (suds.__build__,))
for sd in self.sd:
s.append("\n\n%s" % (unicode(sd),))
s.append("\n\n%s" % (str(sd),))
return "".join(s)


Expand Down Expand Up @@ -239,7 +239,7 @@ def create(self, name):
else:
try:
result = self.builder.build(type)
except Exception, e:
except Exception as e:
log.error("create '%s' failed", name, exc_info=True)
raise BuildError(name, e)
timer.stop()
Expand Down Expand Up @@ -340,20 +340,20 @@ def __find(self, name):
"""
service = None
if not self.__services:
raise Exception, "No services defined"
raise Exception("No services defined")
if isinstance(name, int):
try:
service = self.__services[name]
name = service.name
except IndexError:
raise ServiceNotFound, "at [%d]" % (name,)
raise ServiceNotFound("at [%d]" % (name,))
else:
for s in self.__services:
if name == s.name:
service = s
break
if service is None:
raise ServiceNotFound, name
raise ServiceNotFound(name)
return PortSelector(self.__client, service.ports, name)

def __ds(self):
Expand Down Expand Up @@ -450,21 +450,21 @@ def __find(self, name):
"""
port = None
if not self.__ports:
raise Exception, "No ports defined: %s" % (self.__qn,)
raise Exception("No ports defined: %s" % (self.__qn,))
if isinstance(name, int):
qn = "%s[%d]" % (self.__qn, name)
try:
port = self.__ports[name]
except IndexError:
raise PortNotFound, qn
raise PortNotFound(qn)
else:
qn = ".".join((self.__qn, name))
for p in self.__ports:
if name == p.name:
port = p
break
if port is None:
raise PortNotFound, qn
raise PortNotFound(qn)
qn = ".".join((self.__qn, port.name))
return MethodSelector(self.__client, port.methods, qn)

Expand Down Expand Up @@ -532,7 +532,7 @@ def __getitem__(self, name):
m = self.__methods.get(name)
if m is None:
qn = ".".join((self.__qn, name))
raise MethodNotFound, qn
raise MethodNotFound(qn)
return Method(self.__client, m)


Expand Down Expand Up @@ -564,10 +564,10 @@ def __call__(self, *args, **kwargs):
client = clientclass(self.client, self.method)
try:
return client.invoke(args, kwargs)
except WebFault, e:
except WebFault as e:
if self.faults():
raise
return httplib.INTERNAL_SERVER_ERROR, e
return http.client.INTERNAL_SERVER_ERROR, e

def faults(self):
"""Get faults option."""
Expand Down Expand Up @@ -747,7 +747,7 @@ def send(self, soapenv):
reply = self.options.transport.send(request)
timer.stop()
metrics.log.debug("waited %s on server reply", timer)
except suds.transport.TransportError, e:
except suds.transport.TransportError as e:
content = e.fp and e.fp.read() or ""
return self.process_reply(content, e.httpcode, tostr(e))
return self.process_reply(reply.message, None, None)
Expand All @@ -771,15 +771,15 @@ def process_reply(self, reply, status, description):

"""
if status is None:
status = httplib.OK
status = http.client.OK
debug_message = "Reply HTTP status - %d" % (status,)
if status in (httplib.ACCEPTED, httplib.NO_CONTENT):
if status in (http.client.ACCEPTED, http.client.NO_CONTENT):
log.debug(debug_message)
return
#TODO: Consider whether and how to allow plugins to handle error,
# httplib.ACCEPTED & httplib.NO_CONTENT replies as well as successful
# ones.
if status == httplib.OK:
if status == http.client.OK:
log.debug("%s\n%s", debug_message, reply)
else:
log.debug("%s - %s\n%s", debug_message, description, reply)
Expand All @@ -801,19 +801,19 @@ def process_reply(self, reply, status, description):
# An INSTANCE MUST use a "500 Internal Server Error" HTTP status code
# if the response message is a SOAP Fault.
replyroot = None
if status in (httplib.OK, httplib.INTERNAL_SERVER_ERROR):
if status in (http.client.OK, http.client.INTERNAL_SERVER_ERROR):
replyroot = _parse(reply)
plugins.message.parsed(reply=replyroot)
fault = self.__get_fault(replyroot)
if fault:
if status != httplib.INTERNAL_SERVER_ERROR:
if status != http.client.INTERNAL_SERVER_ERROR:
log.warn("Web service reported a SOAP processing fault "
"using an unexpected HTTP status code %d. Reporting "
"as an internal server error.", status)
if self.options.faults:
raise WebFault(fault, replyroot)
return httplib.INTERNAL_SERVER_ERROR, fault
if status != httplib.OK:
return http.client.INTERNAL_SERVER_ERROR, fault
if status != http.client.OK:
if self.options.faults:
#TODO: Use a more specific exception class here.
raise Exception((status, description))
Expand All @@ -828,7 +828,7 @@ def process_reply(self, reply, status, description):
result = ctx.reply
if self.options.faults:
return result
return httplib.OK, result
return http.client.OK, result

def __get_fault(self, replyroot):
"""
Expand Down Expand Up @@ -858,7 +858,7 @@ def __headers(self):

"""
action = self.method.soap.action
if isinstance(action, unicode):
if isinstance(action, str):
action = action.encode("utf-8")
result = {
"Content-Type": "text/xml; charset=utf-8",
Expand Down Expand Up @@ -886,7 +886,7 @@ class _SimClient(_SoapClient):
@classmethod
def simulation(cls, kwargs):
"""Get whether injected data has been specified in I{kwargs}."""
return kwargs.has_key(_SimClient.__injkey)
return _SimClient.__injkey in kwargs

def invoke(self, args, kwargs):
"""
Expand Down
4 changes: 2 additions & 2 deletions suds/mx/typer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class Typer:
bool: ("boolean", Namespace.xsdns),
float: ("float", Namespace.xsdns),
int: ("int", Namespace.xsdns),
long: ("long", Namespace.xsdns),
int: ("long", Namespace.xsdns),
str: ("string", Namespace.xsdns),
Text: ("string", Namespace.xsdns),
unicode: ("string", Namespace.xsdns)}
str: ("string", Namespace.xsdns)}

@classmethod
def auto(cls, node, value=None):
Expand Down
6 changes: 3 additions & 3 deletions suds/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ def __init__(self, **kwargs):
Definition('extraArgumentErrors', bool, True),
Definition('faults', bool, True),
Definition('transport', Transport, None, TpLinker()),
Definition('service', (int, basestring), None),
Definition('port', (int, basestring), None),
Definition('location', basestring, None),
Definition('service', (int, str), None),
Definition('port', (int, str), None),
Definition('location', str, None),
Definition('soapheaders', (), ()),
Definition('wsse', Security, None),
Definition('doctor', Doctor, None),
Expand Down
2 changes: 1 addition & 1 deletion suds/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def __init__(self, plugins):
def __getattr__(self, name):
domain = self.domains.get(name)
if not domain:
raise Exception, 'plugin domain (%s), invalid' % (name,)
raise Exception('plugin domain (%s), invalid' % (name,))
ctx, pclass = domain
plugins = [p for p in self.plugins if isinstance(p, pclass)]
return PluginDomain(ctx, plugins)
Expand Down
Loading