Introduce a new decorator: 'sig', which combines expose and validate in a single decorator.

This commit is contained in:
Christophe de Vienne 2012-10-13 21:08:17 +02:00
parent 7cad370657
commit 97f1b197ce
2 changed files with 14 additions and 2 deletions

View File

@ -1,7 +1,8 @@
from wsme.api import expose, validate from wsme.api import sig, expose, validate
from wsme.root import WSRoot from wsme.root import WSRoot
from wsme.types import wsattr, wsproperty, Unset from wsme.types import wsattr, wsproperty, Unset
__all__ = ['expose', 'validate', __all__ = [
'expose', 'validate', 'sig',
'WSRoot', 'WSRoot',
'wsattr', 'wsproperty', 'Unset'] 'wsattr', 'wsproperty', 'Unset']

View File

@ -156,6 +156,17 @@ class expose(object):
return func return func
class sig(object):
def __init__(self, return_type, *param_types, **options):
self.expose = expose(return_type, **options)
self.validate = validate(*param_types)
def __call__(self, func):
func = self.expose(func)
func = self.validate(func)
return func
class pexpose(object): class pexpose(object):
def __init__(self, return_type=None, contenttype=None): def __init__(self, return_type=None, contenttype=None):
self.return_type = return_type self.return_type = return_type