From d69a287ba4fb78d0edc921f663ea4fd944f2661e Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 9 Jan 2014 18:49:33 +0100 Subject: [PATCH] pecan: cleanup, use global vars and staticmethod Change-Id: If5a7c1b4b71380053ed650ddc8e9928422869807 --- wsmeext/pecan.py | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/wsmeext/pecan.py b/wsmeext/pecan.py index 66b9e7a..41c0334 100644 --- a/wsmeext/pecan.py +++ b/wsmeext/pecan.py @@ -15,10 +15,12 @@ from wsme.utils import is_valid_code class JSonRenderer(object): - def __init__(self, path, extra_vars): + @staticmethod + def __init__(path, extra_vars): pass - def render(self, template_path, namespace): + @staticmethod + def render(template_path, namespace): if 'faultcode' in namespace: return wsme.rest.json.encode_error(None, namespace) return wsme.rest.json.encode_result( @@ -28,10 +30,12 @@ class JSonRenderer(object): class XMLRenderer(object): - def __init__(self, path, extra_vars): + @staticmethod + def __init__(path, extra_vars): pass - def render(self, template_path, namespace): + @staticmethod + def render(template_path, namespace): if 'faultcode' in namespace: return wsme.rest.xml.encode_error(None, namespace) return wsme.rest.xml.encode_result( @@ -42,22 +46,23 @@ class XMLRenderer(object): pecan.templating._builtin_renderers['wsmejson'] = JSonRenderer pecan.templating._builtin_renderers['wsmexml'] = XMLRenderer +pecan_json_decorate = pecan.expose( + template='wsmejson:', + content_type='application/json', + generic=False) +pecan_xml_decorate = pecan.expose( + template='wsmexml:', + content_type='application/xml', + generic=False +) +pecan_text_xml_decorate = pecan.expose( + template='wsmexml:', + content_type='text/xml', + generic=False +) + def wsexpose(*args, **kwargs): - pecan_json_decorate = pecan.expose( - template='wsmejson:', - content_type='application/json', - generic=False) - pecan_xml_decorate = pecan.expose( - template='wsmexml:', - content_type='application/xml', - generic=False - ) - pecan_text_xml_decorate = pecan.expose( - template='wsmexml:', - content_type='text/xml', - generic=False - ) sig = wsme.signature(*args, **kwargs) def decorate(f):