[Python-modules-commits] [python-jsonrpc2] 02/03: Import python-jsonrpc2_0.4.1.orig.tar.gz

Takaki Taniguchi takaki at moszumanska.debian.org
Wed Nov 25 09:18:48 UTC 2015


This is an automated email from the git hooks/post-receive script.

takaki pushed a commit to branch master
in repository python-jsonrpc2.

commit 72e0d1abbab29b5aeb6dac1de62b93150d917f06
Author: TANIGUCHI Takaki <takaki at asis.media-as.org>
Date:   Wed Nov 25 18:16:30 2015 +0900

    Import python-jsonrpc2_0.4.1.orig.tar.gz
---
 ChangeLog                          |  18 +++++
 PKG-INFO                           | 138 ++++++++++++++++++++++++-------------
 README => README.rst               |  31 ++++++---
 jsonrpc2.egg-info/PKG-INFO         | 138 ++++++++++++++++++++++++-------------
 jsonrpc2.egg-info/SOURCES.txt      |   2 +-
 jsonrpc2.egg-info/entry_points.txt |   6 +-
 jsonrpc2.egg-info/requires.txt     |  12 ++--
 jsonrpc2/__init__.py               | 132 +++++++++++++++++++++--------------
 rpc_example.txt                    |   1 +
 setup.cfg                          |  11 ++-
 setup.py                           |  17 +++--
 11 files changed, 327 insertions(+), 179 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 13f4516..1c5af1b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,24 @@
 ChangeLog
 ===================================================
 
+0.4.1
+------------------------------
+
+- 0.4 is brown bag release.
+
+0.4
+-----------------------------------------------
+feature
+
+- added supporting py3
+- added registering application errors
+
+fixed bugs
+
+- Dont raise internal error for server exceptions `#13 <https://bitbucket.org/aodag/jsonrpc2/issue/13/dont-raise-internal-error-for-server>`_
+- incorrect Content-type `#15 https://bitbucket.org/aodag/jsonrpc2/issue/15/incorrect-content-type`_
+- internal logging configuration broken `#16 <https://bitbucket.org/aodag/jsonrpc2/issue/16/internal-logging-configuration-broken>`_
+
 0.3
 -----------------------------------------------
 
diff --git a/PKG-INFO b/PKG-INFO
index 34bb524..d1cb1f1 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
-Metadata-Version: 1.0
+Metadata-Version: 1.1
 Name: jsonrpc2
-Version: 0.3.2
+Version: 0.4.1
 Summary: WSGI Framework for JSON RPC 2.0
 Home-page: http://hg.aodag.jp/jsonrpc2/
 Author: Atsushi Odagiri
@@ -8,8 +8,12 @@ Author-email: aodagx at gmail.com
 License: MIT
 Description: .. -*- restructuredtext -*-
         
+        .. image:: https://drone.io/bitbucket.org/aodag/jsonrpc2/status.png
+           :target: https://drone.io/bitbucket.org/aodag/jsonrpc2/latest
+        
         jsonrpc2 is WSGI Framework for JSON RPC 2.0.
-        JSON RPC 2.0 Spec can be seen on http://groups.google.com/group/json-rpc/web/json-rpc-2-0
+        
+        JSON RPC 2.0 Spec can be seen on http://www.jsonrpc.org/specification .
         
         .. contents::
         
@@ -20,10 +24,6 @@ Description: .. -*- restructuredtext -*-
         
          $ pip install jsonrpc2
         
-        or install via easy_install::
-        
-         $ easy_install jsonrpc2
-        
         write your procedures in hello.py::
         
          def greeting(name):
@@ -54,7 +54,7 @@ Description: .. -*- restructuredtext -*-
         
         ::
         
-         >>> import simplejson as json
+         >>> import json
          >>> from jsonrpc2 import JsonRpcApplication
         
         sample procedure::
@@ -79,7 +79,7 @@ Description: .. -*- restructuredtext -*-
         got results::
         
          >>> res.json
-         {'jsonrpc': '2.0', 'id': 'greeting', 'result': 'Hello, world!'}
+         {u'jsonrpc': u'2.0', u'id': u'greeting', u'result': u'Hello, world!'}
         
         
         lazy loading::
@@ -88,7 +88,7 @@ Description: .. -*- restructuredtext -*-
          >>> call_values = {'jsonrpc':'2.0', 'method':'sample.add', 'id':'sample.add', 'params':[1, 2]}
          >>> res = testapp.post('/', params=json.dumps(call_values), content_type="application/json")
          >>> res.json
-         {'jsonrpc': '2.0', 'id': 'sample.add', 'result': 3}
+         {u'jsonrpc': u'2.0', u'id': u'sample.add', u'result': 3}
         
         
         extra vars
@@ -102,6 +102,21 @@ Description: .. -*- restructuredtext -*-
          >>> rpc({'jsonrpc': '2.0', 'method': 'add', 'id': 'rpc-1', 'params': {'a': 2}}, b=3)
          {'jsonrpc': '2.0', 'id': 'rpc-1', 'result': 5}
         
+        handle errors
+        =================
+        
+        ::
+        
+         >>> from jsonrpc2 import JsonRpc
+         >>> class MyException(Exception):
+         ...     pass
+         >>> def my_rpc():
+         ...     raise MyException()
+         >>> rpc = JsonRpc({'call': my_rpc}, {MyException: -32001})
+         >>> rpc({'jsonrpc': '2.0', 'method': 'call', 'id': 'rpc-1', 'params': []})
+         {'jsonrpc': '2.0', 'id': 'rpc-1', 'error': {'message': '', 'code': -32001, 'data': '[]'}}
+        
+        
         JSON-RPC2 Example
         =====================================================
         
@@ -147,6 +162,7 @@ Description: .. -*- restructuredtext -*-
          >>> rpc({"jsonrpc": "2.0", "method": "foobar"})
         
         Procedure Call of non-existent procedure::
+        
          >>> del rpc['foobar']
          >>> rpc({"jsonrpc": "2.0", "method": "foobar", "id": "1"})
          {'jsonrpc': '2.0', 'id': '1', 'error': {'message': 'Method Not Found', 'code': -32601}}
@@ -189,45 +205,63 @@ Description: .. -*- restructuredtext -*-
         
         
         
-        ChangeLog
-        ===================================================
-        
-        0.3
-        -----------------------------------------------
-        
-        - fix bugs
-        - Paste Scripte templates
-        - runjsonrpc2 command
-        
-        0.3.1
-        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-        
-        - fix bugs (content-type with charset)
-        
-        0.3.2
-        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-        - enable to pass the extra vars to procedures
-        
-        0.2
-        -----------------------------------------------
-        
-        - remove dependency to WebOb
-        - split procedure call class from web application class
-        
-        0.2.1
-        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-        
-        - lazy loading from method name.
-        
-        0.2.2
-        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-        
-        - add dict interface.
-        
-        0.2.3
-        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-        
-        - fix: read body with CONTENT_LENGTH.
+        ChangeLog
+        ===================================================
+        
+        0.4.1
+        ------------------------------
+        
+        - 0.4 is brown bag release.
+        
+        0.4
+        -----------------------------------------------
+        feature
+        
+        - added supporting py3
+        - added registering application errors
+        
+        fixed bugs
+        
+        - Dont raise internal error for server exceptions `#13 <https://bitbucket.org/aodag/jsonrpc2/issue/13/dont-raise-internal-error-for-server>`_
+        - incorrect Content-type `#15 https://bitbucket.org/aodag/jsonrpc2/issue/15/incorrect-content-type`_
+        - internal logging configuration broken `#16 <https://bitbucket.org/aodag/jsonrpc2/issue/16/internal-logging-configuration-broken>`_
+        
+        0.3
+        -----------------------------------------------
+        
+        - fix bugs
+        - Paste Scripte templates
+        - runjsonrpc2 command
+        
+        0.3.1
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+        
+        - fix bugs (content-type with charset)
+        
+        0.3.2
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+        - enable to pass the extra vars to procedures
+        
+        0.2
+        -----------------------------------------------
+        
+        - remove dependency to WebOb
+        - split procedure call class from web application class
+        
+        0.2.1
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+        
+        - lazy loading from method name.
+        
+        0.2.2
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+        
+        - add dict interface.
+        
+        0.2.3
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+        
+        - fix: read body with CONTENT_LENGTH.
         
 Keywords: wsgi request web http json rpc
 Platform: UNKNOWN
@@ -235,3 +269,9 @@ Classifier: Intended Audience :: Developers
 Classifier: License :: OSI Approved :: MIT License
 Classifier: Topic :: Internet :: WWW/HTTP :: WSGI
 Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.2
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
diff --git a/README b/README.rst
similarity index 69%
rename from README
rename to README.rst
index 3e2d23f..d4f0c19 100644
--- a/README
+++ b/README.rst
@@ -1,7 +1,11 @@
 .. -*- restructuredtext -*-
 
+.. image:: https://drone.io/bitbucket.org/aodag/jsonrpc2/status.png
+   :target: https://drone.io/bitbucket.org/aodag/jsonrpc2/latest
+
 jsonrpc2 is WSGI Framework for JSON RPC 2.0.
-JSON RPC 2.0 Spec can be seen on http://groups.google.com/group/json-rpc/web/json-rpc-2-0
+
+JSON RPC 2.0 Spec can be seen on http://www.jsonrpc.org/specification .
 
 .. contents::
 
@@ -12,10 +16,6 @@ install via pip::
 
  $ pip install jsonrpc2
 
-or install via easy_install::
-
- $ easy_install jsonrpc2
-
 write your procedures in hello.py::
 
  def greeting(name):
@@ -46,7 +46,7 @@ Internal
 
 ::
 
- >>> import simplejson as json
+ >>> import json
  >>> from jsonrpc2 import JsonRpcApplication
 
 sample procedure::
@@ -71,7 +71,7 @@ call procedure::
 got results::
 
  >>> res.json
- {'jsonrpc': '2.0', 'id': 'greeting', 'result': 'Hello, world!'}
+ {u'jsonrpc': u'2.0', u'id': u'greeting', u'result': u'Hello, world!'}
 
 
 lazy loading::
@@ -80,7 +80,7 @@ lazy loading::
  >>> call_values = {'jsonrpc':'2.0', 'method':'sample.add', 'id':'sample.add', 'params':[1, 2]}
  >>> res = testapp.post('/', params=json.dumps(call_values), content_type="application/json")
  >>> res.json
- {'jsonrpc': '2.0', 'id': 'sample.add', 'result': 3}
+ {u'jsonrpc': u'2.0', u'id': u'sample.add', u'result': 3}
 
 
 extra vars
@@ -93,3 +93,18 @@ extra vars
  >>> rpc['add'] = lambda a, b: a + b
  >>> rpc({'jsonrpc': '2.0', 'method': 'add', 'id': 'rpc-1', 'params': {'a': 2}}, b=3)
  {'jsonrpc': '2.0', 'id': 'rpc-1', 'result': 5}
+
+handle errors
+=================
+
+::
+
+ >>> from jsonrpc2 import JsonRpc
+ >>> class MyException(Exception):
+ ...     pass
+ >>> def my_rpc():
+ ...     raise MyException()
+ >>> rpc = JsonRpc({'call': my_rpc}, {MyException: -32001})
+ >>> rpc({'jsonrpc': '2.0', 'method': 'call', 'id': 'rpc-1', 'params': []})
+ {'jsonrpc': '2.0', 'id': 'rpc-1', 'error': {'message': '', 'code': -32001, 'data': '[]'}}
+
diff --git a/jsonrpc2.egg-info/PKG-INFO b/jsonrpc2.egg-info/PKG-INFO
index 34bb524..d1cb1f1 100644
--- a/jsonrpc2.egg-info/PKG-INFO
+++ b/jsonrpc2.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
-Metadata-Version: 1.0
+Metadata-Version: 1.1
 Name: jsonrpc2
-Version: 0.3.2
+Version: 0.4.1
 Summary: WSGI Framework for JSON RPC 2.0
 Home-page: http://hg.aodag.jp/jsonrpc2/
 Author: Atsushi Odagiri
@@ -8,8 +8,12 @@ Author-email: aodagx at gmail.com
 License: MIT
 Description: .. -*- restructuredtext -*-
         
+        .. image:: https://drone.io/bitbucket.org/aodag/jsonrpc2/status.png
+           :target: https://drone.io/bitbucket.org/aodag/jsonrpc2/latest
+        
         jsonrpc2 is WSGI Framework for JSON RPC 2.0.
-        JSON RPC 2.0 Spec can be seen on http://groups.google.com/group/json-rpc/web/json-rpc-2-0
+        
+        JSON RPC 2.0 Spec can be seen on http://www.jsonrpc.org/specification .
         
         .. contents::
         
@@ -20,10 +24,6 @@ Description: .. -*- restructuredtext -*-
         
          $ pip install jsonrpc2
         
-        or install via easy_install::
-        
-         $ easy_install jsonrpc2
-        
         write your procedures in hello.py::
         
          def greeting(name):
@@ -54,7 +54,7 @@ Description: .. -*- restructuredtext -*-
         
         ::
         
-         >>> import simplejson as json
+         >>> import json
          >>> from jsonrpc2 import JsonRpcApplication
         
         sample procedure::
@@ -79,7 +79,7 @@ Description: .. -*- restructuredtext -*-
         got results::
         
          >>> res.json
-         {'jsonrpc': '2.0', 'id': 'greeting', 'result': 'Hello, world!'}
+         {u'jsonrpc': u'2.0', u'id': u'greeting', u'result': u'Hello, world!'}
         
         
         lazy loading::
@@ -88,7 +88,7 @@ Description: .. -*- restructuredtext -*-
          >>> call_values = {'jsonrpc':'2.0', 'method':'sample.add', 'id':'sample.add', 'params':[1, 2]}
          >>> res = testapp.post('/', params=json.dumps(call_values), content_type="application/json")
          >>> res.json
-         {'jsonrpc': '2.0', 'id': 'sample.add', 'result': 3}
+         {u'jsonrpc': u'2.0', u'id': u'sample.add', u'result': 3}
         
         
         extra vars
@@ -102,6 +102,21 @@ Description: .. -*- restructuredtext -*-
          >>> rpc({'jsonrpc': '2.0', 'method': 'add', 'id': 'rpc-1', 'params': {'a': 2}}, b=3)
          {'jsonrpc': '2.0', 'id': 'rpc-1', 'result': 5}
         
+        handle errors
+        =================
+        
+        ::
+        
+         >>> from jsonrpc2 import JsonRpc
+         >>> class MyException(Exception):
+         ...     pass
+         >>> def my_rpc():
+         ...     raise MyException()
+         >>> rpc = JsonRpc({'call': my_rpc}, {MyException: -32001})
+         >>> rpc({'jsonrpc': '2.0', 'method': 'call', 'id': 'rpc-1', 'params': []})
+         {'jsonrpc': '2.0', 'id': 'rpc-1', 'error': {'message': '', 'code': -32001, 'data': '[]'}}
+        
+        
         JSON-RPC2 Example
         =====================================================
         
@@ -147,6 +162,7 @@ Description: .. -*- restructuredtext -*-
          >>> rpc({"jsonrpc": "2.0", "method": "foobar"})
         
         Procedure Call of non-existent procedure::
+        
          >>> del rpc['foobar']
          >>> rpc({"jsonrpc": "2.0", "method": "foobar", "id": "1"})
          {'jsonrpc': '2.0', 'id': '1', 'error': {'message': 'Method Not Found', 'code': -32601}}
@@ -189,45 +205,63 @@ Description: .. -*- restructuredtext -*-
         
         
         
-        ChangeLog
-        ===================================================
-        
-        0.3
-        -----------------------------------------------
-        
-        - fix bugs
-        - Paste Scripte templates
-        - runjsonrpc2 command
-        
-        0.3.1
-        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-        
-        - fix bugs (content-type with charset)
-        
-        0.3.2
-        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-        - enable to pass the extra vars to procedures
-        
-        0.2
-        -----------------------------------------------
-        
-        - remove dependency to WebOb
-        - split procedure call class from web application class
-        
-        0.2.1
-        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-        
-        - lazy loading from method name.
-        
-        0.2.2
-        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-        
-        - add dict interface.
-        
-        0.2.3
-        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-        
-        - fix: read body with CONTENT_LENGTH.
+        ChangeLog
+        ===================================================
+        
+        0.4.1
+        ------------------------------
+        
+        - 0.4 is brown bag release.
+        
+        0.4
+        -----------------------------------------------
+        feature
+        
+        - added supporting py3
+        - added registering application errors
+        
+        fixed bugs
+        
+        - Dont raise internal error for server exceptions `#13 <https://bitbucket.org/aodag/jsonrpc2/issue/13/dont-raise-internal-error-for-server>`_
+        - incorrect Content-type `#15 https://bitbucket.org/aodag/jsonrpc2/issue/15/incorrect-content-type`_
+        - internal logging configuration broken `#16 <https://bitbucket.org/aodag/jsonrpc2/issue/16/internal-logging-configuration-broken>`_
+        
+        0.3
+        -----------------------------------------------
+        
+        - fix bugs
+        - Paste Scripte templates
+        - runjsonrpc2 command
+        
+        0.3.1
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+        
+        - fix bugs (content-type with charset)
+        
+        0.3.2
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+        - enable to pass the extra vars to procedures
+        
+        0.2
+        -----------------------------------------------
+        
+        - remove dependency to WebOb
+        - split procedure call class from web application class
+        
+        0.2.1
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+        
+        - lazy loading from method name.
+        
+        0.2.2
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+        
+        - add dict interface.
+        
+        0.2.3
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+        
+        - fix: read body with CONTENT_LENGTH.
         
 Keywords: wsgi request web http json rpc
 Platform: UNKNOWN
@@ -235,3 +269,9 @@ Classifier: Intended Audience :: Developers
 Classifier: License :: OSI Approved :: MIT License
 Classifier: Topic :: Internet :: WWW/HTTP :: WSGI
 Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.2
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
diff --git a/jsonrpc2.egg-info/SOURCES.txt b/jsonrpc2.egg-info/SOURCES.txt
index 43a39b1..c2b3f79 100644
--- a/jsonrpc2.egg-info/SOURCES.txt
+++ b/jsonrpc2.egg-info/SOURCES.txt
@@ -1,6 +1,6 @@
 ChangeLog
 MANIFEST.in
-README
+README.rst
 rpc_example.txt
 setup.cfg
 setup.py
diff --git a/jsonrpc2.egg-info/entry_points.txt b/jsonrpc2.egg-info/entry_points.txt
index 3a36ff8..ad0d4d7 100644
--- a/jsonrpc2.egg-info/entry_points.txt
+++ b/jsonrpc2.egg-info/entry_points.txt
@@ -1,9 +1,9 @@
+[console_scripts]
+runjsonrpc2 = jsonrpc2.cmd:main
+
 [paste.app_factory]
 main = jsonrpc2.paste:make_app
 
 [paste.paster_create_template]
 paster_jsonrpc2 = jsonrpc2.paste.templates:JsonRpcTemplate
 
-[console_scripts]
-runjsonrpc2 = jsonrpc2.cmd:main
-
diff --git a/jsonrpc2.egg-info/requires.txt b/jsonrpc2.egg-info/requires.txt
index 171cf31..acdd1bd 100644
--- a/jsonrpc2.egg-info/requires.txt
+++ b/jsonrpc2.egg-info/requires.txt
@@ -1,9 +1,9 @@
+six
 
+[PASTE]
+PasteScript
 
 [test]
-Nose
-WebTest
-simplejson
-
-[PASTE]
-PasteScript
\ No newline at end of file
+pytest
+pytest-cov
+WebTest
\ No newline at end of file
diff --git a/jsonrpc2/__init__.py b/jsonrpc2/__init__.py
index dc33ead..3ad7c38 100644
--- a/jsonrpc2/__init__.py
+++ b/jsonrpc2/__init__.py
@@ -41,24 +41,23 @@ INVALID_REQUEST = -32600
 METHOD_NOT_FOUND = -32601
 INVALID_PARAMS = -32602
 INTERNAL_ERROR = -32603
+GENERIC_APPLICATION_ERROR = -32000
+
 errors = {}
 errors[PARSE_ERROR] = "Parse Error"
 errors[INVALID_REQUEST] = "Invalid Request"
 errors[METHOD_NOT_FOUND] = "Method Not Found"
 errors[INVALID_PARAMS] = "Invalid Params"
 errors[INTERNAL_ERROR] = "Internal Error"
-import sys
-try:
-    import json
-except ImportError:
-    try:
-        import django.utils.simplejson as json
-        sys.modules['json'] = json
-    except ImportError:
-        import simplejson as json
-        sys.modules['json'] = json
+errors[GENERIC_APPLICATION_ERROR] = "Application Error"
 
+import sys
+import json
+import logging
 import itertools
+from six import string_types
+
+logger = logging.getLogger(__name__)
 
 class JsonRpcException(Exception):
     """
@@ -94,19 +93,31 @@ class JsonRpcException(Exception):
         return json.dumps(self.as_dict())
 
 class JsonRpcBase(object):
-    def __init__(self, methods=None):
+    def __init__(self, methods=None,
+                 application_errors={}):
         if methods is not None:
             self.methods = methods
         else:
             self.methods = {}
 
+        message = ('extra error code must '
+                   'be from {0} to {1}').format(-32099, -32001)
+        for code in application_errors.values():
+            if code < -32100 or code > -32001:
+                raise ValueError(message, code)
+        self.application_errors = application_errors.copy()
+        self.exceptable = tuple(application_errors)
+
     def load_method(self, method):
-        import sys
         module_name, func_name = method.split(':', 1)
         __import__(module_name)
         method = getattr(sys.modules[module_name], func_name)
         return method
 
+    def get_app_error_code(self, exc):
+        exc_type = type(exc)
+        return self.application_errors[exc_type]
+
     def process(self, data, extra_vars):
 
         if data.get('jsonrpc') != "2.0":
@@ -116,7 +127,7 @@ class JsonRpcBase(object):
             raise JsonRpcException(data.get('id'), INVALID_REQUEST)
         
         methodname = data['method']
-        if not isinstance(methodname, basestring):
+        if not isinstance(methodname, string_types):
             raise JsonRpcException(data.get('id'), INVALID_REQUEST)
             
         if methodname.startswith('_'):
@@ -128,37 +139,56 @@ class JsonRpcBase(object):
 
 
         method = self.methods[methodname]
-        if isinstance(method, basestring):
+        params = data.get('params', [])
+
+        if isinstance(method, string_types):
             method = self.load_method(method)
 
+        if not isinstance(params, (list, dict)):
+            raise JsonRpcException(data.get('id'), INVALID_PARAMS)
+
+        args = []
+        kwargs = {}
+        if isinstance(params, list):
+            args = params
+        elif isinstance(params, dict):
+            kwargs.update(params)
+            kwargs.update(extra_vars)
+
         try:
-            params = data.get('params', [])
-            if isinstance(params, list):
-                result = method(*params, **extra_vars)
-            elif isinstance(params, dict):
-                kwargs = dict([(str(k), v) for k, v in params.iteritems()])
-                kwargs.update(extra_vars)
-                result = method(**kwargs)
-            else:
-                raise JsonRpcException(data.get('id'), INVALID_PARAMS)
-            resdata = None
-            if data.get('id'):
-
-                resdata = {
-                    'jsonrpc':'2.0',
-                    'id':data.get('id'),
-                    'result':result,
-                    }
-            return resdata
-        except JsonRpcException, e:
-            raise e
-        except Exception, e:
-            raise JsonRpcException(data.get('id'), INTERNAL_ERROR, data=str(e))
+            result = method(*args, **kwargs)
+        except self.exceptable as e:
+            return {
+                'jsonrpc':'2.0',
+                'id':data.get('id'),
+                'error':{'code': self.get_app_error_code(e),
+                         'message': str(e), 
+                         'data': json.dumps(e.args)}
+            }
+        except Exception as e:
+            return {
+                'jsonrpc':'2.0',
+                'id':data.get('id'),
+                'error':{'code': GENERIC_APPLICATION_ERROR,
+                         'message': str(e), 
+                         'data': json.dumps(e.args)}
+            }
+
+
+        if not data.get('id'):
+            return None
+
+        return {
+            'jsonrpc':'2.0',
+            'id':data.get('id'),
+            'result':result,
+        }
+
 
     def _call(self, data, extra_vars):
         try:
             return self.process(data, extra_vars)
-        except JsonRpcException, e:
+        except JsonRpcException as e:
             return e.as_dict()
 
     def __call__(self, data, **extra_vars):
@@ -186,34 +216,31 @@ class JsonRpcBase(object):
 
 
 class JsonRpc(JsonRpcBase):
-    def __init__(self, methods=None):
-        super(JsonRpc, self).__init__(methods)
+    # def __init__(self, methods=None, application_errors={}):
+    #     super(JsonRpc, self).__init__(methods, application_errors)
 
     def add_module(self, mod):
         name = mod.__name__
-        for k, v in ((k, v) for k, v in mod.__dict__.iteritems() if not k.startswith('_') and callable(v)):
+        for k, v in ((k, v) for k, v in mod.__dict__.items() if not k.startswith('_') and callable(v)):
             self.methods[name + '.' + k] = v
 
     addModule = add_module
 
-import logging
-import sys
-logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
 class JsonRpcApplication(object):
-    def __init__(self, rpcs=None):
-        self.rpc = JsonRpc(rpcs)
+    def __init__(self, rpcs=None, application_errors={}):
+        self.rpc = JsonRpc(rpcs, application_errors)
 
 
     def __call__(self, environ, start_response):
-        logging.debug("jsonrpc")
-        logging.debug("check method")
+        logger.debug("jsonrpc")
+        logger.debug("check method")
         if environ['REQUEST_METHOD'] != "POST":
             start_response('405 Method Not Allowed',
                     [('Content-type', 'text/plain')])
             return ["405 Method Not Allowed"]
 
-        logging.debug("check content-type")
-        if environ['CONTENT_TYPE'].split(';', 1)[0] != 'application/json':
+        logger.debug("check content-type")
+        if environ['CONTENT_TYPE'].split(';', 1)[0] not in ('application/json', 'application/json-rpc'):
             start_response('400 Bad Request',
                     [('Content-type', 'text/plain')])
             return ["Content-type must by application/json"]
@@ -223,10 +250,11 @@ class JsonRpcApplication(object):
             content_length = int(environ["CONTENT_LENGTH"])
         try:
             body = environ['wsgi.input'].read(content_length)
+            body = body.decode('utf-8')
             data = json.loads(body)
             resdata = self.rpc(data) 
-            logging.debug("response %s" % json.dumps(resdata))
-        except ValueError, e:
+            logger.debug("response %s" % json.dumps(resdata))
+        except ValueError as e:
             resdata = {'jsonrpc':'2.0',
                        'id':None,
                        'error':{'code':PARSE_ERROR,
@@ -237,7 +265,7 @@ class JsonRpcApplication(object):
 
 
         if resdata:
-            return [json.dumps(resdata)]
+            return [json.dumps(resdata).encode('utf-8')]
         return []
 
 
diff --git a/rpc_example.txt b/rpc_example.txt
index 93b73e9..e0dcc8e 100644
--- a/rpc_example.txt
+++ b/rpc_example.txt
@@ -43,6 +43,7 @@ Notification::
  >>> rpc({"jsonrpc": "2.0", "method": "foobar"})
 
 Procedure Call of non-existent procedure::
+
  >>> del rpc['foobar']
  >>> rpc({"jsonrpc": "2.0", "method": "foobar", "id": "1"})
  {'jsonrpc': '2.0', 'id': '1', 'error': {'message': 'Method Not Found', 'code': -32601}}
diff --git a/setup.cfg b/setup.cfg
index 65ee7bf..bd35539 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,9 +1,8 @@
+[wheel]
+universal = 1
+
 [egg_info]
-tag_build = 
-tag_date = 0
 tag_svn_revision = 0
-
-[nosetests]
-doctest-extension = .txt
-with-doctest = 1
+tag_date = 0
+tag_build = 
 
diff --git a/setup.py b/setup.py
index 1e171ec..b1de956 100644
--- a/setup.py
+++ b/setup.py
@@ -1,15 +1,15 @@
 from setuptools import setup, find_packages
 import os
 here = os.path.dirname(__file__)
-readme = open(os.path.join(here, "README")).read()
+readme = open(os.path.join(here, "README.rst")).read()
 example = open(os.path.join(here, "rpc_example.txt")).read()
 changelog = open(os.path.join(here, "ChangeLog")).read()
-version="0.3.2"
+version="0.4.1"
 
 tests_require = [
-    "Nose",
+    "pytest",
+    "pytest-cov",
     "WebTest",
-    "simplejson",
 ]
 
 setup(
@@ -21,6 +21,12 @@ setup(
         "License :: OSI Approved :: MIT License",
         "Topic :: Internet :: WWW/HTTP :: WSGI",
         "Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
+        "Programming Language :: Python :: 2.6",
+        "Programming Language :: Python :: 2.7",
+        "Programming Language :: Python :: 3",
+        "Programming Language :: Python :: 3.2",
+        "Programming Language :: Python :: 3.3",
+        "Programming Language :: Python :: 3.4",
         ],
     author='Atsushi Odagiri',
     author_email='aodagx at gmail.com',
@@ -29,9 +35,10 @@ setup(
     url='http://hg.aodag.jp/jsonrpc2/',
     version=version,
     install_requires=[
+        "six",
     ],
     include_package_data=True,
-    test_suite="nose.collector",
+    test_suite="jsonrpc2",
     tests_require=tests_require,
     extras_require={
         "PASTE":[

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-jsonrpc2.git



More information about the Python-modules-commits mailing list