Added an adapter for TG1
This commit is contained in:
@@ -26,6 +26,7 @@ Contents
|
|||||||
|
|
||||||
gettingstarted
|
gettingstarted
|
||||||
api
|
api
|
||||||
|
integrate
|
||||||
|
|
||||||
changes
|
changes
|
||||||
|
|
||||||
|
|||||||
42
doc/integrate.rst
Normal file
42
doc/integrate.rst
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
Integrating with a Framework
|
||||||
|
============================
|
||||||
|
|
||||||
|
Turbogears 1.x
|
||||||
|
--------------
|
||||||
|
|
||||||
|
.. module:: wsme.tg1
|
||||||
|
|
||||||
|
wsme.tg1 provides a WSRoot controller that can be part of your
|
||||||
|
controller tree.
|
||||||
|
|
||||||
|
In a freshly quickstarted tg1 application (let's say, wsmedemo),
|
||||||
|
the prefered way is the following :
|
||||||
|
|
||||||
|
Create a new file, "wsmedemo/ws.py" :
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
from wsme.tg1 import WSRoot
|
||||||
|
from wsme import expose, validate
|
||||||
|
|
||||||
|
class WSController(WSRoot):
|
||||||
|
@expose(int)
|
||||||
|
@validate(int, int)
|
||||||
|
def multiply(self, a, b):
|
||||||
|
return a * b
|
||||||
|
|
||||||
|
Insert the ws controller in the controller tree, (file controllers.py):
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
# ...
|
||||||
|
|
||||||
|
from wsmedemo.ws import WSController
|
||||||
|
|
||||||
|
# make sure the wanted protocols are known
|
||||||
|
import wsme.protocols.restjson
|
||||||
|
|
||||||
|
class Root(controllers.RootController):
|
||||||
|
ws = WSController(webpath='ws', protocols=['REST+Json'])
|
||||||
|
|
||||||
|
# ...
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
from controller import expose, validate, WSRoot
|
from controller import expose, validate
|
||||||
from types import wsattr, wsproperty
|
from types import wsattr, wsproperty
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import sys
|
|||||||
from wsme import exc
|
from wsme import exc
|
||||||
from wsme.types import register_type
|
from wsme.types import register_type
|
||||||
|
|
||||||
__all__ = ['expose', 'validate', 'WSRoot']
|
__all__ = ['expose', 'validate']
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -128,10 +128,9 @@ class validate(object):
|
|||||||
|
|
||||||
|
|
||||||
class WSRoot(object):
|
class WSRoot(object):
|
||||||
def __init__(self, protocols=[]):
|
def __init__(self, protocols=[], webpath=''):
|
||||||
self._debug = True
|
self._debug = True
|
||||||
if protocols is None:
|
self._webpath = webpath
|
||||||
protocols = registered_protocols.keys()
|
|
||||||
self.protocols = {}
|
self.protocols = {}
|
||||||
for protocol in protocols:
|
for protocol in protocols:
|
||||||
self.addprotocol(protocol)
|
self.addprotocol(protocol)
|
||||||
|
|||||||
@@ -52,7 +52,10 @@ class RestProtocol(object):
|
|||||||
return kw
|
return kw
|
||||||
|
|
||||||
def extract_path(self, request):
|
def extract_path(self, request):
|
||||||
path = request.path.strip('/').split('/')
|
path = request.path
|
||||||
|
assert path.startswith(self.root._webpath)
|
||||||
|
path = path[len(self.root._webpath):]
|
||||||
|
path = path.strip('/').split('/')
|
||||||
|
|
||||||
if path[-1].endswith('.' + self.dataformat):
|
if path[-1].endswith('.' + self.dataformat):
|
||||||
path[-1] = path[-1][:-len(self.dataformat) - 1]
|
path[-1] = path[-1][:-len(self.dataformat) - 1]
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from webob.dec import wsgify
|
|||||||
from webtest import TestApp
|
from webtest import TestApp
|
||||||
|
|
||||||
from wsme import *
|
from wsme import *
|
||||||
|
from wsme.controller import WSRoot
|
||||||
import wsme.types
|
import wsme.types
|
||||||
|
|
||||||
warnings.filterwarnings('ignore', module='webob.dec')
|
warnings.filterwarnings('ignore', module='webob.dec')
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from webob.dec import wsgify
|
|||||||
import webtest
|
import webtest
|
||||||
|
|
||||||
from wsme import *
|
from wsme import *
|
||||||
from wsme.controller import scan_api
|
from wsme.controller import scan_api, WSRoot
|
||||||
|
|
||||||
|
|
||||||
class DummyProtocol(object):
|
class DummyProtocol(object):
|
||||||
|
|||||||
13
wsme/tg1.py
Normal file
13
wsme/tg1.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import wsme
|
||||||
|
import cherrypy
|
||||||
|
import webob
|
||||||
|
from turbogears import expose
|
||||||
|
|
||||||
|
class WSRoot(wsme.WSRoot):
|
||||||
|
@expose()
|
||||||
|
def default(self, *args, **kw):
|
||||||
|
req = webob.Request(cherrypy.request.wsgi_environ)
|
||||||
|
res = self._handle_request(req)
|
||||||
|
cherrypy.response.header_list = res.headerlist
|
||||||
|
cherrypy.status = res.status
|
||||||
|
return res.body
|
||||||
Reference in New Issue
Block a user