Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-updates > by-pkgid > e1011ddec34cda34f3a002b121247943 > files > 915

python-docs-2.7.17-1.1.mga7.noarch.rpm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
    <title>20.24. SimpleXMLRPCServer — Basic XML-RPC server &#8212; Python 2.7.17 documentation</title>
    <link rel="stylesheet" href="../_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python 2.7.17 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="next" title="20.25. DocXMLRPCServer — Self-documenting XML-RPC server" href="docxmlrpcserver.html" />
    <link rel="prev" title="20.23. xmlrpclib — XML-RPC client access" href="xmlrpclib.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/2/library/simplexmlrpcserver.html" />
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
 
    

  </head><body>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="docxmlrpcserver.html" title="20.25. DocXMLRPCServer — Self-documenting XML-RPC server"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="xmlrpclib.html" title="20.23. xmlrpclib — XML-RPC client access"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">Python 2.7.17 documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="internet.html" accesskey="U">20. Internet Protocols and Support</a> &#187;</li> 
      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="module-SimpleXMLRPCServer">
<span id="simplexmlrpcserver-basic-xml-rpc-server"></span><h1>20.24. <a class="reference internal" href="#module-SimpleXMLRPCServer" title="SimpleXMLRPCServer: Basic XML-RPC server implementation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">SimpleXMLRPCServer</span></code></a> — Basic XML-RPC server<a class="headerlink" href="#module-SimpleXMLRPCServer" title="Permalink to this headline">¶</a></h1>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The <a class="reference internal" href="#module-SimpleXMLRPCServer" title="SimpleXMLRPCServer: Basic XML-RPC server implementation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">SimpleXMLRPCServer</span></code></a> module has been merged into
<code class="xref py py-mod docutils literal notranslate"><span class="pre">xmlrpc.server</span></code> in Python 3.  The <a class="reference internal" href="../glossary.html#term-2to3"><span class="xref std std-term">2to3</span></a> tool will automatically
adapt imports when converting your sources to Python 3.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified added">New in version 2.2.</span></p>
</div>
<p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/2.7/Lib/SimpleXMLRPCServer.py">Lib/SimpleXMLRPCServer.py</a></p>
<hr class="docutils" />
<p>The <a class="reference internal" href="#module-SimpleXMLRPCServer" title="SimpleXMLRPCServer: Basic XML-RPC server implementation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">SimpleXMLRPCServer</span></code></a> module provides a basic server framework for
XML-RPC servers written in Python.  Servers can either be free standing, using
<a class="reference internal" href="#SimpleXMLRPCServer.SimpleXMLRPCServer" title="SimpleXMLRPCServer.SimpleXMLRPCServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleXMLRPCServer</span></code></a>, or embedded in a CGI environment, using
<a class="reference internal" href="#SimpleXMLRPCServer.CGIXMLRPCRequestHandler" title="SimpleXMLRPCServer.CGIXMLRPCRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CGIXMLRPCRequestHandler</span></code></a>.</p>
<dl class="class">
<dt id="SimpleXMLRPCServer.SimpleXMLRPCServer">
<em class="property">class </em><code class="descclassname">SimpleXMLRPCServer.</code><code class="descname">SimpleXMLRPCServer</code><span class="sig-paren">(</span><em>addr[, requestHandler[, logRequests[, allow_none[, encoding[, bind_and_activate]]]]</em><span class="sig-paren">)</span><a class="headerlink" href="#SimpleXMLRPCServer.SimpleXMLRPCServer" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a new server instance.  This class provides methods for registration of
functions that can be called by the XML-RPC protocol.  The <em>requestHandler</em>
parameter should be a factory for request handler instances; it defaults to
<a class="reference internal" href="#SimpleXMLRPCServer.SimpleXMLRPCRequestHandler" title="SimpleXMLRPCServer.SimpleXMLRPCRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleXMLRPCRequestHandler</span></code></a>.  The <em>addr</em> and <em>requestHandler</em> parameters
are passed to the <a class="reference internal" href="socketserver.html#SocketServer.TCPServer" title="SocketServer.TCPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">SocketServer.TCPServer</span></code></a> constructor.  If <em>logRequests</em>
is true (the default), requests will be logged; setting this parameter to false
will turn off logging.   The <em>allow_none</em> and <em>encoding</em> parameters are passed
on to  <a class="reference internal" href="xmlrpclib.html#module-xmlrpclib" title="xmlrpclib: XML-RPC client access."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xmlrpclib</span></code></a> and control the XML-RPC responses that will be returned
from the server. The <em>bind_and_activate</em> parameter controls whether
<code class="xref py py-meth docutils literal notranslate"><span class="pre">server_bind()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">server_activate()</span></code> are called immediately by the
constructor; it defaults to true. Setting it to false allows code to manipulate
the <em>allow_reuse_address</em> class variable before the address is bound.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 2.5: </span>The <em>allow_none</em> and <em>encoding</em> parameters were added.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 2.6: </span>The <em>bind_and_activate</em> parameter was added.</p>
</div>
</dd></dl>

<dl class="class">
<dt id="SimpleXMLRPCServer.CGIXMLRPCRequestHandler">
<em class="property">class </em><code class="descclassname">SimpleXMLRPCServer.</code><code class="descname">CGIXMLRPCRequestHandler</code><span class="sig-paren">(</span><span class="optional">[</span><em>allow_none</em><span class="optional">[</span>, <em>encoding</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#SimpleXMLRPCServer.CGIXMLRPCRequestHandler" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a new instance to handle XML-RPC requests in a CGI environment.  The
<em>allow_none</em> and <em>encoding</em> parameters are passed on to  <a class="reference internal" href="xmlrpclib.html#module-xmlrpclib" title="xmlrpclib: XML-RPC client access."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xmlrpclib</span></code></a> and
control the XML-RPC responses that will be returned  from the server.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in version 2.3.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 2.5: </span>The <em>allow_none</em> and <em>encoding</em> parameters were added.</p>
</div>
</dd></dl>

<dl class="class">
<dt id="SimpleXMLRPCServer.SimpleXMLRPCRequestHandler">
<em class="property">class </em><code class="descclassname">SimpleXMLRPCServer.</code><code class="descname">SimpleXMLRPCRequestHandler</code><a class="headerlink" href="#SimpleXMLRPCServer.SimpleXMLRPCRequestHandler" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a new request handler instance.  This request handler supports <code class="docutils literal notranslate"><span class="pre">POST</span></code>
requests and modifies logging so that the <em>logRequests</em> parameter to the
<a class="reference internal" href="#SimpleXMLRPCServer.SimpleXMLRPCServer" title="SimpleXMLRPCServer.SimpleXMLRPCServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleXMLRPCServer</span></code></a> constructor parameter is honored.</p>
</dd></dl>

<div class="section" id="simplexmlrpcserver-objects">
<span id="simple-xmlrpc-servers"></span><h2>20.24.1. SimpleXMLRPCServer Objects<a class="headerlink" href="#simplexmlrpcserver-objects" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference internal" href="#SimpleXMLRPCServer.SimpleXMLRPCServer" title="SimpleXMLRPCServer.SimpleXMLRPCServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleXMLRPCServer</span></code></a> class is based on
<a class="reference internal" href="socketserver.html#SocketServer.TCPServer" title="SocketServer.TCPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">SocketServer.TCPServer</span></code></a> and provides a means of creating simple, stand
alone XML-RPC servers.</p>
<dl class="method">
<dt id="SimpleXMLRPCServer.SimpleXMLRPCServer.register_function">
<code class="descclassname">SimpleXMLRPCServer.</code><code class="descname">register_function</code><span class="sig-paren">(</span><em>function</em><span class="optional">[</span>, <em>name</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#SimpleXMLRPCServer.SimpleXMLRPCServer.register_function" title="Permalink to this definition">¶</a></dt>
<dd><p>Register a function that can respond to XML-RPC requests.  If <em>name</em> is given,
it will be the method name associated with <em>function</em>, otherwise
<code class="docutils literal notranslate"><span class="pre">function.__name__</span></code> will be used.  <em>name</em> can be either a normal or Unicode
string, and may contain characters not legal in Python identifiers, including
the period character.</p>
</dd></dl>

<dl class="method">
<dt id="SimpleXMLRPCServer.SimpleXMLRPCServer.register_instance">
<code class="descclassname">SimpleXMLRPCServer.</code><code class="descname">register_instance</code><span class="sig-paren">(</span><em>instance</em><span class="optional">[</span>, <em>allow_dotted_names</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#SimpleXMLRPCServer.SimpleXMLRPCServer.register_instance" title="Permalink to this definition">¶</a></dt>
<dd><p>Register an object which is used to expose method names which have not been
registered using <a class="reference internal" href="#SimpleXMLRPCServer.SimpleXMLRPCServer.register_function" title="SimpleXMLRPCServer.SimpleXMLRPCServer.register_function"><code class="xref py py-meth docutils literal notranslate"><span class="pre">register_function()</span></code></a>.  If <em>instance</em> contains a
<code class="xref py py-meth docutils literal notranslate"><span class="pre">_dispatch()</span></code> method, it is called with the requested method name and the
parameters from the request.  Its API is <code class="docutils literal notranslate"><span class="pre">def</span> <span class="pre">_dispatch(self,</span> <span class="pre">method,</span> <span class="pre">params)</span></code>
(note that <em>params</em> does not represent a variable argument list).  If it calls
an underlying function to perform its task, that function is called as
<code class="docutils literal notranslate"><span class="pre">func(*params)</span></code>, expanding the parameter list. The return value from
<code class="xref py py-meth docutils literal notranslate"><span class="pre">_dispatch()</span></code> is returned to the client as the result.  If <em>instance</em> does
not have a <code class="xref py py-meth docutils literal notranslate"><span class="pre">_dispatch()</span></code> method, it is searched for an attribute matching
the name of the requested method.</p>
<p>If the optional <em>allow_dotted_names</em> argument is true and the instance does not
have a <code class="xref py py-meth docutils literal notranslate"><span class="pre">_dispatch()</span></code> method, then if the requested method name contains
periods, each component of the method name is searched for individually, with
the effect that a simple hierarchical search is performed.  The value found from
this search is then called with the parameters from the request, and the return
value is passed back to the client.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Enabling the <em>allow_dotted_names</em> option allows intruders to access your
module’s global variables and may allow intruders to execute arbitrary code on
your machine.  Only use this option on a secure, closed network.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 2.3.5,: </span>2.4.1
<em>allow_dotted_names</em> was added to plug a security hole; prior versions are
insecure.</p>
</div>
</dd></dl>

<dl class="method">
<dt id="SimpleXMLRPCServer.SimpleXMLRPCServer.register_introspection_functions">
<code class="descclassname">SimpleXMLRPCServer.</code><code class="descname">register_introspection_functions</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#SimpleXMLRPCServer.SimpleXMLRPCServer.register_introspection_functions" title="Permalink to this definition">¶</a></dt>
<dd><p>Registers the XML-RPC introspection functions <code class="docutils literal notranslate"><span class="pre">system.listMethods</span></code>,
<code class="docutils literal notranslate"><span class="pre">system.methodHelp</span></code> and <code class="docutils literal notranslate"><span class="pre">system.methodSignature</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in version 2.3.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="SimpleXMLRPCServer.SimpleXMLRPCServer.register_multicall_functions">
<code class="descclassname">SimpleXMLRPCServer.</code><code class="descname">register_multicall_functions</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#SimpleXMLRPCServer.SimpleXMLRPCServer.register_multicall_functions" title="Permalink to this definition">¶</a></dt>
<dd><p>Registers the XML-RPC multicall function system.multicall.</p>
</dd></dl>

<dl class="attribute">
<dt id="SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.rpc_paths">
<code class="descclassname">SimpleXMLRPCRequestHandler.</code><code class="descname">rpc_paths</code><a class="headerlink" href="#SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.rpc_paths" title="Permalink to this definition">¶</a></dt>
<dd><p>An attribute value that must be a tuple listing valid path portions of the URL
for receiving XML-RPC requests.  Requests posted to other paths will result in a
404 “no such page” HTTP error.  If this tuple is empty, all paths will be
considered valid. The default value is <code class="docutils literal notranslate"><span class="pre">('/',</span> <span class="pre">'/RPC2')</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in version 2.5.</span></p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.encode_threshold">
<code class="descclassname">SimpleXMLRPCRequestHandler.</code><code class="descname">encode_threshold</code><a class="headerlink" href="#SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.encode_threshold" title="Permalink to this definition">¶</a></dt>
<dd><p>If this attribute is not <code class="docutils literal notranslate"><span class="pre">None</span></code>, responses larger than this value
will be encoded using the <em>gzip</em> transfer encoding, if permitted by
the client.  The default is <code class="docutils literal notranslate"><span class="pre">1400</span></code> which corresponds roughly
to a single TCP packet.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in version 2.7.</span></p>
</div>
</dd></dl>

<div class="section" id="simplexmlrpcserver-example">
<span id="id1"></span><h3>20.24.1.1. SimpleXMLRPCServer Example<a class="headerlink" href="#simplexmlrpcserver-example" title="Permalink to this headline">¶</a></h3>
<p>Server code:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">SimpleXMLRPCServer</span> <span class="k">import</span> <span class="n">SimpleXMLRPCServer</span>
<span class="kn">from</span> <span class="nn">SimpleXMLRPCServer</span> <span class="k">import</span> <span class="n">SimpleXMLRPCRequestHandler</span>

<span class="c1"># Restrict to a particular path.</span>
<span class="k">class</span> <span class="nc">RequestHandler</span><span class="p">(</span><span class="n">SimpleXMLRPCRequestHandler</span><span class="p">):</span>
    <span class="n">rpc_paths</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;/RPC2&#39;</span><span class="p">,)</span>

<span class="c1"># Create server</span>
<span class="n">server</span> <span class="o">=</span> <span class="n">SimpleXMLRPCServer</span><span class="p">((</span><span class="s2">&quot;localhost&quot;</span><span class="p">,</span> <span class="mi">8000</span><span class="p">),</span>
                            <span class="n">requestHandler</span><span class="o">=</span><span class="n">RequestHandler</span><span class="p">)</span>
<span class="n">server</span><span class="o">.</span><span class="n">register_introspection_functions</span><span class="p">()</span>

<span class="c1"># Register pow() function; this will use the value of</span>
<span class="c1"># pow.__name__ as the name, which is just &#39;pow&#39;.</span>
<span class="n">server</span><span class="o">.</span><span class="n">register_function</span><span class="p">(</span><span class="nb">pow</span><span class="p">)</span>

<span class="c1"># Register a function under a different name</span>
<span class="k">def</span> <span class="nf">adder_function</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span>
<span class="n">server</span><span class="o">.</span><span class="n">register_function</span><span class="p">(</span><span class="n">adder_function</span><span class="p">,</span> <span class="s1">&#39;add&#39;</span><span class="p">)</span>

<span class="c1"># Register an instance; all the methods of the instance are</span>
<span class="c1"># published as XML-RPC methods (in this case, just &#39;div&#39;).</span>
<span class="k">class</span> <span class="nc">MyFuncs</span><span class="p">:</span>
    <span class="k">def</span> <span class="nf">div</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">x</span> <span class="o">//</span> <span class="n">y</span>

<span class="n">server</span><span class="o">.</span><span class="n">register_instance</span><span class="p">(</span><span class="n">MyFuncs</span><span class="p">())</span>

<span class="c1"># Run the server&#39;s main loop</span>
<span class="n">server</span><span class="o">.</span><span class="n">serve_forever</span><span class="p">()</span>
</pre></div>
</div>
<p>The following client code will call the methods made available by the preceding
server:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">xmlrpclib</span>

<span class="n">s</span> <span class="o">=</span> <span class="n">xmlrpclib</span><span class="o">.</span><span class="n">ServerProxy</span><span class="p">(</span><span class="s1">&#39;http://localhost:8000&#39;</span><span class="p">)</span>
<span class="nb">print</span> <span class="n">s</span><span class="o">.</span><span class="n">pow</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">)</span>  <span class="c1"># Returns 2**3 = 8</span>
<span class="nb">print</span> <span class="n">s</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">)</span>  <span class="c1"># Returns 5</span>
<span class="nb">print</span> <span class="n">s</span><span class="o">.</span><span class="n">div</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>  <span class="c1"># Returns 5//2 = 2</span>

<span class="c1"># Print list of available methods</span>
<span class="nb">print</span> <span class="n">s</span><span class="o">.</span><span class="n">system</span><span class="o">.</span><span class="n">listMethods</span><span class="p">()</span>
</pre></div>
</div>
<p>The following <a class="reference internal" href="#SimpleXMLRPCServer.SimpleXMLRPCServer" title="SimpleXMLRPCServer.SimpleXMLRPCServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleXMLRPCServer</span></code></a> example is included in the module
<cite>Lib/SimpleXMLRPCServer.py</cite>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">server</span> <span class="o">=</span> <span class="n">SimpleXMLRPCServer</span><span class="p">((</span><span class="s2">&quot;localhost&quot;</span><span class="p">,</span> <span class="mi">8000</span><span class="p">))</span>
<span class="n">server</span><span class="o">.</span><span class="n">register_function</span><span class="p">(</span><span class="nb">pow</span><span class="p">)</span>
<span class="n">server</span><span class="o">.</span><span class="n">register_function</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">:</span> <span class="n">x</span><span class="o">+</span><span class="n">y</span><span class="p">,</span> <span class="s1">&#39;add&#39;</span><span class="p">)</span>
<span class="n">server</span><span class="o">.</span><span class="n">register_multicall_functions</span><span class="p">()</span>
<span class="n">server</span><span class="o">.</span><span class="n">serve_forever</span><span class="p">()</span>
</pre></div>
</div>
<p>This demo server can be run from the command line as:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">SimpleXMLRPCServer</span>
</pre></div>
</div>
<p>Example client code which talks to the above server is included with
<cite>Lib/xmlrpclib.py</cite>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">server</span> <span class="o">=</span> <span class="n">ServerProxy</span><span class="p">(</span><span class="s2">&quot;http://localhost:8000&quot;</span><span class="p">)</span>
<span class="nb">print</span> <span class="n">server</span>
<span class="n">multi</span> <span class="o">=</span> <span class="n">MultiCall</span><span class="p">(</span><span class="n">server</span><span class="p">)</span>
<span class="n">multi</span><span class="o">.</span><span class="n">pow</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">9</span><span class="p">)</span>
<span class="n">multi</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">multi</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="mi">24</span><span class="p">,</span> <span class="mi">11</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
    <span class="k">for</span> <span class="n">response</span> <span class="ow">in</span> <span class="n">multi</span><span class="p">():</span>
        <span class="nb">print</span> <span class="n">response</span>
<span class="k">except</span> <span class="n">Error</span><span class="p">,</span> <span class="n">v</span><span class="p">:</span>
    <span class="nb">print</span> <span class="s2">&quot;ERROR&quot;</span><span class="p">,</span> <span class="n">v</span>
</pre></div>
</div>
<p>And the client can be invoked directly using the following command:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">xmlrpclib</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="cgixmlrpcrequesthandler">
<h2>20.24.2. CGIXMLRPCRequestHandler<a class="headerlink" href="#cgixmlrpcrequesthandler" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference internal" href="#SimpleXMLRPCServer.CGIXMLRPCRequestHandler" title="SimpleXMLRPCServer.CGIXMLRPCRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CGIXMLRPCRequestHandler</span></code></a> class can be used to  handle XML-RPC
requests sent to Python CGI scripts.</p>
<dl class="method">
<dt id="SimpleXMLRPCServer.CGIXMLRPCRequestHandler.register_function">
<code class="descclassname">CGIXMLRPCRequestHandler.</code><code class="descname">register_function</code><span class="sig-paren">(</span><em>function</em><span class="optional">[</span>, <em>name</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#SimpleXMLRPCServer.CGIXMLRPCRequestHandler.register_function" title="Permalink to this definition">¶</a></dt>
<dd><p>Register a function that can respond to XML-RPC requests. If  <em>name</em> is given,
it will be the method name associated with  function, otherwise
<em>function.__name__</em> will be used. <em>name</em> can be either a normal or Unicode
string, and may contain  characters not legal in Python identifiers, including
the period character.</p>
</dd></dl>

<dl class="method">
<dt id="SimpleXMLRPCServer.CGIXMLRPCRequestHandler.register_instance">
<code class="descclassname">CGIXMLRPCRequestHandler.</code><code class="descname">register_instance</code><span class="sig-paren">(</span><em>instance</em><span class="sig-paren">)</span><a class="headerlink" href="#SimpleXMLRPCServer.CGIXMLRPCRequestHandler.register_instance" title="Permalink to this definition">¶</a></dt>
<dd><p>Register an object which is used to expose method names  which have not been
registered using <a class="reference internal" href="#SimpleXMLRPCServer.CGIXMLRPCRequestHandler.register_function" title="SimpleXMLRPCServer.CGIXMLRPCRequestHandler.register_function"><code class="xref py py-meth docutils literal notranslate"><span class="pre">register_function()</span></code></a>. If  instance contains a
<code class="xref py py-meth docutils literal notranslate"><span class="pre">_dispatch()</span></code> method, it is called with the  requested method name and the
parameters from the  request; the return value is returned to the client as the
result. If instance does not have a <code class="xref py py-meth docutils literal notranslate"><span class="pre">_dispatch()</span></code> method, it is searched
for an attribute matching the name of the requested method; if  the requested
method name contains periods, each  component of the method name is searched for
individually,  with the effect that a simple hierarchical search is performed.
The value found from this search is then called with the  parameters from the
request, and the return value is passed  back to the client.</p>
</dd></dl>

<dl class="method">
<dt id="SimpleXMLRPCServer.CGIXMLRPCRequestHandler.register_introspection_functions">
<code class="descclassname">CGIXMLRPCRequestHandler.</code><code class="descname">register_introspection_functions</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#SimpleXMLRPCServer.CGIXMLRPCRequestHandler.register_introspection_functions" title="Permalink to this definition">¶</a></dt>
<dd><p>Register the XML-RPC introspection functions  <code class="docutils literal notranslate"><span class="pre">system.listMethods</span></code>,
<code class="docutils literal notranslate"><span class="pre">system.methodHelp</span></code> and  <code class="docutils literal notranslate"><span class="pre">system.methodSignature</span></code>.</p>
</dd></dl>

<dl class="method">
<dt id="SimpleXMLRPCServer.CGIXMLRPCRequestHandler.register_multicall_functions">
<code class="descclassname">CGIXMLRPCRequestHandler.</code><code class="descname">register_multicall_functions</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#SimpleXMLRPCServer.CGIXMLRPCRequestHandler.register_multicall_functions" title="Permalink to this definition">¶</a></dt>
<dd><p>Register the XML-RPC multicall function <code class="docutils literal notranslate"><span class="pre">system.multicall</span></code>.</p>
</dd></dl>

<dl class="method">
<dt id="SimpleXMLRPCServer.CGIXMLRPCRequestHandler.handle_request">
<code class="descclassname">CGIXMLRPCRequestHandler.</code><code class="descname">handle_request</code><span class="sig-paren">(</span><span class="optional">[</span><em>request_text = None</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#SimpleXMLRPCServer.CGIXMLRPCRequestHandler.handle_request" title="Permalink to this definition">¶</a></dt>
<dd><p>Handle an XML-RPC request. If <em>request_text</em> is given, it should be the POST
data provided by the HTTP server,  otherwise the contents of stdin will be used.</p>
</dd></dl>

<p>Example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyFuncs</span><span class="p">:</span>
    <span class="k">def</span> <span class="nf">div</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">):</span> <span class="k">return</span> <span class="n">x</span> <span class="o">//</span> <span class="n">y</span>


<span class="n">handler</span> <span class="o">=</span> <span class="n">CGIXMLRPCRequestHandler</span><span class="p">()</span>
<span class="n">handler</span><span class="o">.</span><span class="n">register_function</span><span class="p">(</span><span class="nb">pow</span><span class="p">)</span>
<span class="n">handler</span><span class="o">.</span><span class="n">register_function</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">:</span> <span class="n">x</span><span class="o">+</span><span class="n">y</span><span class="p">,</span> <span class="s1">&#39;add&#39;</span><span class="p">)</span>
<span class="n">handler</span><span class="o">.</span><span class="n">register_introspection_functions</span><span class="p">()</span>
<span class="n">handler</span><span class="o">.</span><span class="n">register_instance</span><span class="p">(</span><span class="n">MyFuncs</span><span class="p">())</span>
<span class="n">handler</span><span class="o">.</span><span class="n">handle_request</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">20.24. <code class="xref py py-mod docutils literal notranslate"><span class="pre">SimpleXMLRPCServer</span></code> — Basic XML-RPC server</a><ul>
<li><a class="reference internal" href="#simplexmlrpcserver-objects">20.24.1. SimpleXMLRPCServer Objects</a><ul>
<li><a class="reference internal" href="#simplexmlrpcserver-example">20.24.1.1. SimpleXMLRPCServer Example</a></li>
</ul>
</li>
<li><a class="reference internal" href="#cgixmlrpcrequesthandler">20.24.2. CGIXMLRPCRequestHandler</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="xmlrpclib.html"
                        title="previous chapter">20.23. <code class="xref py py-mod docutils literal notranslate"><span class="pre">xmlrpclib</span></code> — XML-RPC client access</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="docxmlrpcserver.html"
                        title="next chapter">20.25. <code class="xref py py-mod docutils literal notranslate"><span class="pre">DocXMLRPCServer</span></code> — Self-documenting XML-RPC server</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/library/simplexmlrpcserver.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="docxmlrpcserver.html" title="20.25. DocXMLRPCServer — Self-documenting XML-RPC server"
             >next</a> |</li>
        <li class="right" >
          <a href="xmlrpclib.html" title="20.23. xmlrpclib — XML-RPC client access"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">Python 2.7.17 documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="internet.html" >20. Internet Protocols and Support</a> &#187;</li> 
      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2019, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Oct 19, 2019.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.0.1.
    </div>

  </body>
</html>