Move around the REST implementation : wsme.protocols.commons -> wsme.rest.args, wsme.protocols.rest -> wsme.rest.protocol, wsme.protocols.restxml/json -> wsme.rest.xml/json, wsme.protocols.__init__ -> wsme.protocol.

--HG--
rename : wsme/protocols/__init__.py => wsme/protocol.py
rename : wsme/protocols/commons.py => wsme/rest/args.py
rename : wsme/protocols/restjson.py => wsme/rest/json.py
rename : wsme/protocols/rest.py => wsme/rest/protocol.py
rename : wsme/protocols/restxml.py => wsme/rest/xml.py
This commit is contained in:
Christophe de Vienne
2012-11-06 22:34:03 +01:00
parent 4826c8b7ed
commit ddd2ba251e
14 changed files with 31 additions and 30 deletions

View File

@@ -30,13 +30,12 @@ classifier =
[entry_points] [entry_points]
wsme.protocols = wsme.protocols =
restjson = wsme.protocols.restjson:RestJsonProtocol restjson = wsme.rest.json:RestJsonProtocol
restxml = wsme.protocols.restxml:RestXmlProtocol restxml = wsme.rest.xml:RestXmlProtocol
[files] [files]
packages = packages =
wsme wsme
wsme.protocols
wsme.rest wsme.rest
wsme.tests wsme.tests

View File

@@ -6,9 +6,9 @@ import json
import xml.etree.ElementTree as et import xml.etree.ElementTree as et
import wsme import wsme
import wsme.protocols.commons import wsme.rest.args
import wsme.protocols.restjson import wsme.rest.json
import wsme.protocols.restxml import wsme.rest.xml
pecan = sys.modules['pecan'] pecan = sys.modules['pecan']
@@ -18,7 +18,7 @@ class JSonRenderer(object):
pass pass
def render(self, template_path, namespace): def render(self, template_path, namespace):
data = wsme.protocols.restjson.tojson( data = wsme.rest.json.tojson(
namespace['datatype'], namespace['datatype'],
namespace['result'] namespace['result']
) )
@@ -30,7 +30,7 @@ class XMLRenderer(object):
pass pass
def render(self, template_path, namespace): def render(self, template_path, namespace):
data = wsme.protocols.restxml.toxml( data = wsme.rest.xml.toxml(
namespace['datatype'], namespace['datatype'],
'result', 'result',
namespace['result'] namespace['result']
@@ -58,7 +58,7 @@ def wsexpose(*args, **kwargs):
funcdef = wsme.api.FunctionDefinition.get(f) funcdef = wsme.api.FunctionDefinition.get(f)
def callfunction(self, *args, **kwargs): def callfunction(self, *args, **kwargs):
args, kwargs = wsme.protocols.commons.get_args( args, kwargs = wsme.rest.args.get_args(
funcdef, args, kwargs, funcdef, args, kwargs,
pecan.request.body, pecan.request.content_type pecan.request.body, pecan.request.content_type
) )

View File

@@ -141,8 +141,8 @@ def args_from_params(funcdef, params):
def args_from_body(funcdef, body, mimetype): def args_from_body(funcdef, body, mimetype):
from wsme.protocols import restjson from wsme.rest import json as restjson
from wsme.protocols import restxml from wsme.rest import xml as restxml
kw = {} kw = {}

View File

@@ -1,6 +1,7 @@
""" """
REST+Json protocol implementation. REST+Json protocol implementation.
""" """
from __future__ import absolute_import
import datetime import datetime
import decimal import decimal
@@ -8,14 +9,14 @@ import six
from simplegeneric import generic from simplegeneric import generic
from wsme.protocols.rest import RestProtocol from wsme.rest.protocol import RestProtocol
from wsme.types import Unset from wsme.types import Unset
import wsme.types import wsme.types
try: try:
import simplejson as json import simplejson as json
except ImportError: except ImportError:
import json import json # noqa
@generic @generic

View File

@@ -4,8 +4,8 @@ import six
from six import u from six import u
from wsme.exc import ClientSideError, UnknownArgument from wsme.exc import ClientSideError, UnknownArgument
from wsme.protocols import CallContext, Protocol from wsme.protocol import CallContext, Protocol
from wsme.protocols.commons import from_params from wsme.rest.args import from_params
from wsme.types import Unset from wsme.types import Unset
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View File

@@ -1,3 +1,5 @@
from __future__ import absolute_import
import datetime import datetime
from six import u from six import u
@@ -7,7 +9,7 @@ import xml.etree.ElementTree as et
from simplegeneric import generic from simplegeneric import generic
from wsme.protocols.rest import RestProtocol from wsme.rest.protocol import RestProtocol
import wsme.types import wsme.types
import re import re

View File

@@ -9,7 +9,7 @@ import six
import webob import webob
from wsme.exc import ClientSideError, MissingArgument, UnknownFunction from wsme.exc import ClientSideError, MissingArgument, UnknownFunction
from wsme.protocols import getprotocol from wsme.protocol import getprotocol
from wsme.rest import scan_api from wsme.rest import scan_api
from wsme import spore from wsme import spore
import wsme.types import wsme.types

View File

@@ -173,7 +173,7 @@ class TypeDocumenter(autodoc.ClassDocumenter):
def add_content(self, more_content, no_docstring=False): def add_content(self, more_content, no_docstring=False):
protocols = self.options.protocols or self.env.app.config.wsme_protocols protocols = self.options.protocols or self.env.app.config.wsme_protocols
protocols = [wsme.protocols.getprotocol(p) for p in protocols] protocols = [wsme.protocol.getprotocol(p) for p in protocols]
content = [] content = []
if protocols: if protocols:
sample_obj = make_sample_object(self.object) sample_obj = make_sample_object(self.object)
@@ -336,7 +336,7 @@ class FunctionDocumenter(autodoc.MethodDocumenter):
found_params = set() found_params = set()
protocols = self.options.protocols or self.env.app.config.wsme_protocols protocols = self.options.protocols or self.env.app.config.wsme_protocols
protocols = [wsme.protocols.getprotocol(p) for p in protocols] protocols = [wsme.protocol.getprotocol(p) for p in protocols]
for si, docstring in enumerate(docstrings): for si, docstring in enumerate(docstrings):
for i, line in enumerate(docstring): for i, line in enumerate(docstring):

View File

@@ -3,8 +3,8 @@
import unittest import unittest
from wsme import WSRoot from wsme import WSRoot
from wsme.protocols import getprotocol, CallContext, Protocol from wsme.protocol import getprotocol, CallContext, Protocol
import wsme.protocols import wsme.protocol
class DummyProtocol(Protocol): class DummyProtocol(Protocol):
@@ -45,8 +45,8 @@ def test_getprotocol():
class TestProtocols(unittest.TestCase): class TestProtocols(unittest.TestCase):
def test_register_protocol(self): def test_register_protocol(self):
wsme.protocols.register_protocol(DummyProtocol) wsme.protocol.register_protocol(DummyProtocol)
assert wsme.protocols.registered_protocols['dummy'] == DummyProtocol assert wsme.protocol.registered_protocols['dummy'] == DummyProtocol
r = WSRoot() r = WSRoot()
assert len(r.protocols) == 0 assert len(r.protocols) == 0
@@ -60,7 +60,7 @@ class TestProtocols(unittest.TestCase):
assert r.protocols[0].__class__ == DummyProtocol assert r.protocols[0].__class__ == DummyProtocol
def test_Protocol(self): def test_Protocol(self):
p = wsme.protocols.Protocol() p = wsme.protocol.Protocol()
assert p.iter_calls(None) is None assert p.iter_calls(None) is None
assert p.extract_path(None) is None assert p.extract_path(None) is None
assert p.read_arguments(None) is None assert p.read_arguments(None) is None

View File

@@ -3,7 +3,7 @@
import datetime import datetime
import unittest import unittest
from wsme.protocols.commons import from_param, from_params from wsme.rest.args import from_param, from_params
from wsme.types import UserType, Unset, ArrayType, DictType from wsme.types import UserType, Unset, ArrayType, DictType

View File

@@ -9,8 +9,7 @@ try:
except: except:
import json # noqa import json # noqa
import wsme.protocols.restjson from wsme.rest.json import fromjson, tojson
from wsme.protocols.restjson import fromjson, tojson
from wsme.utils import parse_isodatetime, parse_isotime, parse_isodate from wsme.utils import parse_isodatetime, parse_isotime, parse_isodate
from wsme.types import isusertype, register_type from wsme.types import isusertype, register_type
from wsme.rest import expose, validate from wsme.rest import expose, validate

View File

@@ -9,7 +9,7 @@ import wsme.tests.protocol
from wsme.utils import parse_isodatetime, parse_isodate, parse_isotime from wsme.utils import parse_isodatetime, parse_isodate, parse_isotime
from wsme.types import isusertype, register_type from wsme.types import isusertype, register_type
from wsme.protocols.restxml import fromxml, toxml from wsme.rest.xml import fromxml, toxml
try: try:
import xml.etree.ElementTree as et import xml.etree.ElementTree as et

View File

@@ -24,9 +24,9 @@ class TestRoot(unittest.TestCase):
default_prepare_response_body(None, [u('a'), u('b')]) == u('a\nb') default_prepare_response_body(None, [u('a'), u('b')]) == u('a\nb')
def test_protocol_selection_error(self): def test_protocol_selection_error(self):
import wsme.protocols import wsme.protocol
class P(wsme.protocols.Protocol): class P(wsme.protocol.Protocol):
def accept(self, r): def accept(self, r):
raise Exception('test') raise Exception('test')