summaryrefslogtreecommitdiff
path: root/pecan/decorators.py
diff options
context:
space:
mode:
authorJonathan LaCour <jonathan@cleverdevil.org>2010-10-11 18:09:35 -0400
committerJonathan LaCour <jonathan@cleverdevil.org>2010-10-11 18:09:35 -0400
commitb7e444628e41b40b2bc29c81781dee3f44b62a80 (patch)
tree8fc2d2879352ff464fbe9b8cdfca295fbb19e5ec /pecan/decorators.py
parent1bc441876ba13a3ef1b07cbead8d3b9e29a5fabf (diff)
downloadpecan-b7e444628e41b40b2bc29c81781dee3f44b62a80.tar.gz
Adding validation support.
Diffstat (limited to 'pecan/decorators.py')
-rw-r--r--pecan/decorators.py31
1 files changed, 25 insertions, 6 deletions
diff --git a/pecan/decorators.py b/pecan/decorators.py
index 8927702..7dce90a 100644
--- a/pecan/decorators.py
+++ b/pecan/decorators.py
@@ -1,18 +1,37 @@
from inspect import getargspec
-def expose(template=None, content_type='text/html'):
+def _cfg(f):
+ if not hasattr(f, 'pecan'): f.pecan = {}
+ return f.pecan
+
+
+def expose(template = None,
+ content_type = 'text/html',
+ schema = None,
+ json_schema = None,
+ error_handler = None):
+
if template == 'json': content_type = 'application/json'
def decorate(f):
# flag the method as exposed
f.exposed = True
# set a "pecan" attribute, where we will store details
- if not hasattr(f, 'pecan'): f.pecan = {}
- f.pecan['content_type'] = content_type
- f.pecan.setdefault('template', []).append(template)
- f.pecan.setdefault('content_types', {})[content_type] = template
+ cfg = _cfg(f)
+ cfg['content_type'] = content_type
+ cfg.setdefault('template', []).append(template)
+ cfg.setdefault('content_types', {})[content_type] = template
# store the arguments for this controller method
- f.pecan['argspec'] = getargspec(f)
+ cfg['argspec'] = getargspec(f)
+
+ # store the validator
+ cfg['error_handler'] = error_handler
+ if schema is not None:
+ cfg['schema'] = schema
+ cfg['validate_json'] = False
+ elif json_schema is not None:
+ cfg['schema'] = json_schema
+ cfg['validate_json'] = True
return f
return decorate \ No newline at end of file