From 188786441568e0013145c39bcf1e1fd01eb4c92f Mon Sep 17 00:00:00 2001 From: Burak Arslan Date: Sun, 28 Oct 2012 03:57:38 +0300 Subject: [PATCH] Finalize HttpPattern object and its converter to werkzeug.routing.Rule. --- spyne/_base.py | 2 +- spyne/protocol/http.py | 21 ++++++++++----------- spyne/service.py | 3 +++ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/spyne/_base.py b/spyne/_base.py index 34c813823..c58357551 100644 --- a/spyne/_base.py +++ b/spyne/_base.py @@ -348,7 +348,7 @@ def __init__(self, function, in_message, out_message, doc, various elements of the request protocol. Currently, the only object supported here is the - :class:`spyne.protocol.http.HttpRoute` object. + :class:`spyne.protocol.http.HttpPattern` object. """ @property diff --git a/spyne/protocol/http.py b/spyne/protocol/http.py index 92ca1fd12..960cb24eb 100644 --- a/spyne/protocol/http.py +++ b/spyne/protocol/http.py @@ -40,7 +40,6 @@ from spyne.protocol.dictobj import DictObject - def get_stream_factory(dir=None, delete=True): def stream_factory(total_content_length, filename, content_type, content_length=None): @@ -158,7 +157,7 @@ def create_out_string(self, ctx, out_string_encoding='utf8'): ctx.out_string = ctx.out_document -class HttpRoute(object): +class HttpPattern(object): """Experimental. Stay away. :param address: Address pattern @@ -166,19 +165,19 @@ class HttpRoute(object): :param host: HTTP "Host:" header pattern """ - def __init__(self, address, verb=None, host=None): + def __init__(self, address, verb=None, host=None, endpoint=None): self.address = address self.host = host self.verb = verb - self._callable = None + self.endpoint = endpoint - def for_werkzeug(self): + def as_werkzeug_rule(self): from werkzeug.routing import Rule from spyne.util.invregex import invregex - if self.verb is None: - for v in invregex(self.verb): - yield Rule(self.address, host=self.host, endpoint=self._callable, - verb=v) - else: - yield Rule(self.address, host=self.host, endpoint=self._callable) + methods = None + if self.verb is not None: + methods = invregex(self.verb) + + return Rule(self.address, host=self.host, endpoint=self.endpoint, + methods=methods) diff --git a/spyne/service.py b/spyne/service.py index e11f7d832..64b03fdd9 100644 --- a/spyne/service.py +++ b/spyne/service.py @@ -55,6 +55,9 @@ def __init__(self, cls_name, cls_bases, cls_dict): else: self.__has_aux_methods = True + for p in descriptor.patterns: + p.endpoint = k + def __get_base_event_handlers(self, cls_bases): handlers = {}