diff --git a/setup.cfg b/setup.cfg index ed559e2..93e1a3e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,13 +30,12 @@ classifier = [entry_points] wsme.protocols = - restjson = wsme.protocols.restjson:RestJsonProtocol - restxml = wsme.protocols.restxml:RestXmlProtocol + restjson = wsme.rest.json:RestJsonProtocol + restxml = wsme.rest.xml:RestXmlProtocol [files] packages = wsme - wsme.protocols wsme.rest wsme.tests diff --git a/wsme/pecan.py b/wsme/pecan.py index a9d9766..41eb501 100644 --- a/wsme/pecan.py +++ b/wsme/pecan.py @@ -6,9 +6,9 @@ import json import xml.etree.ElementTree as et import wsme -import wsme.protocols.commons -import wsme.protocols.restjson -import wsme.protocols.restxml +import wsme.rest.args +import wsme.rest.json +import wsme.rest.xml pecan = sys.modules['pecan'] @@ -18,7 +18,7 @@ class JSonRenderer(object): pass def render(self, template_path, namespace): - data = wsme.protocols.restjson.tojson( + data = wsme.rest.json.tojson( namespace['datatype'], namespace['result'] ) @@ -30,7 +30,7 @@ class XMLRenderer(object): pass def render(self, template_path, namespace): - data = wsme.protocols.restxml.toxml( + data = wsme.rest.xml.toxml( namespace['datatype'], 'result', namespace['result'] @@ -58,7 +58,7 @@ def wsexpose(*args, **kwargs): funcdef = wsme.api.FunctionDefinition.get(f) def callfunction(self, *args, **kwargs): - args, kwargs = wsme.protocols.commons.get_args( + args, kwargs = wsme.rest.args.get_args( funcdef, args, kwargs, pecan.request.body, pecan.request.content_type ) diff --git a/wsme/protocols/__init__.py b/wsme/protocol.py similarity index 100% rename from wsme/protocols/__init__.py rename to wsme/protocol.py diff --git a/wsme/protocols/commons.py b/wsme/rest/args.py similarity index 98% rename from wsme/protocols/commons.py rename to wsme/rest/args.py index 8f7e68c..c7ac592 100644 --- a/wsme/protocols/commons.py +++ b/wsme/rest/args.py @@ -141,8 +141,8 @@ def args_from_params(funcdef, params): def args_from_body(funcdef, body, mimetype): - from wsme.protocols import restjson - from wsme.protocols import restxml + from wsme.rest import json as restjson + from wsme.rest import xml as restxml kw = {} diff --git a/wsme/protocols/restjson.py b/wsme/rest/json.py similarity index 98% rename from wsme/protocols/restjson.py rename to wsme/rest/json.py index 52938ce..7fa0654 100644 --- a/wsme/protocols/restjson.py +++ b/wsme/rest/json.py @@ -1,6 +1,7 @@ """ REST+Json protocol implementation. """ +from __future__ import absolute_import import datetime import decimal @@ -8,14 +9,14 @@ import six from simplegeneric import generic -from wsme.protocols.rest import RestProtocol +from wsme.rest.protocol import RestProtocol from wsme.types import Unset import wsme.types try: import simplejson as json except ImportError: - import json + import json # noqa @generic diff --git a/wsme/protocols/rest.py b/wsme/rest/protocol.py similarity index 97% rename from wsme/protocols/rest.py rename to wsme/rest/protocol.py index 3fcd933..bdcd025 100644 --- a/wsme/protocols/rest.py +++ b/wsme/rest/protocol.py @@ -4,8 +4,8 @@ import six from six import u from wsme.exc import ClientSideError, UnknownArgument -from wsme.protocols import CallContext, Protocol -from wsme.protocols.commons import from_params +from wsme.protocol import CallContext, Protocol +from wsme.rest.args import from_params from wsme.types import Unset log = logging.getLogger(__name__) diff --git a/wsme/protocols/restxml.py b/wsme/rest/xml.py similarity index 98% rename from wsme/protocols/restxml.py rename to wsme/rest/xml.py index 08614a0..c78eedf 100644 --- a/wsme/protocols/restxml.py +++ b/wsme/rest/xml.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import + import datetime from six import u @@ -7,7 +9,7 @@ import xml.etree.ElementTree as et from simplegeneric import generic -from wsme.protocols.rest import RestProtocol +from wsme.rest.protocol import RestProtocol import wsme.types import re diff --git a/wsme/root.py b/wsme/root.py index fb8258d..e6b4e96 100644 --- a/wsme/root.py +++ b/wsme/root.py @@ -9,7 +9,7 @@ import six import webob 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 import spore import wsme.types diff --git a/wsme/sphinxext.py b/wsme/sphinxext.py index 3b993e6..a38f5c5 100644 --- a/wsme/sphinxext.py +++ b/wsme/sphinxext.py @@ -173,7 +173,7 @@ class TypeDocumenter(autodoc.ClassDocumenter): def add_content(self, more_content, no_docstring=False): 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 = [] if protocols: sample_obj = make_sample_object(self.object) @@ -336,7 +336,7 @@ class FunctionDocumenter(autodoc.MethodDocumenter): found_params = set() 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 i, line in enumerate(docstring): diff --git a/wsme/tests/test_protocols.py b/wsme/tests/test_protocols.py index e4d9e0b..557401e 100644 --- a/wsme/tests/test_protocols.py +++ b/wsme/tests/test_protocols.py @@ -3,8 +3,8 @@ import unittest from wsme import WSRoot -from wsme.protocols import getprotocol, CallContext, Protocol -import wsme.protocols +from wsme.protocol import getprotocol, CallContext, Protocol +import wsme.protocol class DummyProtocol(Protocol): @@ -45,8 +45,8 @@ def test_getprotocol(): class TestProtocols(unittest.TestCase): def test_register_protocol(self): - wsme.protocols.register_protocol(DummyProtocol) - assert wsme.protocols.registered_protocols['dummy'] == DummyProtocol + wsme.protocol.register_protocol(DummyProtocol) + assert wsme.protocol.registered_protocols['dummy'] == DummyProtocol r = WSRoot() assert len(r.protocols) == 0 @@ -60,7 +60,7 @@ class TestProtocols(unittest.TestCase): assert r.protocols[0].__class__ == DummyProtocol def test_Protocol(self): - p = wsme.protocols.Protocol() + p = wsme.protocol.Protocol() assert p.iter_calls(None) is None assert p.extract_path(None) is None assert p.read_arguments(None) is None diff --git a/wsme/tests/test_protocols_commons.py b/wsme/tests/test_protocols_commons.py index 5c9319f..8ecfe14 100644 --- a/wsme/tests/test_protocols_commons.py +++ b/wsme/tests/test_protocols_commons.py @@ -3,7 +3,7 @@ import datetime 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 diff --git a/wsme/tests/test_restjson.py b/wsme/tests/test_restjson.py index dcaf373..b18bf41 100644 --- a/wsme/tests/test_restjson.py +++ b/wsme/tests/test_restjson.py @@ -9,8 +9,7 @@ try: except: import json # noqa -import wsme.protocols.restjson -from wsme.protocols.restjson import fromjson, tojson +from wsme.rest.json import fromjson, tojson from wsme.utils import parse_isodatetime, parse_isotime, parse_isodate from wsme.types import isusertype, register_type from wsme.rest import expose, validate diff --git a/wsme/tests/test_restxml.py b/wsme/tests/test_restxml.py index f51c257..8af8150 100644 --- a/wsme/tests/test_restxml.py +++ b/wsme/tests/test_restxml.py @@ -9,7 +9,7 @@ import wsme.tests.protocol from wsme.utils import parse_isodatetime, parse_isodate, parse_isotime from wsme.types import isusertype, register_type -from wsme.protocols.restxml import fromxml, toxml +from wsme.rest.xml import fromxml, toxml try: import xml.etree.ElementTree as et diff --git a/wsme/tests/test_root.py b/wsme/tests/test_root.py index da53780..d0a3485 100644 --- a/wsme/tests/test_root.py +++ b/wsme/tests/test_root.py @@ -24,9 +24,9 @@ class TestRoot(unittest.TestCase): default_prepare_response_body(None, [u('a'), u('b')]) == u('a\nb') 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): raise Exception('test')