Minor code cleanups

Change-Id: I338656e8f131b36aae342af94f1c2cedad14ae2b
This commit is contained in:
Julien Danjou 2013-09-18 11:18:28 +02:00
parent 15c05263c3
commit a04748e868
5 changed files with 18 additions and 21 deletions

View File

@ -83,8 +83,8 @@ class FunctionDefinition(object):
#: Dictionnary of protocol-specific options.
self.extra_options = None
@classmethod
def get(cls, func):
@staticmethod
def get(func):
"""
Returns the :class:`FunctionDefinition` of a method.
"""

View File

@ -12,25 +12,25 @@ class expose(object):
return self.signature(func)
@classmethod
def with_method(self, method, *args, **kwargs):
def with_method(cls, method, *args, **kwargs):
kwargs['method'] = method
return expose(*args, **kwargs)
return cls(*args, **kwargs)
@classmethod
def get(cls, *args, **kwargs):
return expose.with_method('GET', *args, **kwargs)
return cls.with_method('GET', *args, **kwargs)
@classmethod
def post(cls, *args, **kwargs):
return expose.with_method('POST', *args, **kwargs)
return cls.with_method('POST', *args, **kwargs)
@classmethod
def put(cls, *args, **kwargs):
return expose.with_method('PUT', *args, **kwargs)
return cls.with_method('PUT', *args, **kwargs)
@classmethod
def delete(cls, *args, **kwargs):
return expose.with_method('DELETE', *args, **kwargs)
return cls.with_method('DELETE', *args, **kwargs)
class validate(object):

View File

@ -438,15 +438,12 @@ def inspect_class(class_):
if inspect.isroutine(attr):
continue
if isinstance(attr, wsattr):
attrdef = attr
elif isinstance(attr, wsproperty):
if isinstance(attr, (wsattr, wsproperty)):
attrdef = attr
else:
if attr not in native_types and (
inspect.isclass(attr)
or isinstance(attr, list)
or isinstance(attr, dict)):
or isinstance(attr, (list, dict))):
register_type(attr)
attrdef = getattr(class_, '__wsattrclass__', wsattr)(attr)

View File

@ -76,7 +76,7 @@ class SampleType(object):
@classmethod
def sample(cls):
return SampleType(10)
return cls(10)
class SampleService(wsme.WSRoot):
@ -194,8 +194,8 @@ class TypeDocumenter(autodoc.ClassDocumenter):
'samples-slot': check_samples_slot,
})
@classmethod
def can_document_member(cls, member, membername, isattr, parent):
@staticmethod
def can_document_member(member, membername, isattr, parent):
# we don't want to be automaticaly used
# TODO check if the member is registered an an exposed type
return False
@ -271,8 +271,8 @@ class AttributeDocumenter(autodoc.AttributeDocumenter):
datatype = None
domain = 'wsme'
@classmethod
def can_document_member(cls, member, membername, isattr, parent):
@staticmethod
def can_document_member(member, membername, isattr, parent):
return isinstance(parent, TypeDocumenter)
def import_object(self):
@ -483,8 +483,8 @@ class FunctionDocumenter(autodoc.MethodDocumenter):
'method': directives.unchanged
}
@classmethod
def can_document_member(cls, member, membername, isattr, parent):
@staticmethod
def can_document_member(member, membername, isattr, parent):
return (isinstance(parent, ServiceDocumenter)
and wsme.api.iswsmefunction(member))

View File

@ -18,7 +18,7 @@ class SQLAlchemyRegistry(object):
@classmethod
def get(cls, registry):
if not hasattr(registry, 'sqlalchemy'):
registry.sqlalchemy = SQLAlchemyRegistry()
registry.sqlalchemy = cls()
return registry.sqlalchemy
def __init__(self):