Moved non-core features to the wsmeext namespace package

--HG--
rename : wsme/cornice.py => wsmeext/cornice.py
rename : wsme/pecan.py => wsmeext/pecan.py
rename : wsme/sphinxext.py => wsmeext/sphinxext.py
rename : wsme/tg1.py => wsmeext/tg1.py
rename : wsme/tg11.py => wsmeext/tg11.py
rename : wsme/tg15.py => wsmeext/tg15.py
This commit is contained in:
Christophe de Vienne 2013-01-17 13:15:25 +01:00
parent bd184770a3
commit 8736089dc9
15 changed files with 59 additions and 53 deletions

View File

@ -39,6 +39,10 @@ packages =
wsme wsme
wsme.rest wsme.rest
wsme.tests wsme.tests
wsmeext
namespace_packages =
wsmeext
extra_files = extra_files =
setup.py setup.py

View File

@ -1,7 +1,7 @@
from pecan import expose from pecan import expose
from webob.exc import status_map from webob.exc import status_map
from .ws import AuthorsController from .ws import AuthorsController
from wsme.pecan import wsexpose from wsmeext.pecan import wsexpose
class RootController(object): class RootController(object):

View File

@ -4,7 +4,7 @@ from pecan.rest import RestController
from wsme.types import Base, text, wsattr from wsme.types import Base, text, wsattr
import wsme import wsme
import wsme.pecan import wsmeext.pecan
class Author(Base): class Author(Base):
@ -21,7 +21,7 @@ class Book(Base):
class BooksController(RestController): class BooksController(RestController):
@wsme.pecan.wsexpose(Book, int, int) @wsmeext.pecan.wsexpose(Book, int, int)
def get(self, author_id, id): def get(self, author_id, id):
print repr(author_id), repr(id) print repr(author_id), repr(id)
book = Book( book = Book(
@ -30,7 +30,7 @@ class BooksController(RestController):
author=Author(lastname=u"Proudhon")) author=Author(lastname=u"Proudhon"))
return book return book
@wsme.pecan.wsexpose(Book, int, int, body=Book) @wsmeext.pecan.wsexpose(Book, int, int, body=Book)
def put(self, author_id, id, book=None): def put(self, author_id, id, book=None):
print author_id, id print author_id, id
print book print book
@ -47,7 +47,7 @@ class AuthorsController(RestController):
books = BooksController() books = BooksController()
@wsme.pecan.wsexpose([Author], [unicode], [Criterion]) @wsmeext.pecan.wsexpose([Author], [unicode], [Criterion])
def get_all(self, q=None, r=None): def get_all(self, q=None, r=None):
if q: if q:
return [ return [
@ -63,7 +63,7 @@ class AuthorsController(RestController):
Author(id=1, firstname=u'FirstName') Author(id=1, firstname=u'FirstName')
] ]
@wsme.pecan.wsexpose(Author, int) @wsmeext.pecan.wsexpose(Author, int)
def get(self, id): def get(self, id):
if id == 999: if id == 999:
raise wsme.exc.ClientSideError('Wrong ID') raise wsme.exc.ClientSideError('Wrong ID')

View File

@ -25,7 +25,7 @@ sys.path.insert(0, os.path.abspath('..'))
# Add any Sphinx extension module names here, as strings. They can be extensions # Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'wsme.sphinxext'] extensions = ['sphinx.ext.autodoc', 'wsmeext.sphinxext']
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates'] templates_path = ['_templates']
@ -40,7 +40,7 @@ source_suffix = '.rst'
master_doc = 'index' master_doc = 'index'
# General information about the project. # General information about the project.
project = u'wsme.sphinxext Test' project = u'wsmeext.sphinxext Test'
copyright = u'2011, Christophe de Vienne' copyright = u'2011, Christophe de Vienne'
# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for

View File

@ -3,7 +3,7 @@ import sphinx
import os.path import os.path
import wsme.types import wsme.types
from wsme import sphinxext from wsmeext import sphinxext
docpath = os.path.join( docpath = os.path.join(
os.path.dirname(__file__), os.path.dirname(__file__),

View File

@ -1,7 +1,7 @@
import wsme.tg11 import wsmeext.tg11
from wsme import WSRoot from wsme import WSRoot
from wsme.tg11 import wsexpose, wsvalidate from wsmeext.tg11 import wsexpose, wsvalidate
import wsme.tg1 import wsmeext.tg1
from turbogears.controllers import RootController from turbogears.controllers import RootController
@ -25,7 +25,7 @@ class Subcontroller(object):
class Root(RootController): class Root(RootController):
class UselessSubClass: class UselessSubClass:
# This class is here only to make sure wsme.tg1.scan_api # This class is here only to make sure wsmeext.tg1.scan_api
# does its job properly # does its job properly
pass pass
@ -36,7 +36,7 @@ class Root(RootController):
typenamespace=test_soap.typenamespace, typenamespace=test_soap.typenamespace,
baseURL='/ws/' baseURL='/ws/'
) )
ws = wsme.tg11.adapt(ws) ws = wsmeext.tg11.adapt(ws)
@wsexpose(int) @wsexpose(int)
@wsvalidate(int, int) @wsvalidate(int, int)
@ -61,7 +61,7 @@ class TestController(unittest.TestCase):
def tearDown(self): def tearDown(self):
# implementation copied from turbogears.testutil.stop_server. # implementation copied from turbogears.testutil.stop_server.
# The only change is that cherrypy.root is set to None # The only change is that cherrypy.root is set to None
# AFTER stopTurbogears has been called so that wsme.tg11 # AFTER stopTurbogears has been called so that wsmeext.tg11
# can correctly uninstall its filter. # can correctly uninstall its filter.
if config.get("cp_started"): if config.get("cp_started"):
cherrypy.server.stop() cherrypy.server.stop()
@ -133,7 +133,7 @@ class TestController(unittest.TestCase):
root = MyRoot() root = MyRoot()
api = list(wsme.tg1._scan_api(root)) api = list(wsmeext.tg1._scan_api(root))
print(api) print(api)
self.assertEquals(len(api), 0) self.assertEquals(len(api), 0)
@ -152,14 +152,14 @@ class TestController(unittest.TestCase):
c.sub = subc() c.sub = subc()
c = subc c = subc
root = ARoot() root = ARoot()
self.assertRaises(ValueError, list, wsme.tg1._scan_api(root)) self.assertRaises(ValueError, list, wsmeext.tg1._scan_api(root))
def test_templates_content_type(self): def test_templates_content_type(self):
self.assertEquals( self.assertEquals(
"application/json", "application/json",
wsme.tg1.AutoJSONTemplate().get_content_type('dummy') wsmeext.tg1.AutoJSONTemplate().get_content_type('dummy')
) )
self.assertEquals( self.assertEquals(
"text/xml", "text/xml",
wsme.tg1.AutoXMLTemplate().get_content_type('dummy') wsmeext.tg1.AutoXMLTemplate().get_content_type('dummy')
) )

View File

@ -1,4 +1,4 @@
import wsme.tg15 import wsmeext.tg15
from wsme import WSRoot from wsme import WSRoot
from turbogears.controllers import RootController from turbogears.controllers import RootController
@ -9,14 +9,14 @@ import simplejson
class Subcontroller(object): class Subcontroller(object):
@wsme.tg15.wsexpose(int, int, int) @wsmeext.tg15.wsexpose(int, int, int)
def add(self, a, b): def add(self, a, b):
return a + b return a + b
class Root(RootController): class Root(RootController):
class UselessSubClass: class UselessSubClass:
# This class is here only to make sure wsme.tg1.scan_api # This class is here only to make sure wsmeext.tg1.scan_api
# does its job properly # does its job properly
pass pass
@ -28,10 +28,10 @@ class Root(RootController):
typenamespace=test_soap.typenamespace, typenamespace=test_soap.typenamespace,
baseURL='/ws/' baseURL='/ws/'
) )
ws = wsme.tg15.adapt(ws) ws = wsmeext.tg15.adapt(ws)
@wsme.tg15.wsexpose(int) @wsmeext.tg15.wsexpose(int)
@wsme.tg15.wsvalidate(int, int) @wsmeext.tg15.wsvalidate(int, int)
def multiply(self, a, b): def multiply(self, a, b):
return a * b return a * b
@ -51,7 +51,7 @@ class TestController(testutil.TGTest):
# def tearDown(self): # def tearDown(self):
# # implementation copied from turbogears.testutil.stop_server. # # implementation copied from turbogears.testutil.stop_server.
# # The only change is that cherrypy.root is set to None # # The only change is that cherrypy.root is set to None
# # AFTER stopTurbogears has been called so that wsme.tg15 # # AFTER stopTurbogears has been called so that wsmeext.tg15
# # can correctly uninstall its filter. # # can correctly uninstall its filter.
# if config.get("cp_started"): # if config.get("cp_started"):
# cherrypy.server.stop() # cherrypy.server.stop()
@ -112,7 +112,7 @@ class TestController(testutil.TGTest):
root = MyRoot() root = MyRoot()
api = list(wsme.tg1._scan_api(root)) api = list(wsmeext.tg1._scan_api(root))
print(api) print(api)
self.assertEquals(len(api), 0) self.assertEquals(len(api), 0)
@ -131,14 +131,14 @@ class TestController(testutil.TGTest):
c.sub = subc() c.sub = subc()
c = subc c = subc
root = ARoot() root = ARoot()
self.assertRaises(ValueError, list, wsme.tg1._scan_api(root)) self.assertRaises(ValueError, list, wsmeext.tg1._scan_api(root))
def test_templates_content_type(self): def test_templates_content_type(self):
self.assertEquals( self.assertEquals(
"application/json", "application/json",
wsme.tg1.AutoJSONTemplate().get_content_type('dummy') wsmeext.tg1.AutoJSONTemplate().get_content_type('dummy')
) )
self.assertEquals( self.assertEquals(
"text/xml", "text/xml",
wsme.tg1.AutoXMLTemplate().get_content_type('dummy') wsmeext.tg1.AutoXMLTemplate().get_content_type('dummy')
) )

30
tox.ini
View File

@ -26,8 +26,8 @@ setenv=
#commands=nosetests --verbose [] #commands=nosetests --verbose []
commands= commands=
{envbindir}/coverage run {envbindir}/nosetests --with-xunit --xunit-file nosetests-{envname}.xml -w ./wsme/tests --verbose {posargs} {envbindir}/coverage run {envbindir}/nosetests --with-xunit --xunit-file nosetests-{envname}.xml -w ./wsme/tests --verbose {posargs}
{envbindir}/coverage xml -o coverage-{envname}.xml wsme/*.py wsme/rest/*.py {envbindir}/coverage xml -o coverage-{envname}.xml wsme/*.py wsme/rest/*.py wsmeext/*.py
{envbindir}/coverage report --show-missing wsme/*.py wsme/rest/*.py {envbindir}/coverage report --show-missing wsme/*.py wsme/rest/*.py wsmeext/*.py
downloadcache=.tox/cache downloadcache=.tox/cache
@ -45,8 +45,8 @@ deps=
[testenv:py32] [testenv:py32]
commands= commands=
{envbindir}/coverage run {envbindir}/nosetests --with-xunit --xunit-file nosetests-{envname}.xml -w ./wsme/tests --verbose {posargs} {envbindir}/coverage run {envbindir}/nosetests --with-xunit --xunit-file nosetests-{envname}.xml -w ./wsme/tests --verbose {posargs}
{envbindir}/coverage xml -o coverage-{envname}.xml --omit wsme/sphinxext.py wsme/*.py wsme/rest/*.py {envbindir}/coverage xml -o coverage-{envname}.xml --omit wsmeext/sphinxext.py wsme/*.py wsme/rest/*.py wsmeext/*.py
{envbindir}/coverage report --show-missing --omit wsme/sphinxext.py wsme/*.py wsme/rest/*.py {envbindir}/coverage report --show-missing --omit wsmeext/sphinxext.py wsme/*.py wsme/rest/*.py wsmeext/*.py
[testenv:sphinxext] [testenv:sphinxext]
basepython=python2.5 basepython=python2.5
@ -58,8 +58,8 @@ deps=
Sphinx Sphinx
commands= commands=
{envbindir}/coverage run {envbindir}/nosetests --with-xunit --xunit-file nosetests-{envname}.xml tests/test_sphinxext.py --verbose {posargs} {envbindir}/coverage run {envbindir}/nosetests --with-xunit --xunit-file nosetests-{envname}.xml tests/test_sphinxext.py --verbose {posargs}
{envbindir}/coverage xml -o coverage-{envname}.xml wsme/*.py wsme/rest/*.py {envbindir}/coverage xml -o coverage-{envname}.xml wsme/*.py wsme/rest/*.py wsmeext/*.py
{envbindir}/coverage report --show-missing wsme/*.py wsme/rest/*.py {envbindir}/coverage report --show-missing wsme/*.py wsme/rest/*.py wsmeext/*.py
[testenv:tg11] [testenv:tg11]
basepython=python2.5 basepython=python2.5
@ -75,8 +75,8 @@ commands=
{envbindir}/easy_install https://bitbucket.org/cdevienne/wsme-soap/get/tip.zip {envbindir}/easy_install https://bitbucket.org/cdevienne/wsme-soap/get/tip.zip
{envbindir}/easy_install -i http://www.turbogears.org/1.1/downloads/current/index/ 'TurboGears<1.1.99' {envbindir}/easy_install -i http://www.turbogears.org/1.1/downloads/current/index/ 'TurboGears<1.1.99'
{envbindir}/coverage run {envbindir}/nosetests --with-xunit --xunit-file nosetests-{envname}.xml tests/test_tg1.py --verbose {posargs} {envbindir}/coverage run {envbindir}/nosetests --with-xunit --xunit-file nosetests-{envname}.xml tests/test_tg1.py --verbose {posargs}
{envbindir}/coverage xml -o coverage-{envname}.xml wsme/*.py wsme/rest/*.py {envbindir}/coverage xml -o coverage-{envname}.xml wsme/*.py wsme/rest/*.py wsmeext/*.py
{envbindir}/coverage report --show-missing wsme/*.py wsme/rest/*.py {envbindir}/coverage report --show-missing wsme/*.py wsme/rest/*.py wsmeext/*.py
[testenv:tg15] [testenv:tg15]
basepython=python2.5 basepython=python2.5
@ -92,8 +92,8 @@ commands=
{envbindir}/easy_install https://bitbucket.org/cdevienne/wsme-soap/get/tip.zip {envbindir}/easy_install https://bitbucket.org/cdevienne/wsme-soap/get/tip.zip
{envbindir}/easy_install -i http://www.turbogears.org/1.5/downloads/current/index/ 'TurboGears<1.5.99' {envbindir}/easy_install -i http://www.turbogears.org/1.5/downloads/current/index/ 'TurboGears<1.5.99'
{envbindir}/coverage run {envbindir}/nosetests --with-xunit --xunit-file nosetests-{envname}.xml tests/test_tg15.py --verbose {posargs} {envbindir}/coverage run {envbindir}/nosetests --with-xunit --xunit-file nosetests-{envname}.xml tests/test_tg15.py --verbose {posargs}
{envbindir}/coverage xml -o coverage-{envname}.xml wsme/*.py wsme/rest/*.py {envbindir}/coverage xml -o coverage-{envname}.xml wsme/*.py wsme/rest/*.py wsmeext/*.py
{envbindir}/coverage report --show-missing wsme/*.py wsme/rest/*.py {envbindir}/coverage report --show-missing wsme/*.py wsme/rest/*.py wsmeext/*.py
[testenv:tg21] [testenv:tg21]
basepython=python2.5 basepython=python2.5
@ -106,8 +106,8 @@ commands=
{envbindir}/easy_install https://bitbucket.org/cdevienne/wsme-soap/get/tip.zip {envbindir}/easy_install https://bitbucket.org/cdevienne/wsme-soap/get/tip.zip
{envbindir}/easy_install -i http://www.turbogears.org/2.1/downloads/current/index/ 'TurboGears2<2.1.99' webtest {envbindir}/easy_install -i http://www.turbogears.org/2.1/downloads/current/index/ 'TurboGears2<2.1.99' webtest
{envbindir}/coverage run {envbindir}/nosetests --with-xunit --xunit-file nosetests-{envname}.xml tests/test_tg20.py --verbose {posargs} {envbindir}/coverage run {envbindir}/nosetests --with-xunit --xunit-file nosetests-{envname}.xml tests/test_tg20.py --verbose {posargs}
{envbindir}/coverage xml -o coverage-{envname}.xml wsme/*.py wsme/rest/*.py {envbindir}/coverage xml -o coverage-{envname}.xml wsme/*.py wsme/rest/*.py wsmeext/*.py
{envbindir}/coverage report --show-missing wsme/*.py wsme/rest/*.py {envbindir}/coverage report --show-missing wsme/*.py wsme/rest/*.py wsmeext/*.py
[testenv:pecan] [testenv:pecan]
basepython=python2.7 basepython=python2.7
@ -125,7 +125,7 @@ setenv=
commands= commands=
{envbindir}/coverage run --source wsme {envbindir}/nosetests -w tests/pecantest test/tests/test_ws.py --with-xunit --xunit-file nosetests-{envname}.xml --verbose {posargs} {envbindir}/coverage run --source wsme {envbindir}/nosetests -w tests/pecantest test/tests/test_ws.py --with-xunit --xunit-file nosetests-{envname}.xml --verbose {posargs}
{envbindir}/coverage xml -o coverage-{envname}.xml {envbindir}/coverage xml -o coverage-{envname}.xml
{envbindir}/coverage report --show-missing wsme/*.py wsme/rest/*.py {envbindir}/coverage report --show-missing wsme/*.py wsme/rest/*.py wsmeext/*.py
[testenv:coverage] [testenv:coverage]
basepython=python basepython=python
@ -136,5 +136,5 @@ setenv=
commands= commands=
{envbindir}/coverage erase {envbindir}/coverage erase
{envbindir}/coverage combine {envbindir}/coverage combine
{envbindir}/coverage xml wsme/*.py wsme/rest/*.py {envbindir}/coverage xml wsme/*.py wsme/rest/*.py wsmeext/*.py
{envbindir}/coverage report --show-missing wsme/*.py wsme/protocols/*.py {envbindir}/coverage report --show-missing wsme/*.py wsme/protocols/*.py wsmeext/*.py

2
wsmeext/__init__.py Normal file
View File

@ -0,0 +1,2 @@
import pkg_resources
pkg_resources.declare_namespace(__name__)

View File

@ -2,8 +2,8 @@ from turbogears import config
import cherrypy import cherrypy
from cherrypy.filters.basefilter import BaseFilter from cherrypy.filters.basefilter import BaseFilter
from turbogears.startup import call_on_startup, call_on_shutdown from turbogears.startup import call_on_startup, call_on_shutdown
from wsme.tg1 import wsexpose, wsvalidate from wsmeext.tg1 import wsexpose, wsvalidate
import wsme.tg1 import wsmeext.tg1
__all__ = ['adapt', 'wsexpose', 'wsvalidate'] __all__ = ['adapt', 'wsexpose', 'wsvalidate']
@ -20,8 +20,8 @@ class WSMECherrypyFilter(BaseFilter):
def adapt(wsroot): def adapt(wsroot):
wsroot._scan_api = wsme.tg1.scan_api wsroot._scan_api = wsmeext.tg1.scan_api
controller = wsme.tg1.Controller(wsroot) controller = wsmeext.tg1.Controller(wsroot)
filter_ = WSMECherrypyFilter(controller) filter_ = WSMECherrypyFilter(controller)
def install_filter(): def install_filter():

View File

@ -1,7 +1,7 @@
import cherrypy import cherrypy
from wsme.tg1 import wsexpose, wsvalidate from wsmeext.tg1 import wsexpose, wsvalidate
import wsme.tg1 import wsmeext.tg1
__all__ = ['adapt', 'wsexpose', 'wsvalidate'] __all__ = ['adapt', 'wsexpose', 'wsvalidate']
@ -10,11 +10,11 @@ __all__ = ['adapt', 'wsexpose', 'wsvalidate']
def scan_api(root=None): def scan_api(root=None):
for baseurl, instance in cherrypy.tree.apps.items(): for baseurl, instance in cherrypy.tree.apps.items():
path = [token for token in baseurl.split('/') if token] path = [token for token in baseurl.split('/') if token]
for i in wsme.tg1._scan_api(instance.root, path): for i in wsmeext.tg1._scan_api(instance.root, path):
yield i yield i
def adapt(wsroot): def adapt(wsroot):
wsroot._scan_api = scan_api wsroot._scan_api = scan_api
controller = wsme.tg1.Controller(wsroot) controller = wsmeext.tg1.Controller(wsroot)
return controller return controller