[Python-modules-commits] [python-tornadorpc] 01/04: Imported Upstream version 0.1.1

Sandro Tosi morph at moszumanska.debian.org
Tue Jul 7 21:38:18 UTC 2015


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

morph pushed a commit to branch bpo8
in repository python-tornadorpc.

commit b5abf1f3fd9e2609bab4aa9b6d270c1936385a6c
Author: Sandro Tosi <morph at debian.org>
Date:   Tue Jul 7 17:29:08 2015 -0400

    Imported Upstream version 0.1.1
---
 PKG-INFO                                 | 243 ++++++++++++++++++
 README                                   | 233 +++++++++++++++++
 setup.cfg                                |   5 +
 setup.py                                 |  28 +++
 tornadorpc.egg-info/PKG-INFO             | 243 ++++++++++++++++++
 tornadorpc.egg-info/SOURCES.txt          |  12 +
 tornadorpc.egg-info/dependency_links.txt |   1 +
 tornadorpc.egg-info/requires.txt         |   2 +
 tornadorpc.egg-info/top_level.txt        |   1 +
 tornadorpc/__init__.py                   |  16 ++
 tornadorpc/base.py                       | 418 +++++++++++++++++++++++++++++++
 tornadorpc/json.py                       | 129 ++++++++++
 tornadorpc/utils.py                      |  57 +++++
 tornadorpc/xml.py                        |  93 +++++++
 14 files changed, 1481 insertions(+)

diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..1428a7f
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,243 @@
+Metadata-Version: 1.0
+Name: tornadorpc
+Version: 0.1.1
+Summary: TornadoRPC is a an implementation of both JSON-RPC and XML-RPC handlers for the Tornado framework.
+Home-page: http://code.google.com/p/tornadorpc/
+Author: Josh Marshall
+Author-email: catchjosh at gmail.com
+License: http://www.apache.org/licenses/LICENSE-2.0
+Description: [![Build Status](https://travis-ci.org/joshmarshall/tornadorpc.png?branch=master)](https://travis-ci.org/joshmarshall/tornadorpc)
+        TORNADO-RPC
+        ===========
+        This library is an implementation of both the JSON-RPC and the
+        XML-RPC specification (server-side) for the Tornado web framework.
+        It supports the basic features of both, as well as the MultiCall /
+        Batch support for both specifications. The JSON-RPC handler supports 
+        both the original 1.0 specification, as well as the new (proposed) 
+        2.0 spec, which includes batch submission, keyword arguments, etc.
+        
+        Asynchronous request support has been added for methods which require 
+        the use of asynchronous libraries (like Tornado's AsyncHTTPClient 
+        library.)
+        
+        TornadoRPC is licensed under the Apache License, Version 2.0
+        (http://www.apache.org/licenses/LICENSE-2.0.html).
+        
+        Mailing List
+        ------------
+        If you have any questions, issues, or just use the library please feel 
+        free to send a message to the mailing list at:
+        
+            http://groups.google.com/group/tornadorpc
+        
+        Installation
+        ------------
+        To install:
+        
+            python setup.py build
+            sudo python setup.py install
+        
+        To use this module, you'll need Tornado installed, which you can
+        get at this address:
+        
+        http://www.tornadoweb.org/
+        
+        If you want to use the JSON-RPC handler, you'll also need 
+        jsonrpclib, which you can grab at:
+        
+        http://github.com/joshmarshall/jsonrpclib/
+        
+        The jsonrpclib library requires one of the JSON libraries. It looks 
+        first for cjson, then for the built-in JSON library (with default 
+        Python 2.6+ distributions), and finally the simplejson library.
+        
+        Overview
+        --------
+        This library is an implementation of both the JSON-RPC and the XML-RPC 
+        specification (server-side) for the Tornado web framework. It supports 
+        the basic features of both, as well as the MultiCall / Batch support for 
+        both specifications. The JSON-RPC handler supports both the original 1.0 
+        specification, as well as the new (proposed) 2.0 spec, which includes batch 
+        submission, keyword arguments, etc. 
+        
+        There is also a base library that other RPC protocols could use to quickly 
+        get tied into Tornado.
+        
+        Requirements
+        ------------
+        The library obviously requires Tornado, which you can get at 
+        Tornado's website (http://www.tornadoweb.org). After installing Tornado 
+        (instructions included with the Tornado distribution) you should be able 
+        to use the XML-RPC handler without any other libraries.
+        
+        The JSON-RPC handler requires my jsonrpclib library, which you can get 
+        at http://github.com/joshmarshall/jsonrpclib . It also requires a JSON 
+        library, although any distribution of Python past 2.5 should have it by 
+        default. (Note: Some Linuxes only include a base Python install. On Ubuntu, 
+        for instance, you may need to run `sudo apt-get install python-json` or 
+        `sudo apt-get python-cjson` to get one of the libraries.)
+        
+        Usage
+        -----
+        The library is designed to be mostly transparent in usage. You simply 
+        extend the XML/JSON RPCHandler class from either the tornadorpc.xml or 
+        the tornado.json library, resepectively, and pass that handler in to 
+        the Tornado framework just like any other handler. 
+        
+        For any synchronous (normal) operation, you can just return the value
+        you want sent to the client. However, if you use any asynchronous
+        library (like Tornado's AsyncHTTPClient) you will want to call 
+        self.result(RESULT) in your callback. See the Asynchronous section
+        below for examples.
+        
+        XML-RPC Example
+        ---------------
+        To set up a simple XML RPC server, this is all you need:
+        
+        	from tornadorpc.xml import XMLRPCHandler
+        	from tornadorpc import private, start_server
+        
+        	class Handler(XMLRPCHandler):
+        
+        	    def add(self, x, y):
+        	        return x+y
+        
+        	    def ping(self, obj):
+        	        return obj
+            
+        	    @private
+        	    def private(self):
+        	        #should not get called
+        	        return False
+        
+        	start_server(Handler, port=8080)
+        
+        The `@private` decorator is a way to ensure that it cannot be called 
+        externally. You can also create methods that start with an underscore `_` 
+        character, and they will be private by default. The `start_server` function 
+        is just an easy wrap around the default Tornado setup -- you can use these 
+        handlers just like you would any other Tornado RequestHandler. 
+        
+        JSON-RPC Example
+        ----------------
+        A JSON-RPC server would be started with the exact same syntax, replacing 
+        XMLRPCHandler with JSONRPCHandler. Here is an example of the JSON-RPC 
+        client with "dot-attribute" support:
+        
+        	from tornadorpc.json import JSONRPCHandler
+        	from tornadorpc import private, start_server
+        
+        	class Tree(object):
+        
+        	    def power(self, base, power, modulo=None):
+        	        result = pow(base, power, modulo)
+                    return result
+          
+        	    def _private(self):
+        	        # Won't be callable
+        	        return False
+        
+        	class Handler(JSONRPCHandler):
+        
+        	    tree = Tree()
+        
+        	    def add(self, x, y):
+        	        return x+y
+        
+        	    def ping(self, obj):
+        	        return obj
+        
+        	start_server(Handler, port=8080)
+        
+        To use this, you should be able to use either the JSON-RPC official 
+        implementation, or the jsonrpclib library (which you'd need for this to 
+        work anyway.) One of the benefits of the jsonrpclib is designed to be a 
+        parallel implementation to the xmlrpclib, so syntax should be very similar 
+        and it should be easy to experiment with existing apps.
+        
+        An example of client usage would be:
+        
+            from jsonrpclib import Server
+            server = Server('http://localhost:8080')
+            result = server.tree.power(2, 6)
+            # result should equal 64
+        
+        Asynchronous Example
+        --------------------
+        To indicate that a request is asynchronous, simply use the "async" 
+        decorator, and call "self.result(RESULT)" in your callback. Please note
+        that this will only work in the RPCHandler methods, not in any sub-tree
+        methods since they do not have access to the handler's result() method.
+        
+        Here is an example that uses Tornado's AsyncHTTPClient with a callback:
+        
+            from tornadorpc import async
+            from tornadorpc.xml import XMLRPCHandler
+            from tornado.httpclient import AsyncHTTPClient
+        
+            class Handler(XMLRPCHandler):
+                
+                @async
+                def external(self, url):
+                    client = AsyncHTTPClient()
+                    client.fetch(url, self._handle_response)
+                    
+                def _handle_response(self, response):
+                    # The underscore will make it private automatically
+                    # You could also use @private if you wished
+                    # This returns the status code of the request
+                    self.result(response.code)
+        
+        Debugging
+        ---------
+        There is a `config` object that is available -- it will be expanded as time 
+        goes by. Currently, it supports two options: `verbose` and `short_errors`, 
+        both of which default to True. The `verbose` setting just specifies whether 
+        you want to print out results to the terminal (automatically on, you'll 
+        probably want to turn that off for production, WSGI deployment, etc.) and 
+        the `short_errors` option determines whether to print just the last few 
+        lines of the traceback (if set to True, default) or print the full traceback. 
+        Once the logging mechanism is in place, the `short_errors` configuration 
+        element will apply to that as well.
+        
+        The default error look something similar to this:
+        
+        	JSON-RPC SERVER AT http://localhost:8484
+        	---------------
+        	ERROR IN messup
+        	---------------
+        	Traceback (most recent call last):
+        	  File "test.py", line 20, in messup
+        	    return doesntexist['bad_key']
+        	NameError: global name 'doesntexist' is not defined
+        
+        To change the configuration, look over the following:
+        
+        	import tornadorpc
+        	tornadorpc.config.verbose = False
+        	tornadorpc.config.short_errors = False
+        	# or...
+        	from tornadorpc import config
+        	config.verbose = False
+        	config.short_errors = False
+            
+        Tests
+        -----
+        To run some basic tests, enter the following in the same directory that
+        this README is in:
+        
+            python run_tests.py
+            
+        This will test a few basic utilites and the XMLRPC system. If you wish
+        to test the JSONRPC system, run the following:
+            
+            python run_tests.py --json
+            
+        TODO
+        ----
+        * Add unit tests
+        * Add logging mechanism
+        * Add proper HTTP codes for failures
+        * Optimize
+        
+Platform: UNKNOWN
diff --git a/README b/README
new file mode 100644
index 0000000..737c0d4
--- /dev/null
+++ b/README
@@ -0,0 +1,233 @@
+[![Build Status](https://travis-ci.org/joshmarshall/tornadorpc.png?branch=master)](https://travis-ci.org/joshmarshall/tornadorpc)
+TORNADO-RPC
+===========
+This library is an implementation of both the JSON-RPC and the
+XML-RPC specification (server-side) for the Tornado web framework.
+It supports the basic features of both, as well as the MultiCall /
+Batch support for both specifications. The JSON-RPC handler supports 
+both the original 1.0 specification, as well as the new (proposed) 
+2.0 spec, which includes batch submission, keyword arguments, etc.
+
+Asynchronous request support has been added for methods which require 
+the use of asynchronous libraries (like Tornado's AsyncHTTPClient 
+library.)
+
+TornadoRPC is licensed under the Apache License, Version 2.0
+(http://www.apache.org/licenses/LICENSE-2.0.html).
+
+Mailing List
+------------
+If you have any questions, issues, or just use the library please feel 
+free to send a message to the mailing list at:
+
+    http://groups.google.com/group/tornadorpc
+
+Installation
+------------
+To install:
+
+    python setup.py build
+    sudo python setup.py install
+
+To use this module, you'll need Tornado installed, which you can
+get at this address:
+
+http://www.tornadoweb.org/
+
+If you want to use the JSON-RPC handler, you'll also need 
+jsonrpclib, which you can grab at:
+
+http://github.com/joshmarshall/jsonrpclib/
+
+The jsonrpclib library requires one of the JSON libraries. It looks 
+first for cjson, then for the built-in JSON library (with default 
+Python 2.6+ distributions), and finally the simplejson library.
+
+Overview
+--------
+This library is an implementation of both the JSON-RPC and the XML-RPC 
+specification (server-side) for the Tornado web framework. It supports 
+the basic features of both, as well as the MultiCall / Batch support for 
+both specifications. The JSON-RPC handler supports both the original 1.0 
+specification, as well as the new (proposed) 2.0 spec, which includes batch 
+submission, keyword arguments, etc. 
+
+There is also a base library that other RPC protocols could use to quickly 
+get tied into Tornado.
+
+Requirements
+------------
+The library obviously requires Tornado, which you can get at 
+Tornado's website (http://www.tornadoweb.org). After installing Tornado 
+(instructions included with the Tornado distribution) you should be able 
+to use the XML-RPC handler without any other libraries.
+
+The JSON-RPC handler requires my jsonrpclib library, which you can get 
+at http://github.com/joshmarshall/jsonrpclib . It also requires a JSON 
+library, although any distribution of Python past 2.5 should have it by 
+default. (Note: Some Linuxes only include a base Python install. On Ubuntu, 
+for instance, you may need to run `sudo apt-get install python-json` or 
+`sudo apt-get python-cjson` to get one of the libraries.)
+
+Usage
+-----
+The library is designed to be mostly transparent in usage. You simply 
+extend the XML/JSON RPCHandler class from either the tornadorpc.xml or 
+the tornado.json library, resepectively, and pass that handler in to 
+the Tornado framework just like any other handler. 
+
+For any synchronous (normal) operation, you can just return the value
+you want sent to the client. However, if you use any asynchronous
+library (like Tornado's AsyncHTTPClient) you will want to call 
+self.result(RESULT) in your callback. See the Asynchronous section
+below for examples.
+
+XML-RPC Example
+---------------
+To set up a simple XML RPC server, this is all you need:
+
+	from tornadorpc.xml import XMLRPCHandler
+	from tornadorpc import private, start_server
+
+	class Handler(XMLRPCHandler):
+
+	    def add(self, x, y):
+	        return x+y
+
+	    def ping(self, obj):
+	        return obj
+    
+	    @private
+	    def private(self):
+	        #should not get called
+	        return False
+
+	start_server(Handler, port=8080)
+
+The `@private` decorator is a way to ensure that it cannot be called 
+externally. You can also create methods that start with an underscore `_` 
+character, and they will be private by default. The `start_server` function 
+is just an easy wrap around the default Tornado setup -- you can use these 
+handlers just like you would any other Tornado RequestHandler. 
+
+JSON-RPC Example
+----------------
+A JSON-RPC server would be started with the exact same syntax, replacing 
+XMLRPCHandler with JSONRPCHandler. Here is an example of the JSON-RPC 
+client with "dot-attribute" support:
+
+	from tornadorpc.json import JSONRPCHandler
+	from tornadorpc import private, start_server
+
+	class Tree(object):
+
+	    def power(self, base, power, modulo=None):
+	        result = pow(base, power, modulo)
+            return result
+  
+	    def _private(self):
+	        # Won't be callable
+	        return False
+
+	class Handler(JSONRPCHandler):
+
+	    tree = Tree()
+
+	    def add(self, x, y):
+	        return x+y
+
+	    def ping(self, obj):
+	        return obj
+
+	start_server(Handler, port=8080)
+
+To use this, you should be able to use either the JSON-RPC official 
+implementation, or the jsonrpclib library (which you'd need for this to 
+work anyway.) One of the benefits of the jsonrpclib is designed to be a 
+parallel implementation to the xmlrpclib, so syntax should be very similar 
+and it should be easy to experiment with existing apps.
+
+An example of client usage would be:
+
+    from jsonrpclib import Server
+    server = Server('http://localhost:8080')
+    result = server.tree.power(2, 6)
+    # result should equal 64
+
+Asynchronous Example
+--------------------
+To indicate that a request is asynchronous, simply use the "async" 
+decorator, and call "self.result(RESULT)" in your callback. Please note
+that this will only work in the RPCHandler methods, not in any sub-tree
+methods since they do not have access to the handler's result() method.
+
+Here is an example that uses Tornado's AsyncHTTPClient with a callback:
+
+    from tornadorpc import async
+    from tornadorpc.xml import XMLRPCHandler
+    from tornado.httpclient import AsyncHTTPClient
+
+    class Handler(XMLRPCHandler):
+        
+        @async
+        def external(self, url):
+            client = AsyncHTTPClient()
+            client.fetch(url, self._handle_response)
+            
+        def _handle_response(self, response):
+            # The underscore will make it private automatically
+            # You could also use @private if you wished
+            # This returns the status code of the request
+            self.result(response.code)
+
+Debugging
+---------
+There is a `config` object that is available -- it will be expanded as time 
+goes by. Currently, it supports two options: `verbose` and `short_errors`, 
+both of which default to True. The `verbose` setting just specifies whether 
+you want to print out results to the terminal (automatically on, you'll 
+probably want to turn that off for production, WSGI deployment, etc.) and 
+the `short_errors` option determines whether to print just the last few 
+lines of the traceback (if set to True, default) or print the full traceback. 
+Once the logging mechanism is in place, the `short_errors` configuration 
+element will apply to that as well.
+
+The default error look something similar to this:
+
+	JSON-RPC SERVER AT http://localhost:8484
+	---------------
+	ERROR IN messup
+	---------------
+	Traceback (most recent call last):
+	  File "test.py", line 20, in messup
+	    return doesntexist['bad_key']
+	NameError: global name 'doesntexist' is not defined
+
+To change the configuration, look over the following:
+
+	import tornadorpc
+	tornadorpc.config.verbose = False
+	tornadorpc.config.short_errors = False
+	# or...
+	from tornadorpc import config
+	config.verbose = False
+	config.short_errors = False
+    
+Tests
+-----
+To run some basic tests, enter the following in the same directory that
+this README is in:
+
+    python run_tests.py
+    
+This will test a few basic utilites and the XMLRPC system. If you wish
+to test the JSONRPC system, run the following:
+    
+    python run_tests.py --json
+    
+TODO
+----
+* Add unit tests
+* Add logging mechanism
+* Add proper HTTP codes for failures
+* Optimize
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..861a9f5
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,5 @@
+[egg_info]
+tag_build = 
+tag_date = 0
+tag_svn_revision = 0
+
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..aa92ab3
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env/python
+
+import os
+import setuptools
+
+
+readme_path = "README.md"
+if not os.path.exists(readme_path):
+    readme_path = "README"
+
+with open(readme_path) as readme:
+    long_description = readme.read()
+    with open("README", "w") as pypi_readme:
+        pypi_readme.write(long_description)
+
+setuptools.setup(
+    name="tornadorpc",
+    version="0.1.1",
+    packages=["tornadorpc"],
+    author="Josh Marshall",
+    install_requires=["tornado", "jsonrpclib"],
+    author_email="catchjosh at gmail.com",
+    url="http://code.google.com/p/tornadorpc/",
+    license="http://www.apache.org/licenses/LICENSE-2.0",
+    description="TornadoRPC is a an implementation of both JSON-RPC "
+        "and XML-RPC handlers for the Tornado framework.",
+    long_description=long_description
+)
diff --git a/tornadorpc.egg-info/PKG-INFO b/tornadorpc.egg-info/PKG-INFO
new file mode 100644
index 0000000..1428a7f
--- /dev/null
+++ b/tornadorpc.egg-info/PKG-INFO
@@ -0,0 +1,243 @@
+Metadata-Version: 1.0
+Name: tornadorpc
+Version: 0.1.1
+Summary: TornadoRPC is a an implementation of both JSON-RPC and XML-RPC handlers for the Tornado framework.
+Home-page: http://code.google.com/p/tornadorpc/
+Author: Josh Marshall
+Author-email: catchjosh at gmail.com
+License: http://www.apache.org/licenses/LICENSE-2.0
+Description: [![Build Status](https://travis-ci.org/joshmarshall/tornadorpc.png?branch=master)](https://travis-ci.org/joshmarshall/tornadorpc)
+        TORNADO-RPC
+        ===========
+        This library is an implementation of both the JSON-RPC and the
+        XML-RPC specification (server-side) for the Tornado web framework.
+        It supports the basic features of both, as well as the MultiCall /
+        Batch support for both specifications. The JSON-RPC handler supports 
+        both the original 1.0 specification, as well as the new (proposed) 
+        2.0 spec, which includes batch submission, keyword arguments, etc.
+        
+        Asynchronous request support has been added for methods which require 
+        the use of asynchronous libraries (like Tornado's AsyncHTTPClient 
+        library.)
+        
+        TornadoRPC is licensed under the Apache License, Version 2.0
+        (http://www.apache.org/licenses/LICENSE-2.0.html).
+        
+        Mailing List
+        ------------
+        If you have any questions, issues, or just use the library please feel 
+        free to send a message to the mailing list at:
+        
+            http://groups.google.com/group/tornadorpc
+        
+        Installation
+        ------------
+        To install:
+        
+            python setup.py build
+            sudo python setup.py install
+        
+        To use this module, you'll need Tornado installed, which you can
+        get at this address:
+        
+        http://www.tornadoweb.org/
+        
+        If you want to use the JSON-RPC handler, you'll also need 
+        jsonrpclib, which you can grab at:
+        
+        http://github.com/joshmarshall/jsonrpclib/
+        
+        The jsonrpclib library requires one of the JSON libraries. It looks 
+        first for cjson, then for the built-in JSON library (with default 
+        Python 2.6+ distributions), and finally the simplejson library.
+        
+        Overview
+        --------
+        This library is an implementation of both the JSON-RPC and the XML-RPC 
+        specification (server-side) for the Tornado web framework. It supports 
+        the basic features of both, as well as the MultiCall / Batch support for 
+        both specifications. The JSON-RPC handler supports both the original 1.0 
+        specification, as well as the new (proposed) 2.0 spec, which includes batch 
+        submission, keyword arguments, etc. 
+        
+        There is also a base library that other RPC protocols could use to quickly 
+        get tied into Tornado.
+        
+        Requirements
+        ------------
+        The library obviously requires Tornado, which you can get at 
+        Tornado's website (http://www.tornadoweb.org). After installing Tornado 
+        (instructions included with the Tornado distribution) you should be able 
+        to use the XML-RPC handler without any other libraries.
+        
+        The JSON-RPC handler requires my jsonrpclib library, which you can get 
+        at http://github.com/joshmarshall/jsonrpclib . It also requires a JSON 
+        library, although any distribution of Python past 2.5 should have it by 
+        default. (Note: Some Linuxes only include a base Python install. On Ubuntu, 
+        for instance, you may need to run `sudo apt-get install python-json` or 
+        `sudo apt-get python-cjson` to get one of the libraries.)
+        
+        Usage
+        -----
+        The library is designed to be mostly transparent in usage. You simply 
+        extend the XML/JSON RPCHandler class from either the tornadorpc.xml or 
+        the tornado.json library, resepectively, and pass that handler in to 
+        the Tornado framework just like any other handler. 
+        
+        For any synchronous (normal) operation, you can just return the value
+        you want sent to the client. However, if you use any asynchronous
+        library (like Tornado's AsyncHTTPClient) you will want to call 
+        self.result(RESULT) in your callback. See the Asynchronous section
+        below for examples.
+        
+        XML-RPC Example
+        ---------------
+        To set up a simple XML RPC server, this is all you need:
+        
+        	from tornadorpc.xml import XMLRPCHandler
+        	from tornadorpc import private, start_server
+        
+        	class Handler(XMLRPCHandler):
+        
+        	    def add(self, x, y):
+        	        return x+y
+        
+        	    def ping(self, obj):
+        	        return obj
+            
+        	    @private
+        	    def private(self):
+        	        #should not get called
+        	        return False
+        
+        	start_server(Handler, port=8080)
+        
+        The `@private` decorator is a way to ensure that it cannot be called 
+        externally. You can also create methods that start with an underscore `_` 
+        character, and they will be private by default. The `start_server` function 
+        is just an easy wrap around the default Tornado setup -- you can use these 
+        handlers just like you would any other Tornado RequestHandler. 
+        
+        JSON-RPC Example
+        ----------------
+        A JSON-RPC server would be started with the exact same syntax, replacing 
+        XMLRPCHandler with JSONRPCHandler. Here is an example of the JSON-RPC 
+        client with "dot-attribute" support:
+        
+        	from tornadorpc.json import JSONRPCHandler
+        	from tornadorpc import private, start_server
+        
+        	class Tree(object):
+        
+        	    def power(self, base, power, modulo=None):
+        	        result = pow(base, power, modulo)
+                    return result
+          
+        	    def _private(self):
+        	        # Won't be callable
+        	        return False
+        
+        	class Handler(JSONRPCHandler):
+        
+        	    tree = Tree()
+        
+        	    def add(self, x, y):
+        	        return x+y
+        
+        	    def ping(self, obj):
+        	        return obj
+        
+        	start_server(Handler, port=8080)
+        
+        To use this, you should be able to use either the JSON-RPC official 
+        implementation, or the jsonrpclib library (which you'd need for this to 
+        work anyway.) One of the benefits of the jsonrpclib is designed to be a 
+        parallel implementation to the xmlrpclib, so syntax should be very similar 
+        and it should be easy to experiment with existing apps.
+        
+        An example of client usage would be:
+        
+            from jsonrpclib import Server
+            server = Server('http://localhost:8080')
+            result = server.tree.power(2, 6)
+            # result should equal 64
+        
+        Asynchronous Example
+        --------------------
+        To indicate that a request is asynchronous, simply use the "async" 
+        decorator, and call "self.result(RESULT)" in your callback. Please note
+        that this will only work in the RPCHandler methods, not in any sub-tree
+        methods since they do not have access to the handler's result() method.
+        
+        Here is an example that uses Tornado's AsyncHTTPClient with a callback:
+        
+            from tornadorpc import async
+            from tornadorpc.xml import XMLRPCHandler
+            from tornado.httpclient import AsyncHTTPClient
+        
+            class Handler(XMLRPCHandler):
+                
+                @async
+                def external(self, url):
+                    client = AsyncHTTPClient()
+                    client.fetch(url, self._handle_response)
+                    
+                def _handle_response(self, response):
+                    # The underscore will make it private automatically
+                    # You could also use @private if you wished
+                    # This returns the status code of the request
+                    self.result(response.code)
+        
+        Debugging
+        ---------
+        There is a `config` object that is available -- it will be expanded as time 
+        goes by. Currently, it supports two options: `verbose` and `short_errors`, 
+        both of which default to True. The `verbose` setting just specifies whether 
+        you want to print out results to the terminal (automatically on, you'll 
+        probably want to turn that off for production, WSGI deployment, etc.) and 
+        the `short_errors` option determines whether to print just the last few 
+        lines of the traceback (if set to True, default) or print the full traceback. 
+        Once the logging mechanism is in place, the `short_errors` configuration 
+        element will apply to that as well.
+        
+        The default error look something similar to this:
+        
+        	JSON-RPC SERVER AT http://localhost:8484
+        	---------------
+        	ERROR IN messup
+        	---------------
+        	Traceback (most recent call last):
+        	  File "test.py", line 20, in messup
+        	    return doesntexist['bad_key']
+        	NameError: global name 'doesntexist' is not defined
+        
+        To change the configuration, look over the following:
+        
+        	import tornadorpc
+        	tornadorpc.config.verbose = False
+        	tornadorpc.config.short_errors = False
+        	# or...
+        	from tornadorpc import config
+        	config.verbose = False
+        	config.short_errors = False
+            
+        Tests
+        -----
+        To run some basic tests, enter the following in the same directory that
+        this README is in:
+        
+            python run_tests.py
+            
+        This will test a few basic utilites and the XMLRPC system. If you wish
+        to test the JSONRPC system, run the following:
+            
+            python run_tests.py --json
+            
+        TODO
+        ----
+        * Add unit tests
+        * Add logging mechanism
+        * Add proper HTTP codes for failures
+        * Optimize
+        
+Platform: UNKNOWN
diff --git a/tornadorpc.egg-info/SOURCES.txt b/tornadorpc.egg-info/SOURCES.txt
new file mode 100644
index 0000000..f8b0cf2
--- /dev/null
+++ b/tornadorpc.egg-info/SOURCES.txt
@@ -0,0 +1,12 @@
+README
+setup.py
+tornadorpc/__init__.py
+tornadorpc/base.py
+tornadorpc/json.py
+tornadorpc/utils.py
+tornadorpc/xml.py
+tornadorpc.egg-info/PKG-INFO
+tornadorpc.egg-info/SOURCES.txt
+tornadorpc.egg-info/dependency_links.txt
+tornadorpc.egg-info/requires.txt
+tornadorpc.egg-info/top_level.txt
\ No newline at end of file
diff --git a/tornadorpc.egg-info/dependency_links.txt b/tornadorpc.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/tornadorpc.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/tornadorpc.egg-info/requires.txt b/tornadorpc.egg-info/requires.txt
new file mode 100644
index 0000000..026cb08
--- /dev/null
+++ b/tornadorpc.egg-info/requires.txt
@@ -0,0 +1,2 @@
+tornado
+jsonrpclib
\ No newline at end of file
diff --git a/tornadorpc.egg-info/top_level.txt b/tornadorpc.egg-info/top_level.txt
new file mode 100644
index 0000000..6f59c25
--- /dev/null
+++ b/tornadorpc.egg-info/top_level.txt
@@ -0,0 +1 @@
+tornadorpc
diff --git a/tornadorpc/__init__.py b/tornadorpc/__init__.py
new file mode 100644
index 0000000..691fbde
--- /dev/null
+++ b/tornadorpc/__init__.py
@@ -0,0 +1,16 @@
+"""
+Copyright 2009 Josh Marshall
+Licensed under the Apache License, Version 2.0 (the "License"); 
+you may not use this file except in compliance with the License. 
+You may obtain a copy of the License at 
+
+   http://www.apache.org/licenses/LICENSE-2.0 
+
+Unless required by applicable law or agreed to in writing, software 
+distributed under the License is distributed on an "AS IS" BASIS, 
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+See the License for the specific language governing permissions and 
+limitations under the License. 
+"""
+
+from base import private, async, start_server, config
diff --git a/tornadorpc/base.py b/tornadorpc/base.py
new file mode 100644
index 0000000..e7935ea
--- /dev/null
+++ b/tornadorpc/base.py
@@ -0,0 +1,418 @@
+"""
+============================
+Base RPC Handler for Tornado
+============================
+This is a basic server implementation, designed for use within the
+Tornado framework. The classes in this library should not be used
+directly, but rather though the XML or JSON RPC implementations.
+You can use the utility functions like 'private' and 'start_server'.
+"""
+
+from tornado.web import RequestHandler
+import tornado.web
+import tornado.ioloop
+import tornado.httpserver
+import types
+import traceback
+from tornadorpc.utils import getcallargs
+
+
+# Configuration element
+class Config(object):
+    verbose = True
+    short_errors = True
+
+config = Config()
+
+
+class BaseRPCParser(object):
+    """
+    This class is responsible for managing the request, dispatch,
+    and response formatting of the system. It is tied into the
+    _RPC_ attribute of the BaseRPCHandler (or subclasses) and
+    populated as necessary throughout the request. Use the
+    .faults attribute to take advantage of the built-in error
+    codes.
+    """
+    content_type = 'text/plain'
+
+    def __init__(self, library, encode=None, decode=None):
+        # Attaches the RPC library and encode / decode functions.
+        self.library = library
+        if not encode:
+            encode = getattr(library, 'dumps')
+        if not decode:
+            decode = getattr(library, 'loads')
+        self.encode = encode
+        self.decode = decode
+        self.requests_in_progress = 0
+        self.responses = []
+
+    @property
+    def faults(self):
+        # Grabs the fault tree on request
+        return Faults(self)
+
+    def run(self, handler, request_body):
+        """
+        This is the main loop -- it passes the request body to
+        the parse_request method, and then takes the resulting
+        method(s) and parameters and passes them to the appropriate
+        method on the parent Handler class, then parses the response
+        into text and returns it to the parent Handler to send back
+        to the client.
+        """
+        self.handler = handler
+        try:
+            requests = self.parse_request(request_body)
+        except:
+            self.traceback()
+            return self.handler.result(self.faults.parse_error())
+        if not isinstance(requests, types.TupleType):
+            # SHOULD be the result of a fault call,
+            # according tothe parse_request spec below.
+            if isinstance(requests, basestring):
+                # Should be the response text of a fault
+                # This will break in Python 3.x
+                return requests
+            elif hasattr(requests, 'response'):
+                # Fault types should have a 'response' method
+                return requests.response()
+            elif hasattr(requests, 'faultCode'):
+                # XML-RPC fault types need to be properly dispatched. This
+                # should only happen if there was an error parsing the
+                # request above.
+                return self.handler.result(requests)
+            else:
+                # No idea, hopefully the handler knows what it
+                # is doing.
+                return requests
+        self.handler._requests = len(requests)
+        for request in requests:
+            self.dispatch(request[0], request[1])
+
+    def dispatch(self, method_name, params):
+        """
+        This method walks the attribute tree in the method
+        and passes the parameters, either in positional or
+        keyword form, into the appropriate method on the
+        Handler class. Currently supports only positional
+        or keyword arguments, not mixed.
+        """
+        if hasattr(RequestHandler, method_name):
+            # Pre-existing, not an implemented attribute
+            return self.handler.result(self.faults.method_not_found())
+        method = self.handler
+        method_list = dir(method)
+        method_list.sort()
+        attr_tree = method_name.split('.')
+        try:
+            for attr_name in attr_tree:
+                method = self.check_method(attr_name, method)
+        except AttributeError:
+            return self.handler.result(self.faults.method_not_found())
+        if not callable(method):
+            # Not callable, so not a method
+            return self.handler.result(self.faults.method_not_found())
+        if method_name.startswith('_') or \
+                getattr(method, 'private', False) is True:
+            # No, no. That's private.
+            return self.handler.result(self.faults.method_not_found())
+        args = []
+        kwargs = {}
+        if isinstance(params, dict):
+            # The parameters are keyword-based
+            kwargs = params
+        elif type(params) in (list, tuple):
... 589 lines suppressed ...

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



More information about the Python-modules-commits mailing list