Add a WSGI adapter
This commit is contained in:
parent
e16ae8e34a
commit
6973868bd3
@ -11,8 +11,8 @@ Then::
|
||||
paster serve demo.cfg
|
||||
"""
|
||||
|
||||
from webob.dec import wsgify
|
||||
from wsme import *
|
||||
from wsme.wsgi import WSRoot
|
||||
|
||||
from wsme.protocols import restxml, restjson, soap
|
||||
|
||||
@ -45,11 +45,12 @@ class DemoRoot(WSRoot):
|
||||
return p
|
||||
|
||||
def app_factory(global_config, **local_conf):
|
||||
soap = wsme.soap.SoapProtocol(
|
||||
tns='http://example.com/demo',
|
||||
typenamespace='http://example.com/demo/types',
|
||||
baseURL='http://127.0.0.1:8989/',
|
||||
)
|
||||
return wsgify(DemoRoot([soap])._handle_request)
|
||||
protocols = [
|
||||
soap.SoapProtocol(
|
||||
tns='http://example.com/demo',
|
||||
typenamespace='http://example.com/demo/types',
|
||||
baseURL='http://127.0.0.1:8989/',
|
||||
)]
|
||||
return DemoRoot(protocols)
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
@ -38,6 +38,8 @@ def scan_api(controller, path=[]):
|
||||
if hasattr(a, '_wsme_definition'):
|
||||
a._wsme_definition.path = path
|
||||
yield a._wsme_definition
|
||||
elif inspect.isclass(a):
|
||||
continue
|
||||
else:
|
||||
if len(path) > 10:
|
||||
raise ValueError(str(path))
|
||||
|
@ -10,7 +10,7 @@ from webob.dec import wsgify
|
||||
from webtest import TestApp
|
||||
|
||||
from wsme import *
|
||||
from wsme.controller import WSRoot
|
||||
from wsme.wsgi import WSRoot
|
||||
import wsme.types
|
||||
|
||||
warnings.filterwarnings('ignore', module='webob.dec')
|
||||
@ -221,7 +221,7 @@ class ProtocolTestCase(unittest.TestCase):
|
||||
if self.__class__.__name__ != 'ProtocolTestCase':
|
||||
self.root = WSTestRoot([self.protocol])
|
||||
|
||||
self.app = TestApp(wsgify(self.root._handle_request))
|
||||
self.app = TestApp(self.root)
|
||||
|
||||
def test_invalid_path(self):
|
||||
try:
|
||||
|
@ -4,7 +4,8 @@ from webob.dec import wsgify
|
||||
import webtest
|
||||
|
||||
from wsme import *
|
||||
from wsme.controller import scan_api, WSRoot
|
||||
from wsme.controller import scan_api
|
||||
from wsme.wsgi import WSRoot
|
||||
|
||||
|
||||
class DummyProtocol(object):
|
||||
@ -32,10 +33,6 @@ class DummyProtocol(object):
|
||||
return str(infos)
|
||||
|
||||
|
||||
def serve_ws(req, root):
|
||||
return root._handle_request(req)
|
||||
|
||||
|
||||
class TestController(unittest.TestCase):
|
||||
def test_expose(self):
|
||||
class MyWS(WSRoot):
|
||||
@ -110,8 +107,7 @@ class TestController(unittest.TestCase):
|
||||
p = DummyProtocol()
|
||||
r = MyRoot(protocols=[p])
|
||||
|
||||
app = webtest.TestApp(
|
||||
wsgify(r._handle_request))
|
||||
app = webtest.TestApp(r)
|
||||
|
||||
res = app.get('/')
|
||||
|
||||
|
11
wsme/wsgi.py
Normal file
11
wsme/wsgi.py
Normal file
@ -0,0 +1,11 @@
|
||||
from webob.dec import wsgify
|
||||
from wsme import controller
|
||||
|
||||
|
||||
class WSRoot(controller.WSRoot, wsgify):
|
||||
"""
|
||||
A WSRoot that is usable as a wsgi application.
|
||||
"""
|
||||
def __init__(self, *args, **kw):
|
||||
super(WSRoot, self).__init__(*args, **kw)
|
||||
wsgify.__init__(self, self._handle_request)
|
Loading…
x
Reference in New Issue
Block a user