From 843c6a3d0f04c73d737c8e236c5ded245797607c Mon Sep 17 00:00:00 2001 From: Christophe de Vienne Date: Sat, 1 Oct 2011 20:16:57 +0200 Subject: [PATCH] Move the protocols to a dedicated module, and their activation more explicit --HG-- rename : wsme/restjson.py => wsme/protocols/restjson.py rename : wsme/restxml.py => wsme/protocols/restxml.py rename : wsme/soap.py => wsme/protocols/soap.py rename : wsme/templates/__init__.py => wsme/protocols/templates/__init__.py rename : wsme/templates/fault.html => wsme/protocols/templates/fault.html rename : wsme/templates/soap.html => wsme/protocols/templates/soap.html rename : wsme/templates/wsdl.html => wsme/protocols/templates/wsdl.html --- examples/demo/demo.py | 4 +--- wsme/controller.py | 13 ++++++++----- wsme/{templates => protocols}/__init__.py | 0 wsme/{ => protocols}/restjson.py | 0 wsme/{ => protocols}/restxml.py | 0 wsme/{ => protocols}/soap.py | 0 wsme/protocols/templates/__init__.py | 0 wsme/{ => protocols}/templates/fault.html | 0 wsme/{ => protocols}/templates/soap.html | 0 wsme/{ => protocols}/templates/wsdl.html | 0 wsme/tests/test_controller.py | 3 +++ wsme/tests/test_restjson.py | 3 ++- wsme/tests/test_restxml.py | 2 +- wsme/tests/test_soap.py | 4 ++-- 14 files changed, 17 insertions(+), 12 deletions(-) rename wsme/{templates => protocols}/__init__.py (100%) rename wsme/{ => protocols}/restjson.py (100%) rename wsme/{ => protocols}/restxml.py (100%) rename wsme/{ => protocols}/soap.py (100%) create mode 100644 wsme/protocols/templates/__init__.py rename wsme/{ => protocols}/templates/fault.html (100%) rename wsme/{ => protocols}/templates/soap.html (100%) rename wsme/{ => protocols}/templates/wsdl.html (100%) diff --git a/examples/demo/demo.py b/examples/demo/demo.py index 340ee4e..a185b93 100644 --- a/examples/demo/demo.py +++ b/examples/demo/demo.py @@ -14,9 +14,7 @@ Then:: from webob.dec import wsgify from wsme import * -import wsme.restjson -import wsme.restxml -import wsme.soap +from wsme.protocols import restxml, restjson, soap import logging diff --git a/wsme/controller.py b/wsme/controller.py index 1ed618d..5b19d1a 100644 --- a/wsme/controller.py +++ b/wsme/controller.py @@ -128,19 +128,22 @@ class validate(object): class WSRoot(object): - def __init__(self, protocols=None): + def __init__(self, protocols=[]): self._debug = True if protocols is None: protocols = registered_protocols.keys() self.protocols = {} for protocol in protocols: - if isinstance(protocol, str): - protocol = registered_protocols[protocol]() - self.protocols[protocol.name] = protocol - protocol.root = weakref.proxy(self) + self.addprotocol(protocol) self._api = None + def addprotocol(self, protocol): + if isinstance(protocol, str): + protocol = registered_protocols[protocol]() + self.protocols[protocol.name] = protocol + protocol.root = weakref.proxy(self) + def getapi(self): if self._api is None: self._api = [i for i in scan_api(self)] diff --git a/wsme/templates/__init__.py b/wsme/protocols/__init__.py similarity index 100% rename from wsme/templates/__init__.py rename to wsme/protocols/__init__.py diff --git a/wsme/restjson.py b/wsme/protocols/restjson.py similarity index 100% rename from wsme/restjson.py rename to wsme/protocols/restjson.py diff --git a/wsme/restxml.py b/wsme/protocols/restxml.py similarity index 100% rename from wsme/restxml.py rename to wsme/protocols/restxml.py diff --git a/wsme/soap.py b/wsme/protocols/soap.py similarity index 100% rename from wsme/soap.py rename to wsme/protocols/soap.py diff --git a/wsme/protocols/templates/__init__.py b/wsme/protocols/templates/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/wsme/templates/fault.html b/wsme/protocols/templates/fault.html similarity index 100% rename from wsme/templates/fault.html rename to wsme/protocols/templates/fault.html diff --git a/wsme/templates/soap.html b/wsme/protocols/templates/soap.html similarity index 100% rename from wsme/templates/soap.html rename to wsme/protocols/templates/soap.html diff --git a/wsme/templates/wsdl.html b/wsme/protocols/templates/wsdl.html similarity index 100% rename from wsme/templates/wsdl.html rename to wsme/protocols/templates/wsdl.html diff --git a/wsme/tests/test_controller.py b/wsme/tests/test_controller.py index 7ad8719..6b6beb8 100644 --- a/wsme/tests/test_controller.py +++ b/wsme/tests/test_controller.py @@ -75,6 +75,9 @@ class TestController(unittest.TestCase): assert wsme.controller.registered_protocols['dummy'] == DummyProtocol r = WSRoot() + assert len(r.protocols) == 0 + + r.addprotocol('dummy') assert r.protocols['dummy'] r = WSRoot(['dummy']) diff --git a/wsme/tests/test_restjson.py b/wsme/tests/test_restjson.py index 86907d8..a965155 100644 --- a/wsme/tests/test_restjson.py +++ b/wsme/tests/test_restjson.py @@ -2,12 +2,13 @@ import decimal import base64 import wsme.tests.protocol + try: import simplejson as json except: import json -import wsme.restjson +import wsme.protocols.restjson from wsme.utils import * def prepare_value(value, datatype): diff --git a/wsme/tests/test_restxml.py b/wsme/tests/test_restxml.py index 80b0845..550e178 100644 --- a/wsme/tests/test_restxml.py +++ b/wsme/tests/test_restxml.py @@ -10,7 +10,7 @@ try: except: import cElementTree as et -import wsme.restxml +import wsme.protocols.restxml def dumpxml(key, obj, datatype=None): diff --git a/wsme/tests/test_soap.py b/wsme/tests/test_soap.py index c76f7ca..f0e3447 100644 --- a/wsme/tests/test_soap.py +++ b/wsme/tests/test_soap.py @@ -9,7 +9,7 @@ try: except: import cElementTree as et -import wsme.soap +from wsme.protocols.soap import SoapProtocol import wsme.utils tns = "http://foo.bar.baz/soap/" @@ -114,7 +114,7 @@ def fromsoap(el): class TestSOAP(wsme.tests.protocol.ProtocolTestCase): - protocol = wsme.soap.SoapProtocol( + protocol = SoapProtocol( tns=tns, typenamespace=typenamespace) def test_simple_call(self):