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. #: Dictionnary of protocol-specific options.
self.extra_options = None self.extra_options = None
@classmethod @staticmethod
def get(cls, func): def get(func):
""" """
Returns the :class:`FunctionDefinition` of a method. Returns the :class:`FunctionDefinition` of a method.
""" """

View File

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

View File

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

View File

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

View File

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