Skip to content

Commit dbdbd10

Browse files
committed
First version of a documentation site
1 parent 30819c1 commit dbdbd10

File tree

10 files changed

+687
-0
lines changed

10 files changed

+687
-0
lines changed

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_build/

docs/Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line.
5+
SPHINXOPTS =
6+
SPHINXBUILD = sphinx-build
7+
SOURCEDIR = .
8+
BUILDDIR = _build
9+
10+
# Put it first so that "make" without argument is like "make help".
11+
help:
12+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
13+
14+
.PHONY: help Makefile
15+
16+
# Catch-all target: route all unknown targets to Sphinx using the new
17+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
18+
%: Makefile
19+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/class_translation.rst

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
.. _class_translation:
2+
3+
Class Translation
4+
*****************
5+
6+
I've recently added "automatic" class translation support, although it is
7+
turned off by default. This can be devastatingly slow if improperly used, so
8+
the following is just a short list of things to keep in mind when using it.
9+
10+
* Keep It (the object) Simple Stupid. (for exceptions, keep reading.)
11+
* Do not require init params (for exceptions, keep reading)
12+
* Getter properties without setters could be dangerous (read: not tested)
13+
14+
If any of the above are issues, use the _serialize method. (see usage below)
15+
The server and client must BOTH have use_jsonclass configuration item on and
16+
they must both have access to the same libraries used by the objects for
17+
this to work.
18+
19+
If you have excessively nested arguments, it would be better to turn off the
20+
translation and manually invoke it on specific objects using
21+
``jsonrpclib.jsonclass.dump`` / ``jsonrpclib.jsonclass.load`` (since the default
22+
behavior recursively goes through attributes and lists / dicts / tuples).
23+
24+
Sample file: *test_obj.py*
25+
26+
.. code-block:: python
27+
28+
# This object is /very/ simple, and the system will look through the
29+
# attributes and serialize what it can.
30+
class TestObj(object):
31+
foo = 'bar'
32+
33+
# This object requires __init__ params, so it uses the _serialize method
34+
# and returns a tuple of init params and attribute values (the init params
35+
# can be a dict or a list, but the attribute values must be a dict.)
36+
class TestSerial(object):
37+
foo = 'bar'
38+
def __init__(self, *args):
39+
self.args = args
40+
def _serialize(self):
41+
return (self.args, {'foo':self.foo,})
42+
43+
* Sample usage
44+
45+
.. code-block:: python
46+
47+
>>> import jsonrpclib
48+
>>> import test_obj
49+
50+
# History is used only to print the serialized form of beans
51+
>>> history = jsonrpclib.history.History()
52+
>>> testobj1 = test_obj.TestObj()
53+
>>> testobj2 = test_obj.TestSerial()
54+
>>> server = jsonrpclib.Server('http://localhost:8080', history=history)
55+
56+
# The 'ping' just returns whatever is sent
57+
>>> ping1 = server.ping(testobj1)
58+
>>> ping2 = server.ping(testobj2)
59+
60+
>>> print(history.request)
61+
{"id": "7805f1f9-9abd-49c6-81dc-dbd47229fe13", "jsonrpc": "2.0",
62+
"method": "ping", "params": [{"__jsonclass__":
63+
["test_obj.TestSerial", []], "foo": "bar"}
64+
]}
65+
>>> print(history.response)
66+
{"id": "7805f1f9-9abd-49c6-81dc-dbd47229fe13", "jsonrpc": "2.0",
67+
"result": {"__jsonclass__": ["test_obj.TestSerial", []], "foo": "bar"}}
68+
69+
This behavior is turned by default. To deactivate it, just set the
70+
``use_jsonclass`` member of a server ``Config`` to False.
71+
If you want to use a per-class serialization method, set its name in the
72+
``serialize_method`` member of a server ``Config``.
73+
Finally, if you are using classes that you have defined in the implementation
74+
(as in, not a separate library), you'll need to add those (on BOTH the server
75+
and the client) using the ``config.classes.add()`` method.
76+
77+
Feedback on this "feature" is very, VERY much appreciated.

docs/client.rst

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
.. _client:
2+
3+
JSON-RPC Client usage
4+
*********************
5+
6+
This is (obviously) taken from a console session.
7+
8+
.. code-block:: python
9+
10+
>>> import jsonrpclib
11+
>>> server = jsonrpclib.ServerProxy('http://localhost:8080')
12+
>>> server.add(5,6)
13+
11
14+
>>> server.add(x=5, y=10)
15+
15
16+
>>> server._notify.add(5,6)
17+
# No result returned...
18+
>>> batch = jsonrpclib.MultiCall(server)
19+
>>> batch.add(5, 6)
20+
>>> batch.ping({'key':'value'})
21+
>>> batch._notify.add(4, 30)
22+
>>> results = batch()
23+
>>> for result in results:
24+
>>> ... print(result)
25+
11
26+
{'key': 'value'}
27+
# Note that there are only two responses -- this is according to spec.
28+
29+
# Clean up
30+
>>> server('close')()
31+
32+
# Using client history
33+
>>> history = jsonrpclib.history.History()
34+
>>> server = jsonrpclib.ServerProxy('http://localhost:8080', history=history)
35+
>>> server.add(5,6)
36+
11
37+
>>> print(history.request)
38+
{"id": "f682b956-c8e1-4506-9db4-29fe8bc9fcaa", "jsonrpc": "2.0",
39+
"method": "add", "params": [5, 6]}
40+
>>> print(history.response)
41+
{"id": "f682b956-c8e1-4506-9db4-29fe8bc9fcaa", "jsonrpc": "2.0",
42+
"result": 11}
43+
44+
# Clean up
45+
>>> server('close')()
46+
47+
If you need 1.0 functionality, there are a bunch of places you can pass that in,
48+
although the best is just to give a specific configuration to
49+
``jsonrpclib.ServerProxy``:
50+
51+
.. code-block:: python
52+
53+
>>> import jsonrpclib
54+
>>> jsonrpclib.config.DEFAULT.version
55+
2.0
56+
>>> config = jsonrpclib.config.Config(version=1.0)
57+
>>> history = jsonrpclib.history.History()
58+
>>> server = jsonrpclib.ServerProxy('http://localhost:8080', config=config,
59+
history=history)
60+
>>> server.add(7, 10)
61+
17
62+
>>> print(history.request)
63+
{"id": "827b2923-5b37-49a5-8b36-e73920a16d32",
64+
"method": "add", "params": [7, 10]}
65+
>>> print(history.response)
66+
{"id": "827b2923-5b37-49a5-8b36-e73920a16d32", "error": null, "result": 17}
67+
>>> server('close')()
68+
69+
The equivalent ``loads`` and ``dumps`` functions also exist, although with minor
70+
modifications. The ``dumps`` arguments are almost identical, but it adds three
71+
arguments: ``rpcid`` for the 'id' key, ``version`` to specify the JSON-RPC
72+
compatibility, and ``notify`` if it's a request that you want to be a
73+
notification.
74+
75+
Additionally, the ``loads`` method does not return the params and method like
76+
``xmlrpclib``, but instead a.) parses for errors, raising ProtocolErrors, and
77+
b.) returns the entire structure of the request / response for manual parsing.
78+

docs/conf.py

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Configuration file for the Sphinx documentation builder.
4+
#
5+
# This file does only contain a selection of the most common options. For a
6+
# full list see the documentation:
7+
# http://www.sphinx-doc.org/en/master/config
8+
9+
# -- Path setup --------------------------------------------------------------
10+
11+
# If extensions (or modules to document with autodoc) are in another directory,
12+
# add these directories to sys.path here. If the directory is relative to the
13+
# documentation root, use os.path.abspath to make it absolute, like shown here.
14+
#
15+
# import os
16+
# import sys
17+
# sys.path.insert(0, os.path.abspath('.'))
18+
19+
20+
# -- Project information -----------------------------------------------------
21+
22+
project = 'jsonrpclib-pelix'
23+
copyright = '2018, Thomas Calmant'
24+
author = 'Thomas Calmant'
25+
26+
# The short X.Y version
27+
version = '0.3.2'
28+
# The full version, including alpha/beta/rc tags
29+
release = '0.3.2'
30+
31+
32+
# -- General configuration ---------------------------------------------------
33+
34+
# If your documentation needs a minimal Sphinx version, state it here.
35+
#
36+
# needs_sphinx = '1.0'
37+
38+
# Add any Sphinx extension module names here, as strings. They can be
39+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
40+
# ones.
41+
extensions = [
42+
'sphinx.ext.autodoc',
43+
]
44+
45+
# Add any paths that contain templates here, relative to this directory.
46+
templates_path = ['_templates']
47+
48+
# The suffix(es) of source filenames.
49+
# You can specify multiple suffix as a list of string:
50+
#
51+
# source_suffix = ['.rst', '.md']
52+
source_suffix = '.rst'
53+
54+
# The master toctree document.
55+
master_doc = 'index'
56+
57+
# The language for content autogenerated by Sphinx. Refer to documentation
58+
# for a list of supported languages.
59+
#
60+
# This is also used if you do content translation via gettext catalogs.
61+
# Usually you set "language" from the command line for these cases.
62+
language = None
63+
64+
# List of patterns, relative to source directory, that match files and
65+
# directories to ignore when looking for source files.
66+
# This pattern also affects html_static_path and html_extra_path.
67+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
68+
69+
# The name of the Pygments (syntax highlighting) style to use.
70+
pygments_style = None
71+
72+
73+
# -- Options for HTML output -------------------------------------------------
74+
75+
# The theme to use for HTML and HTML Help pages. See the documentation for
76+
# a list of builtin themes.
77+
#
78+
html_theme = 'sphinx_rtd_theme'
79+
80+
# Theme options are theme-specific and customize the look and feel of a theme
81+
# further. For a list of options available for each theme, see the
82+
# documentation.
83+
#
84+
# html_theme_options = {}
85+
86+
# Add any paths that contain custom static files (such as style sheets) here,
87+
# relative to this directory. They are copied after the builtin static files,
88+
# so a file named "default.css" will overwrite the builtin "default.css".
89+
html_static_path = ['_static']
90+
91+
# Custom sidebar templates, must be a dictionary that maps document names
92+
# to template names.
93+
#
94+
# The default sidebars (for documents that don't match any pattern) are
95+
# defined by theme itself. Builtin themes are using these templates by
96+
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
97+
# 'searchbox.html']``.
98+
#
99+
# html_sidebars = {}
100+
101+
102+
# -- Options for HTMLHelp output ---------------------------------------------
103+
104+
# Output file base name for HTML help builder.
105+
htmlhelp_basename = 'jsonrpclib-pelixdoc'
106+
107+
108+
# -- Options for LaTeX output ------------------------------------------------
109+
110+
latex_elements = {
111+
# The paper size ('letterpaper' or 'a4paper').
112+
#
113+
# 'papersize': 'letterpaper',
114+
115+
# The font size ('10pt', '11pt' or '12pt').
116+
#
117+
# 'pointsize': '10pt',
118+
119+
# Additional stuff for the LaTeX preamble.
120+
#
121+
# 'preamble': '',
122+
123+
# Latex figure (float) alignment
124+
#
125+
# 'figure_align': 'htbp',
126+
}
127+
128+
# Grouping the document tree into LaTeX files. List of tuples
129+
# (source start file, target name, title,
130+
# author, documentclass [howto, manual, or own class]).
131+
latex_documents = [
132+
(master_doc, 'jsonrpclib-pelix.tex', 'jsonrpclib-pelix Documentation',
133+
'Thomas Calmant', 'manual'),
134+
]
135+
136+
137+
# -- Options for manual page output ------------------------------------------
138+
139+
# One entry per manual page. List of tuples
140+
# (source start file, name, description, authors, manual section).
141+
man_pages = [
142+
(master_doc, 'jsonrpclib-pelix', 'jsonrpclib-pelix Documentation',
143+
[author], 1)
144+
]
145+
146+
147+
# -- Options for Texinfo output ----------------------------------------------
148+
149+
# Grouping the document tree into Texinfo files. List of tuples
150+
# (source start file, target name, title, author,
151+
# dir menu entry, description, category)
152+
texinfo_documents = [
153+
(master_doc, 'jsonrpclib-pelix', 'jsonrpclib-pelix Documentation',
154+
author, 'jsonrpclib-pelix', 'One line description of project.',
155+
'Miscellaneous'),
156+
]
157+
158+
159+
# -- Options for Epub output -------------------------------------------------
160+
161+
# Bibliographic Dublin Core info.
162+
epub_title = project
163+
164+
# The unique identifier of the text. This can be a ISBN number
165+
# or the project homepage.
166+
#
167+
# epub_identifier = ''
168+
169+
# A unique identification for the text.
170+
#
171+
# epub_uid = ''
172+
173+
# A list of files that should not be packed into the epub file.
174+
epub_exclude_files = ['search.html']
175+
176+
177+
# -- Extension configuration -------------------------------------------------

0 commit comments

Comments
 (0)