Skip to content

Commit

Permalink
Refactored classes to use super where applicable.
Browse files Browse the repository at this point in the history
  • Loading branch information
warvariuc committed Oct 24, 2013
1 parent d782415 commit 0c40ff4
Show file tree
Hide file tree
Showing 32 changed files with 76 additions and 73 deletions.
2 changes: 1 addition & 1 deletion doc/source/manual/06_metadata.rst
Expand Up @@ -80,7 +80,7 @@ Here's a sample custom public exception: ::
__namespace__ = 'spyne.examples.authentication'

def __init__(self, value):
Fault.__init__(self,
super(PublicKeyError, self).__init__(
faultcode='Client.KeyError',
faultstring='Value %r not found' % value
)
Expand Down
10 changes: 5 additions & 5 deletions examples/authentication/http_cookie/server_soap.py
Expand Up @@ -57,11 +57,11 @@
from spyne.server.wsgi import WsgiApplication
from spyne.service import ServiceBase

class PublicKeyError(ResourceNotFoundError):
class PublicKeyError(Fault):
__namespace__ = 'spyne.examples.authentication'

def __init__(self, value):
Fault.__init__(self,
super(PublicKeyError, self).__init__(
faultcode='Client.KeyError',
faultstring='Value %r not found' % value
)
Expand All @@ -73,7 +73,7 @@ class AuthenticationError(Fault):
def __init__(self, user_name):
# TODO: self.transport.http.resp_code = HTTP_401

Fault.__init__(self,
super(AuthenticationError, self).__init__(
faultcode='Client.AuthenticationError',
faultstring='Invalid authentication request for %r' % user_name
)
Expand All @@ -85,7 +85,7 @@ class AuthorizationError(Fault):
def __init__(self):
# TODO: self.transport.http.resp_code = HTTP_401

Fault.__init__(self,
super(AuthorizationError, self).__init__(
faultcode='Client.AuthorizationError',
faultstring='You are not authorized to access this resource.'
)
Expand All @@ -94,7 +94,7 @@ class UnauthenticatedError(Fault):
__namespace__ = 'spyne.examples.authentication'

def __init__(self):
Fault.__init__(self,
super(UnauthenticatedError, self).__init__(
faultcode='Client.UnauthenticatedError',
faultstring='This resource can only be accessed after authentication.'
)
Expand Down
8 changes: 4 additions & 4 deletions examples/authentication/server_soap.py
Expand Up @@ -57,11 +57,11 @@
from spyne.service import ServiceBase


class PublicKeyError(ResourceNotFoundError):
class PublicKeyError(Fault):
__namespace__ = 'spyne.examples.authentication'

def __init__(self, value):
ResourceNotFoundError.__init__(self,
super(PublicKeyError, self).__init__(
faultstring='Value %r not found' % value
)

Expand All @@ -72,7 +72,7 @@ class AuthenticationError(Fault):
def __init__(self, user_name):
# TODO: self.transport.http.resp_code = HTTP_401

Fault.__init__(self,
super(AuthenticationError, self).__init__(
faultcode='Client.AuthenticationError',
faultstring='Invalid authentication request for %r' % user_name
)
Expand All @@ -84,7 +84,7 @@ class AuthorizationError(Fault):
def __init__(self):
# TODO: self.transport.http.resp_code = HTTP_401

Fault.__init__(self,
super(AuthorizationError, self).__init__(
faultcode='Client.AuthorizationError',
faultstring='You are not authozied to access this resource.'
)
Expand Down
2 changes: 1 addition & 1 deletion examples/multiple_protocols/protocol.py
Expand Up @@ -45,7 +45,7 @@ class SvgClock(ProtocolBase):
mime_type = 'image/svg+xml'

def __init__(self, app=None):
ProtocolBase.__init__(self, app, validator=None)
super(SvgClock, self).__init__(app, validator=None)

self.length = 500 # if you change this, you should re-scale the svg file
# as well.
Expand Down
6 changes: 3 additions & 3 deletions examples/queue.py
Expand Up @@ -85,7 +85,7 @@ class Consumer(ServerBase):
transport = 'http://sqlalchemy.persistent.queue/'

def __init__(self, db, app, consumer_id):
ServerBase.__init__(self, app)
super(Consumer, self).__init__(app)

self.session = sessionmaker(bind=db)()
self.id = consumer_id
Expand Down Expand Up @@ -152,7 +152,7 @@ def serve_forever(self):

class RemoteProcedure(RemoteProcedureBase):
def __init__(self, db, app, name, out_header):
RemoteProcedureBase.__init__(self, db, app, name, out_header)
super(RemoteProcedure, self).__init__(db, app, name, out_header)

self.Session = sessionmaker(bind=db)

Expand All @@ -174,7 +174,7 @@ def __call__(self, *args, **kwargs):

class Producer(ClientBase):
def __init__(self, db, app):
ClientBase.__init__(self, db, app)
super(Producer, self).__init__(db, app)

self.service = Service(RemoteProcedure, db, app)

Expand Down
2 changes: 1 addition & 1 deletion examples/template/template/application.py
Expand Up @@ -57,7 +57,7 @@ def _on_method_context_closed(ctx):
class MyApplication(Application):
def __init__(self, services, tns, name=None,
in_protocol=None, out_protocol=None):
Application.__init__(self, services, tns, name, in_protocol,
super(MyApplication, self).__init__(services, tns, name, in_protocol,
out_protocol)

self.event_manager.add_listener('method_call', _on_method_call)
Expand Down
2 changes: 1 addition & 1 deletion examples/user_manager/server_sqlalchemy.py
Expand Up @@ -144,7 +144,7 @@ def _on_method_context_closed(ctx):
class MyApplication(Application):
def __init__(self, services, tns, name=None,
in_protocol=None, out_protocol=None):
Application.__init__(self, services, tns, name, in_protocol,
super(MyApplication, self).__init__(services, tns, name, in_protocol,
out_protocol)

self.event_manager.add_listener('method_call', _on_method_call)
Expand Down
2 changes: 1 addition & 1 deletion spyne/auxproc/thread.py
Expand Up @@ -36,7 +36,7 @@ class ThreadAuxProc(AuxProcBase):
"""

def __init__(self, pool_size=1):
AuxProcBase.__init__(self)
super(ThreadAuxProc, self).__init__()

self.pool = None
self.__pool_size = pool_size
Expand Down
2 changes: 1 addition & 1 deletion spyne/client/twisted/__init__.py
Expand Up @@ -138,6 +138,6 @@ def _cb_request(response):

class TwistedHttpClient(ClientBase):
def __init__(self, url, app):
ClientBase.__init__(self, url, app)
super(TwistedHttpClient, self).__init__(url, app)

self.service = Service(_RemoteProcedure, url, app)
2 changes: 1 addition & 1 deletion spyne/client/zeromq.py
Expand Up @@ -49,6 +49,6 @@ def __call__(self, *args, **kwargs):

class ZeroMQClient(ClientBase):
def __init__(self, url, app):
ClientBase.__init__(self, url, app)
super(ZeroMQClient, self).__init__(url, app)

self.service = Service(_RemoteProcedure, url, app)
16 changes: 8 additions & 8 deletions spyne/error.py
Expand Up @@ -32,7 +32,7 @@ class ResourceNotFoundError(Fault):

def __init__(self, fault_object,
fault_string="Requested resource %r not found"):
Fault.__init__(self, 'Client.ResourceNotFound',
super(ResourceNotFoundError, self).__init__('Client.ResourceNotFound',
fault_string % fault_object)


Expand All @@ -41,35 +41,35 @@ class InvalidCredentialsError(Fault):

def __init__(self, fault_object,
fault_string="You do not have permission to access this resource"):
Fault.__init__(self, 'Client.InvalidCredentialsError', fault_string)
super(InvalidCredentialsError, self).__init__('Client.InvalidCredentialsError', fault_string)


class RequestTooLongError(Fault):
"""Raised when request is too long."""

def __init__(self, faultstring="Request too long"):
Fault.__init__(self, 'Client.RequestTooLong', faultstring)
super(RequestTooLongError, self).__init__('Client.RequestTooLong', faultstring)


class RequestNotAllowed(Fault):
"""Raised when request is incomplete."""

def __init__(self, faultstring=""):
Fault.__init__(self, 'Client.RequestNotAllowed', faultstring)
super(RequestNotAllowed, self).__init__('Client.RequestNotAllowed', faultstring)


class ArgumentError(Fault):
"""Raised when there is a general problem with input data."""

def __init__(self, faultstring=""):
Fault.__init__(self, 'Client.ArgumentError', faultstring)
super(ArgumentError, self).__init__('Client.ArgumentError', faultstring)


class InvalidInputError(Fault):
"""Raised when there is a general problem with input data."""

def __init__(self, faultstring="", data=""):
Fault.__init__(self, 'Client.InvalidInput', repr((faultstring, data)))
super(InvalidInputError, self).__init__('Client.InvalidInput', repr((faultstring, data)))

InvalidRequestError = InvalidInputError

Expand All @@ -82,10 +82,10 @@ def __init__(self, obj, custom_msg='The value %r could not be validated.'):
if len(s) > MAX_STRING_FIELD_LENGTH:
s = s[:MAX_STRING_FIELD_LENGTH] + "(...)"

Fault.__init__(self, 'Client.ValidationError', custom_msg % s)
super(ValidationError, self).__init__('Client.ValidationError', custom_msg % s)


class InternalError(Fault):
"""Raised to communicate server-side errors."""
def __init__(self, error):
Fault.__init__(self, 'Server', "InternalError: An unknown error has occured.")
super(InternalError, self).__init__('Server', "InternalError: An unknown error has occured.")
2 changes: 1 addition & 1 deletion spyne/interface/wsdl/wsdl11.py
Expand Up @@ -146,7 +146,7 @@ class Wsdl11(XmlSchema):
# xsd, xsi, wsdl, etc.

def __init__(self, interface=None, _with_partnerlink=False):
XmlSchema.__init__(self, interface)
super(Wsdl11, self).__init__(interface)

self._with_plink = _with_partnerlink

Expand Down
2 changes: 1 addition & 1 deletion spyne/interface/xml_schema/_base.py
Expand Up @@ -109,7 +109,7 @@ class XmlSchema(InterfaceDocumentBase):
"""

def __init__(self, interface):
InterfaceDocumentBase.__init__(self, interface)
super(XmlSchema, self).__init__(interface)

self.schema_dict = {}
self.validation_schema = None
Expand Down
31 changes: 17 additions & 14 deletions spyne/model/_base.py
Expand Up @@ -63,7 +63,7 @@ def __new__(cls, cls_name, cls_bases, cls_dict):
if not 'sqla_mapper_args' in cls_dict:
cls_dict['sqla_mapper_args'] = None

return type(object).__new__(cls, cls_name, cls_bases, cls_dict)
return super(AttributesMeta, cls).__new__(cls, cls_name, cls_bases, cls_dict)

def __init__(self, cls_name, cls_bases, cls_dict):
nullable = cls_dict.get('nullable', None)
Expand All @@ -79,7 +79,7 @@ def __init__(self, cls_name, cls_bases, cls_dict):
if getattr(self, '_nullable', None) is None:
self._nullable = None

type(object).__init__(self, cls_name, cls_bases, cls_dict)
super(AttributesMeta, self).__init__(cls_name, cls_bases, cls_dict)

def get_nullable(self):
return (self._nullable if self._nullable is not None else
Expand Down Expand Up @@ -437,6 +437,20 @@ class Null(ModelBase):
pass


class SimpleModelAttributesMeta(ModelBase.Attributes.__metaclass__):
def __init__(self, cls_name, cls_bases, cls_dict):
super(SimpleModelAttributesMeta, self).__init__(cls_name, cls_bases, cls_dict)
if getattr(self, '_pattern', None) is None:
self._pattern = None
def get_pattern(self):
return self._pattern
def set_pattern(self, pattern):
self._pattern = pattern
if pattern is not None:
self._pattern_re = re.compile(pattern)
pattern = property(get_pattern, set_pattern)


class SimpleModel(ModelBase):
"""The base class for primitives."""

Expand All @@ -445,18 +459,7 @@ class SimpleModel(ModelBase):
class Attributes(ModelBase.Attributes):
"""The class that holds the constraints for the given type."""

class __metaclass__(AttributesMeta):
def __init__(self, cls_name, cls_bases, cls_dict):
AttributesMeta.__init__(self, cls_name, cls_bases, cls_dict)
if getattr(self, '_pattern', None) is None:
self._pattern = None
def get_pattern(self):
return self._pattern
def set_pattern(self, pattern):
self._pattern = pattern
if pattern is not None:
self._pattern_re = re.compile(pattern)
pattern = property(get_pattern, set_pattern)
__metaclass__ = SimpleModelAttributesMeta

values = set()
"""The set of possible values for this type."""
Expand Down
8 changes: 4 additions & 4 deletions spyne/model/complex.py
Expand Up @@ -131,7 +131,7 @@ def __init__(self):

class TypeInfo(odict):
def __init__(self, *args, **kwargs):
odict.__init__(self, *args, **kwargs)
super(TypeInfo, self).__init__(*args, **kwargs)
self.attributes = {}


Expand Down Expand Up @@ -211,7 +211,7 @@ class XmlAttribute(XmlModifier):
"""

def __new__(cls, type_, use=None, ns=None, attribute_of=None):
retval = XmlModifier.__new__(cls, type_, ns)
retval = super(XmlAttribute, cls).__new__(cls, type_, ns)
retval._use = use
retval.attribute_of = attribute_of
return retval
Expand Down Expand Up @@ -412,7 +412,7 @@ class Attributes(b.Attributes):
targs = cls_dict.get('__table_args__', None)
attrs.sqla_table_args = _join_args(attrs.sqla_table_args, targs)

return type(ModelBase).__new__(cls, cls_name, cls_bases, cls_dict)
return super(ComplexModelMeta, cls).__new__(cls, cls_name, cls_bases, cls_dict)

def __init__(self, cls_name, cls_bases, cls_dict):
type_info = cls_dict['_type_info']
Expand Down Expand Up @@ -457,7 +457,7 @@ def __init__(self, cls_name, cls_bases, cls_dict):

gen_sqla_info(self, cls_bases)

type(ModelBase).__init__(self, cls_name, cls_bases, cls_dict)
super(ComplexModelMeta, self).__init__(cls_name, cls_bases, cls_dict)


# FIXME: what an ugly hack.
Expand Down
2 changes: 1 addition & 1 deletion spyne/model/table.py
Expand Up @@ -202,7 +202,7 @@ def check_same_table_inheritance(bases):
if _is_interesting(k, v):
_type_info[k] = _process_item(v)

return DeclarativeMeta.__new__(cls, cls_name, cls_bases, cls_dict)
return super(TableModelMeta, cls).__new__(cls, cls_name, cls_bases, cls_dict)


class TableModel(ComplexModelBase):
Expand Down
2 changes: 1 addition & 1 deletion spyne/protocol/dictdoc.py
Expand Up @@ -205,7 +205,7 @@ class DictDocument(ProtocolBase):
def __init__(self, app=None, validator=None, mime_type=None,
ignore_uncap=False, ignore_wrappers=True, complex_as=dict,
ordered=False):
ProtocolBase.__init__(self, app, validator, mime_type, ignore_uncap)
super(DictDocument, self).__init__(app, validator, mime_type, ignore_uncap)

self.ignore_wrappers = ignore_wrappers
self.complex_as = complex_as
Expand Down
6 changes: 3 additions & 3 deletions spyne/protocol/html.py
Expand Up @@ -104,7 +104,7 @@ def __init__(self, app=None, validator=None):
type names of the complex object children.
"""

ProtocolBase.__init__(self, app, validator)
super(HtmlBase, self).__init__(app, validator)

def serialize_class(self, cls, value, locale, name):
handler = self.serialization_handlers[cls]
Expand Down Expand Up @@ -189,7 +189,7 @@ def __init__(self, app=None, validator=None, root_tag='div',
inside separate tags.
"""

HtmlBase.__init__(self, app, validator)
super(HtmlMicroFormat, self).__init__(app, validator)

assert root_tag in ('div', 'span')
assert child_tag in ('div', 'span')
Expand Down Expand Up @@ -323,7 +323,7 @@ class _HtmlTableBase(HtmlBase):
def __init__(self, app, validator, produce_header, table_name_attr,
field_name_attr, border, row_class, cell_class, header_cell_class):

HtmlBase.__init__(self, app, validator)
super(_HtmlTableBase, self).__init__(app, validator)

assert table_name_attr in (None, 'class', 'id')
assert field_name_attr in (None, 'class', 'id')
Expand Down
2 changes: 1 addition & 1 deletion spyne/protocol/http.py
Expand Up @@ -114,7 +114,7 @@ class HttpRpc(SimpleDictDocument):
def __init__(self, app=None, validator=None, mime_type=None,
tmp_dir=None, tmp_delete_on_close=True, ignore_uncap=False,
parse_cookie=False):
SimpleDictDocument.__init__(self, app, validator, mime_type,
super(HttpRpc, self).__init__(app, validator, mime_type,
ignore_uncap=ignore_uncap)

self.tmp_dir = tmp_dir
Expand Down
2 changes: 1 addition & 1 deletion spyne/protocol/json.py
Expand Up @@ -112,7 +112,7 @@ def __init__(self, app=None, validator=None, mime_type=None,
default_string_encoding=None,
**kwargs):

HierDictDocument.__init__(self, app, validator, mime_type, ignore_uncap,
super(JsonDocument, self).__init__(app, validator, mime_type, ignore_uncap,
ignore_wrappers, complex_as, ordered)

# this is needed when we're overriding a regular instance attribute
Expand Down

0 comments on commit 0c40ff4

Please sign in to comment.