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
This commit is contained in:
parent
ffd8758b90
commit
843c6a3d0f
@ -14,9 +14,7 @@ Then::
|
|||||||
from webob.dec import wsgify
|
from webob.dec import wsgify
|
||||||
from wsme import *
|
from wsme import *
|
||||||
|
|
||||||
import wsme.restjson
|
from wsme.protocols import restxml, restjson, soap
|
||||||
import wsme.restxml
|
|
||||||
import wsme.soap
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -128,19 +128,22 @@ class validate(object):
|
|||||||
|
|
||||||
|
|
||||||
class WSRoot(object):
|
class WSRoot(object):
|
||||||
def __init__(self, protocols=None):
|
def __init__(self, protocols=[]):
|
||||||
self._debug = True
|
self._debug = True
|
||||||
if protocols is None:
|
if protocols is None:
|
||||||
protocols = registered_protocols.keys()
|
protocols = registered_protocols.keys()
|
||||||
self.protocols = {}
|
self.protocols = {}
|
||||||
for protocol in protocols:
|
for protocol in protocols:
|
||||||
if isinstance(protocol, str):
|
self.addprotocol(protocol)
|
||||||
protocol = registered_protocols[protocol]()
|
|
||||||
self.protocols[protocol.name] = protocol
|
|
||||||
protocol.root = weakref.proxy(self)
|
|
||||||
|
|
||||||
self._api = None
|
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):
|
def getapi(self):
|
||||||
if self._api is None:
|
if self._api is None:
|
||||||
self._api = [i for i in scan_api(self)]
|
self._api = [i for i in scan_api(self)]
|
||||||
|
0
wsme/protocols/templates/__init__.py
Normal file
0
wsme/protocols/templates/__init__.py
Normal file
@ -75,6 +75,9 @@ class TestController(unittest.TestCase):
|
|||||||
assert wsme.controller.registered_protocols['dummy'] == DummyProtocol
|
assert wsme.controller.registered_protocols['dummy'] == DummyProtocol
|
||||||
|
|
||||||
r = WSRoot()
|
r = WSRoot()
|
||||||
|
assert len(r.protocols) == 0
|
||||||
|
|
||||||
|
r.addprotocol('dummy')
|
||||||
assert r.protocols['dummy']
|
assert r.protocols['dummy']
|
||||||
|
|
||||||
r = WSRoot(['dummy'])
|
r = WSRoot(['dummy'])
|
||||||
|
@ -2,12 +2,13 @@ import decimal
|
|||||||
import base64
|
import base64
|
||||||
|
|
||||||
import wsme.tests.protocol
|
import wsme.tests.protocol
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
except:
|
except:
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import wsme.restjson
|
import wsme.protocols.restjson
|
||||||
from wsme.utils import *
|
from wsme.utils import *
|
||||||
|
|
||||||
def prepare_value(value, datatype):
|
def prepare_value(value, datatype):
|
||||||
|
@ -10,7 +10,7 @@ try:
|
|||||||
except:
|
except:
|
||||||
import cElementTree as et
|
import cElementTree as et
|
||||||
|
|
||||||
import wsme.restxml
|
import wsme.protocols.restxml
|
||||||
|
|
||||||
|
|
||||||
def dumpxml(key, obj, datatype=None):
|
def dumpxml(key, obj, datatype=None):
|
||||||
|
@ -9,7 +9,7 @@ try:
|
|||||||
except:
|
except:
|
||||||
import cElementTree as et
|
import cElementTree as et
|
||||||
|
|
||||||
import wsme.soap
|
from wsme.protocols.soap import SoapProtocol
|
||||||
import wsme.utils
|
import wsme.utils
|
||||||
|
|
||||||
tns = "http://foo.bar.baz/soap/"
|
tns = "http://foo.bar.baz/soap/"
|
||||||
@ -114,7 +114,7 @@ def fromsoap(el):
|
|||||||
|
|
||||||
|
|
||||||
class TestSOAP(wsme.tests.protocol.ProtocolTestCase):
|
class TestSOAP(wsme.tests.protocol.ProtocolTestCase):
|
||||||
protocol = wsme.soap.SoapProtocol(
|
protocol = SoapProtocol(
|
||||||
tns=tns, typenamespace=typenamespace)
|
tns=tns, typenamespace=typenamespace)
|
||||||
|
|
||||||
def test_simple_call(self):
|
def test_simple_call(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user