forked from joshmarshall/jsonrpclib
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First version of a documentation site
- Loading branch information
Showing
10 changed files
with
687 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Minimal makefile for Sphinx documentation | ||
# | ||
|
||
# You can set these variables from the command line. | ||
SPHINXOPTS = | ||
SPHINXBUILD = sphinx-build | ||
SOURCEDIR = . | ||
BUILDDIR = _build | ||
|
||
# Put it first so that "make" without argument is like "make help". | ||
help: | ||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) | ||
|
||
.PHONY: help Makefile | ||
|
||
# Catch-all target: route all unknown targets to Sphinx using the new | ||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). | ||
%: Makefile | ||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
.. _class_translation: | ||
|
||
Class Translation | ||
***************** | ||
|
||
I've recently added "automatic" class translation support, although it is | ||
turned off by default. This can be devastatingly slow if improperly used, so | ||
the following is just a short list of things to keep in mind when using it. | ||
|
||
* Keep It (the object) Simple Stupid. (for exceptions, keep reading.) | ||
* Do not require init params (for exceptions, keep reading) | ||
* Getter properties without setters could be dangerous (read: not tested) | ||
|
||
If any of the above are issues, use the _serialize method. (see usage below) | ||
The server and client must BOTH have use_jsonclass configuration item on and | ||
they must both have access to the same libraries used by the objects for | ||
this to work. | ||
|
||
If you have excessively nested arguments, it would be better to turn off the | ||
translation and manually invoke it on specific objects using | ||
``jsonrpclib.jsonclass.dump`` / ``jsonrpclib.jsonclass.load`` (since the default | ||
behavior recursively goes through attributes and lists / dicts / tuples). | ||
|
||
Sample file: *test_obj.py* | ||
|
||
.. code-block:: python | ||
# This object is /very/ simple, and the system will look through the | ||
# attributes and serialize what it can. | ||
class TestObj(object): | ||
foo = 'bar' | ||
# This object requires __init__ params, so it uses the _serialize method | ||
# and returns a tuple of init params and attribute values (the init params | ||
# can be a dict or a list, but the attribute values must be a dict.) | ||
class TestSerial(object): | ||
foo = 'bar' | ||
def __init__(self, *args): | ||
self.args = args | ||
def _serialize(self): | ||
return (self.args, {'foo':self.foo,}) | ||
* Sample usage | ||
|
||
.. code-block:: python | ||
>>> import jsonrpclib | ||
>>> import test_obj | ||
# History is used only to print the serialized form of beans | ||
>>> history = jsonrpclib.history.History() | ||
>>> testobj1 = test_obj.TestObj() | ||
>>> testobj2 = test_obj.TestSerial() | ||
>>> server = jsonrpclib.Server('http://localhost:8080', history=history) | ||
# The 'ping' just returns whatever is sent | ||
>>> ping1 = server.ping(testobj1) | ||
>>> ping2 = server.ping(testobj2) | ||
>>> print(history.request) | ||
{"id": "7805f1f9-9abd-49c6-81dc-dbd47229fe13", "jsonrpc": "2.0", | ||
"method": "ping", "params": [{"__jsonclass__": | ||
["test_obj.TestSerial", []], "foo": "bar"} | ||
]} | ||
>>> print(history.response) | ||
{"id": "7805f1f9-9abd-49c6-81dc-dbd47229fe13", "jsonrpc": "2.0", | ||
"result": {"__jsonclass__": ["test_obj.TestSerial", []], "foo": "bar"}} | ||
This behavior is turned by default. To deactivate it, just set the | ||
``use_jsonclass`` member of a server ``Config`` to False. | ||
If you want to use a per-class serialization method, set its name in the | ||
``serialize_method`` member of a server ``Config``. | ||
Finally, if you are using classes that you have defined in the implementation | ||
(as in, not a separate library), you'll need to add those (on BOTH the server | ||
and the client) using the ``config.classes.add()`` method. | ||
|
||
Feedback on this "feature" is very, VERY much appreciated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
.. _client: | ||
|
||
JSON-RPC Client usage | ||
********************* | ||
|
||
This is (obviously) taken from a console session. | ||
|
||
.. code-block:: python | ||
>>> import jsonrpclib | ||
>>> server = jsonrpclib.ServerProxy('http://localhost:8080') | ||
>>> server.add(5,6) | ||
11 | ||
>>> server.add(x=5, y=10) | ||
15 | ||
>>> server._notify.add(5,6) | ||
# No result returned... | ||
>>> batch = jsonrpclib.MultiCall(server) | ||
>>> batch.add(5, 6) | ||
>>> batch.ping({'key':'value'}) | ||
>>> batch._notify.add(4, 30) | ||
>>> results = batch() | ||
>>> for result in results: | ||
>>> ... print(result) | ||
11 | ||
{'key': 'value'} | ||
# Note that there are only two responses -- this is according to spec. | ||
# Clean up | ||
>>> server('close')() | ||
# Using client history | ||
>>> history = jsonrpclib.history.History() | ||
>>> server = jsonrpclib.ServerProxy('http://localhost:8080', history=history) | ||
>>> server.add(5,6) | ||
11 | ||
>>> print(history.request) | ||
{"id": "f682b956-c8e1-4506-9db4-29fe8bc9fcaa", "jsonrpc": "2.0", | ||
"method": "add", "params": [5, 6]} | ||
>>> print(history.response) | ||
{"id": "f682b956-c8e1-4506-9db4-29fe8bc9fcaa", "jsonrpc": "2.0", | ||
"result": 11} | ||
# Clean up | ||
>>> server('close')() | ||
If you need 1.0 functionality, there are a bunch of places you can pass that in, | ||
although the best is just to give a specific configuration to | ||
``jsonrpclib.ServerProxy``: | ||
|
||
.. code-block:: python | ||
>>> import jsonrpclib | ||
>>> jsonrpclib.config.DEFAULT.version | ||
2.0 | ||
>>> config = jsonrpclib.config.Config(version=1.0) | ||
>>> history = jsonrpclib.history.History() | ||
>>> server = jsonrpclib.ServerProxy('http://localhost:8080', config=config, | ||
history=history) | ||
>>> server.add(7, 10) | ||
17 | ||
>>> print(history.request) | ||
{"id": "827b2923-5b37-49a5-8b36-e73920a16d32", | ||
"method": "add", "params": [7, 10]} | ||
>>> print(history.response) | ||
{"id": "827b2923-5b37-49a5-8b36-e73920a16d32", "error": null, "result": 17} | ||
>>> server('close')() | ||
The equivalent ``loads`` and ``dumps`` functions also exist, although with minor | ||
modifications. The ``dumps`` arguments are almost identical, but it adds three | ||
arguments: ``rpcid`` for the 'id' key, ``version`` to specify the JSON-RPC | ||
compatibility, and ``notify`` if it's a request that you want to be a | ||
notification. | ||
|
||
Additionally, the ``loads`` method does not return the params and method like | ||
``xmlrpclib``, but instead a.) parses for errors, raising ProtocolErrors, and | ||
b.) returns the entire structure of the request / response for manual parsing. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Configuration file for the Sphinx documentation builder. | ||
# | ||
# This file does only contain a selection of the most common options. For a | ||
# full list see the documentation: | ||
# http://www.sphinx-doc.org/en/master/config | ||
|
||
# -- Path setup -------------------------------------------------------------- | ||
|
||
# If extensions (or modules to document with autodoc) are in another directory, | ||
# add these directories to sys.path here. If the directory is relative to the | ||
# documentation root, use os.path.abspath to make it absolute, like shown here. | ||
# | ||
# import os | ||
# import sys | ||
# sys.path.insert(0, os.path.abspath('.')) | ||
|
||
|
||
# -- Project information ----------------------------------------------------- | ||
|
||
project = 'jsonrpclib-pelix' | ||
copyright = '2018, Thomas Calmant' | ||
author = 'Thomas Calmant' | ||
|
||
# The short X.Y version | ||
version = '0.3.2' | ||
# The full version, including alpha/beta/rc tags | ||
release = '0.3.2' | ||
|
||
|
||
# -- General configuration --------------------------------------------------- | ||
|
||
# If your documentation needs a minimal Sphinx version, state it here. | ||
# | ||
# needs_sphinx = '1.0' | ||
|
||
# Add any Sphinx extension module names here, as strings. They can be | ||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom | ||
# ones. | ||
extensions = [ | ||
'sphinx.ext.autodoc', | ||
] | ||
|
||
# Add any paths that contain templates here, relative to this directory. | ||
templates_path = ['_templates'] | ||
|
||
# The suffix(es) of source filenames. | ||
# You can specify multiple suffix as a list of string: | ||
# | ||
# source_suffix = ['.rst', '.md'] | ||
source_suffix = '.rst' | ||
|
||
# The master toctree document. | ||
master_doc = 'index' | ||
|
||
# The language for content autogenerated by Sphinx. Refer to documentation | ||
# for a list of supported languages. | ||
# | ||
# This is also used if you do content translation via gettext catalogs. | ||
# Usually you set "language" from the command line for these cases. | ||
language = None | ||
|
||
# List of patterns, relative to source directory, that match files and | ||
# directories to ignore when looking for source files. | ||
# This pattern also affects html_static_path and html_extra_path. | ||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] | ||
|
||
# The name of the Pygments (syntax highlighting) style to use. | ||
pygments_style = None | ||
|
||
|
||
# -- Options for HTML output ------------------------------------------------- | ||
|
||
# The theme to use for HTML and HTML Help pages. See the documentation for | ||
# a list of builtin themes. | ||
# | ||
html_theme = 'sphinx_rtd_theme' | ||
|
||
# Theme options are theme-specific and customize the look and feel of a theme | ||
# further. For a list of options available for each theme, see the | ||
# documentation. | ||
# | ||
# html_theme_options = {} | ||
|
||
# Add any paths that contain custom static files (such as style sheets) here, | ||
# relative to this directory. They are copied after the builtin static files, | ||
# so a file named "default.css" will overwrite the builtin "default.css". | ||
html_static_path = ['_static'] | ||
|
||
# Custom sidebar templates, must be a dictionary that maps document names | ||
# to template names. | ||
# | ||
# The default sidebars (for documents that don't match any pattern) are | ||
# defined by theme itself. Builtin themes are using these templates by | ||
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', | ||
# 'searchbox.html']``. | ||
# | ||
# html_sidebars = {} | ||
|
||
|
||
# -- Options for HTMLHelp output --------------------------------------------- | ||
|
||
# Output file base name for HTML help builder. | ||
htmlhelp_basename = 'jsonrpclib-pelixdoc' | ||
|
||
|
||
# -- Options for LaTeX output ------------------------------------------------ | ||
|
||
latex_elements = { | ||
# The paper size ('letterpaper' or 'a4paper'). | ||
# | ||
# 'papersize': 'letterpaper', | ||
|
||
# The font size ('10pt', '11pt' or '12pt'). | ||
# | ||
# 'pointsize': '10pt', | ||
|
||
# Additional stuff for the LaTeX preamble. | ||
# | ||
# 'preamble': '', | ||
|
||
# Latex figure (float) alignment | ||
# | ||
# 'figure_align': 'htbp', | ||
} | ||
|
||
# Grouping the document tree into LaTeX files. List of tuples | ||
# (source start file, target name, title, | ||
# author, documentclass [howto, manual, or own class]). | ||
latex_documents = [ | ||
(master_doc, 'jsonrpclib-pelix.tex', 'jsonrpclib-pelix Documentation', | ||
'Thomas Calmant', 'manual'), | ||
] | ||
|
||
|
||
# -- Options for manual page output ------------------------------------------ | ||
|
||
# One entry per manual page. List of tuples | ||
# (source start file, name, description, authors, manual section). | ||
man_pages = [ | ||
(master_doc, 'jsonrpclib-pelix', 'jsonrpclib-pelix Documentation', | ||
[author], 1) | ||
] | ||
|
||
|
||
# -- Options for Texinfo output ---------------------------------------------- | ||
|
||
# Grouping the document tree into Texinfo files. List of tuples | ||
# (source start file, target name, title, author, | ||
# dir menu entry, description, category) | ||
texinfo_documents = [ | ||
(master_doc, 'jsonrpclib-pelix', 'jsonrpclib-pelix Documentation', | ||
author, 'jsonrpclib-pelix', 'One line description of project.', | ||
'Miscellaneous'), | ||
] | ||
|
||
|
||
# -- Options for Epub output ------------------------------------------------- | ||
|
||
# Bibliographic Dublin Core info. | ||
epub_title = project | ||
|
||
# The unique identifier of the text. This can be a ISBN number | ||
# or the project homepage. | ||
# | ||
# epub_identifier = '' | ||
|
||
# A unique identification for the text. | ||
# | ||
# epub_uid = '' | ||
|
||
# A list of files that should not be packed into the epub file. | ||
epub_exclude_files = ['search.html'] | ||
|
||
|
||
# -- Extension configuration ------------------------------------------------- |
Oops, something went wrong.