Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > 762e4b4e451f9de4722602c03fda2c9b > files > 216

python-fedora-0.3.25.1-1.fc14.1.noarch.rpm



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>API Documentation &mdash; python-fedora v0.3.25.1 documentation</title>
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '0.3.25.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </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>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within python-fedora v0.3.25.1 documentation"
          href="_static/opensearch.xml"/>
    <link rel="top" title="python-fedora v0.3.25.1 documentation" href="index.html" />
    <link rel="next" title="Glossary" href="glossary.html" />
    <link rel="prev" title="JavaScript" href="javascript.html" /> 
  </head>
  <body>
    <div class="related">
      <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="glossary.html" title="Glossary"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="javascript.html" title="JavaScript"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">python-fedora v0.3.25.1 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="api-documentation">
<h1>API Documentation<a class="headerlink" href="#api-documentation" title="Permalink to this headline">¶</a></h1>
<p>This API Documentation is currently a catch-all.  We&#8217;re going to merge the API
docs into the hand created docs as we have time to integrate them.</p>
<div class="toctree-wrapper compound">
<ul class="simple">
</ul>
</div>
<div class="section" id="module-fedora.client">
<span id="client"></span><h2>Client<a class="headerlink" href="#module-fedora.client" title="Permalink to this headline">¶</a></h2>
<p>fedora.client is used to interact with Fedora Services.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 0.3.21: </span>Deprecate DictContainer in favor of bunch.Bunch</p>
<p><em>Module author: Ricky Zhou &lt;<a class="reference external" href="mailto:ricky&#37;&#52;&#48;fedoraproject&#46;org">ricky<span>&#64;</span>fedoraproject<span>&#46;</span>org</a>&gt;</em></p>
<p><em>Module author: Luke Macken &lt;<a class="reference external" href="mailto:lmacken&#37;&#52;&#48;redhat&#46;com">lmacken<span>&#64;</span>redhat<span>&#46;</span>com</a>&gt;</em></p>
<p><em>Module author: Toshio Kuratomi &lt;<a class="reference external" href="mailto:tkuratom&#37;&#52;&#48;redhat&#46;com">tkuratom<span>&#64;</span>redhat<span>&#46;</span>com</a>&gt;</em></p>
<dl class="exception">
<dt id="fedora.client.FedoraServiceError">
<em class="property">exception </em><tt class="descclassname">fedora.client.</tt><tt class="descname">FedoraServiceError</tt><a class="headerlink" href="#fedora.client.FedoraServiceError" title="Permalink to this definition">¶</a></dt>
<dd><p>Base Exception for any problem talking with the Service.</p>
<p>When the Client gets an error talking to the server, an exception of this
type is raised.  This can be anything in the networking layer up to an
error returned from the server itself.</p>
</dd></dl>

<dl class="exception">
<dt id="fedora.client.ServerError">
<em class="property">exception </em><tt class="descclassname">fedora.client.</tt><tt class="descname">ServerError</tt><big>(</big><em>url</em>, <em>status</em>, <em>msg</em><big>)</big><a class="headerlink" href="#fedora.client.ServerError" title="Permalink to this definition">¶</a></dt>
<dd><p>Unable to talk to the server properly.</p>
<p>This includes network errors and 500 response codes.</p>
</dd></dl>

<dl class="exception">
<dt id="fedora.client.AuthError">
<em class="property">exception </em><tt class="descclassname">fedora.client.</tt><tt class="descname">AuthError</tt><a class="headerlink" href="#fedora.client.AuthError" title="Permalink to this definition">¶</a></dt>
<dd><p>Error during authentication.  For instance, invalid password.</p>
</dd></dl>

<dl class="exception">
<dt id="fedora.client.AppError">
<em class="property">exception </em><tt class="descclassname">fedora.client.</tt><tt class="descname">AppError</tt><big>(</big><em>name</em>, <em>message</em>, <em>extras=None</em><big>)</big><a class="headerlink" href="#fedora.client.AppError" title="Permalink to this definition">¶</a></dt>
<dd><p>Error condition that the server is passing back to the client.</p>
</dd></dl>

<dl class="exception">
<dt id="fedora.client.FedoraClientError">
<em class="property">exception </em><tt class="descclassname">fedora.client.</tt><tt class="descname">FedoraClientError</tt><a class="headerlink" href="#fedora.client.FedoraClientError" title="Permalink to this definition">¶</a></dt>
<dd><p>Base Exception for problems which originate within the Clients.</p>
<p>This should be the base class for any exceptions that the Client generates
generate.  For instance, if the client performs validation before passing
the data on to the Fedora Service.</p>
<p>Problems returned while talking to the Services should be returned via a
<cite>FedoraServiceError</cite> instead.</p>
</dd></dl>

<dl class="exception">
<dt id="fedora.client.FASError">
<em class="property">exception </em><tt class="descclassname">fedora.client.</tt><tt class="descname">FASError</tt><a class="headerlink" href="#fedora.client.FASError" title="Permalink to this definition">¶</a></dt>
<dd><p>FAS Error</p>
</dd></dl>

<dl class="exception">
<dt id="fedora.client.CLAError">
<em class="property">exception </em><tt class="descclassname">fedora.client.</tt><tt class="descname">CLAError</tt><a class="headerlink" href="#fedora.client.CLAError" title="Permalink to this definition">¶</a></dt>
<dd><p>CLA Error</p>
</dd></dl>

<dl class="exception">
<dt id="fedora.client.PackageDBError">
<em class="property">exception </em><tt class="descclassname">fedora.client.</tt><tt class="descname">PackageDBError</tt><a class="headerlink" href="#fedora.client.PackageDBError" title="Permalink to this definition">¶</a></dt>
<dd><p>Errors generated by the PackageDB Client.</p>
</dd></dl>

<div class="section" id="generic-clients">
<h3>Generic Clients<a class="headerlink" href="#generic-clients" title="Permalink to this headline">¶</a></h3>
<div class="section" id="baseclient">
<h4>BaseClient<a class="headerlink" href="#baseclient" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="fedora.client.BaseClient">
<em class="property">class </em><tt class="descclassname">fedora.client.</tt><tt class="descname">BaseClient</tt><big>(</big><em>base_url</em>, <em>useragent=None</em>, <em>debug=False</em>, <em>insecure=False</em>, <em>username=None</em>, <em>password=None</em>, <em>httpauth=None</em>, <em>session_cookie=None</em>, <em>session_id=None</em>, <em>session_name='tg-visit'</em>, <em>cache_session=True</em>, <em>retries=None</em><big>)</big><a class="headerlink" href="#fedora.client.BaseClient" title="Permalink to this definition">¶</a></dt>
<dd><p>A client for interacting with web services.</p>
<dl class="method">
<dt id="fedora.client.BaseClient.logout">
<tt class="descname">logout</tt><big>(</big><big>)</big><a class="headerlink" href="#fedora.client.BaseClient.logout" title="Permalink to this definition">¶</a></dt>
<dd><p>Logout from the server.</p>
</dd></dl>

<dl class="method">
<dt id="fedora.client.BaseClient.send_request">
<tt class="descname">send_request</tt><big>(</big><em>method</em>, <em>req_params=None</em>, <em>file_params=None</em>, <em>auth=False</em>, <em>retries=0</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#fedora.client.BaseClient.send_request" title="Permalink to this definition">¶</a></dt>
<dd><p>Make an HTTP request to a server method.</p>
<p>The given method is called with any parameters set in req_params.  If
auth is True, then the request is made with an authenticated session
cookie.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>method</strong> &#8211; Method to call on the server.  It&#8217;s a url fragment that
comes after the base_url set in __init__().</li>
<li><strong>req_params</strong> &#8211; Extra parameters to send to the server.</li>
<li><strong>file_params</strong> &#8211; dict of files where the key is the name of the
file field used in the remote method and the value is the local
path of the file to be uploaded.  If you want to pass multiple
files to a single file field, pass the paths as a list of paths.</li>
<li><strong>auth</strong> &#8211; If True perform auth to the server, else do not.</li>
<li><strong>retries</strong> &#8211; if we get an unknown or possibly transient error from
the server, retry this many times.  Setting this to a negative
number makes it try forever.  Defaults to zero, no retries.
number makes it try forever.  Default to use the <tt class="xref py py-attr docutils literal"><span class="pre">retries</span></tt>
value set on the instance or in <tt class="xref py py-meth docutils literal"><span class="pre">__init__()</span></tt>.</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first">Bunch</p>
</td>
</tr>
<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">The data from the server</p>
</td>
</tr>
</tbody>
</table>
<p class="versionchanged">
<span class="versionmodified">Changed in version 0.3.21: </span>* Return data as a Bunch instead of a DictContainer
* Add file_params to allow uploading files</p>
</dd></dl>

<dl class="attribute">
<dt id="fedora.client.BaseClient.session_cookie">
<tt class="descname">session_cookie</tt><a class="headerlink" href="#fedora.client.BaseClient.session_cookie" title="Permalink to this definition">¶</a></dt>
<dd><p><em>Deprecated</em>, use session_id instead.</p>
<p>The session cookie is saved in a file in case it is needed in
consecutive runs of BaseClient.</p>
</dd></dl>

<dl class="attribute">
<dt id="fedora.client.BaseClient.session_id">
<tt class="descname">session_id</tt><a class="headerlink" href="#fedora.client.BaseClient.session_id" title="Permalink to this definition">¶</a></dt>
<dd><p>The session_id.</p>
<p>The session id is saved in a file in case it is needed in consecutive
runs of BaseClient.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="proxyclient">
<h4>ProxyClient<a class="headerlink" href="#proxyclient" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="fedora.client.ProxyClient">
<em class="property">class </em><tt class="descclassname">fedora.client.</tt><tt class="descname">ProxyClient</tt><big>(</big><em>base_url</em>, <em>useragent=None</em>, <em>session_name='tg-visit'</em>, <em>session_as_cookie=True</em>, <em>debug=False</em>, <em>insecure=False</em>, <em>retries=0</em><big>)</big><a class="headerlink" href="#fedora.client.ProxyClient" title="Permalink to this definition">¶</a></dt>
<dd><p>A client to a Fedora Service.  This class is optimized to proxy multiple
users to a service.  ProxyClient is designed to be threadsafe so that
code can instantiate one instance of the class and use it for multiple
requests for different users from different threads.</p>
<p>If you want something that can manage one user&#8217;s connection to a Fedora
Service, then look into using BaseClient instead.</p>
<p>This class has several attributes.  These may be changed after
instantiation however, please note that this class is intended to be
threadsafe.  Changing these values when another thread may affect more
than just the thread that you are making the change in.  (For instance,
changing the debug option could cause other threads to start logging debug
messages in the middle of a method.)</p>
<dl class="attribute">
<dt id="fedora.client.ProxyClient.base_url">
<tt class="descname">base_url</tt><a class="headerlink" href="#fedora.client.ProxyClient.base_url" title="Permalink to this definition">¶</a></dt>
<dt>
<tt class="descname">Initial portion of the url to contact the server.  It is highly</tt></dt>
<dt>
<tt class="descname">recommended not to change this value unless you know that no other</tt></dt>
<dt>
<tt class="descname">threads are accessing this :class:`ProxyClient instance.</tt></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="fedora.client.ProxyClient.useragent">
<tt class="descname">useragent</tt><a class="headerlink" href="#fedora.client.ProxyClient.useragent" title="Permalink to this definition">¶</a></dt>
<dt>
<tt class="descname">Changes the useragent string that is reported to the web server.</tt></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="fedora.client.ProxyClient.session_name">
<tt class="descname">session_name</tt><a class="headerlink" href="#fedora.client.ProxyClient.session_name" title="Permalink to this definition">¶</a></dt>
<dt>
<tt class="descname">Name of the cookie that holds the authentication value.</tt></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="fedora.client.ProxyClient.session_as_cookie">
<tt class="descname">session_as_cookie</tt><a class="headerlink" href="#fedora.client.ProxyClient.session_as_cookie" title="Permalink to this definition">¶</a></dt>
<dt>
<tt class="descname">If :data:`True`, then the session information is saved locally as</tt></dt>
<dt>
<tt class="descname">a cookie.  This is here for backwards compatibility.  New code should</tt></dt>
<dt>
<tt class="descname">set this to :data:`False` when constructing the :class:`ProxyClient`.</tt></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="fedora.client.ProxyClient.debug">
<tt class="descname">debug</tt><a class="headerlink" href="#fedora.client.ProxyClient.debug" title="Permalink to this definition">¶</a></dt>
<dt>
<tt class="descname">If :data:`True`, then more verbose logging is performed to aid in</tt></dt>
<dt>
<tt class="descname">debugging issues.</tt></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="fedora.client.ProxyClient.insecure">
<tt class="descname">insecure</tt><a class="headerlink" href="#fedora.client.ProxyClient.insecure" title="Permalink to this definition">¶</a></dt>
<dt>
<tt class="descname">If :data:`True` then the connection to the server is not checked to be</tt></dt>
<dt>
<tt class="descname">sure that any SSL certificate information is valid.  That means that</tt></dt>
<dt>
<tt class="descname">a remote host can lie about who it is.  Useful for development but</tt></dt>
<dt>
<tt class="descname">should not be used in production code.</tt></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="fedora.client.ProxyClient.retries">
<tt class="descname">retries</tt><a class="headerlink" href="#fedora.client.ProxyClient.retries" title="Permalink to this definition">¶</a></dt>
<dt>
<tt class="descname">Setting this to a positive integer will retry failed requests to the</tt></dt>
<dt>
<tt class="descname">web server this many times.  Setting to a negative integer will retry</tt></dt>
<dt>
<tt class="descname">forever.</tt></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<tt class="descname">debug</tt></dt>
<dd><p>When True, we log extra debugging statements.  When False, we only log
errors.</p>
</dd></dl>

<dl class="method">
<dt id="fedora.client.ProxyClient.send_request">
<tt class="descname">send_request</tt><big>(</big><em>method</em>, <em>req_params=None</em>, <em>auth_params=None</em>, <em>file_params=None</em>, <em>retries=None</em><big>)</big><a class="headerlink" href="#fedora.client.ProxyClient.send_request" title="Permalink to this definition">¶</a></dt>
<dd><p>Make an HTTP request to a server method.</p>
<p>The given method is called with any parameters set in <tt class="docutils literal"><span class="pre">req_params</span></tt>.
If auth is True, then the request is made with an authenticated session
cookie.  Note that path parameters should be set by adding onto the
method, not via <tt class="docutils literal"><span class="pre">req_params</span></tt>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>method</strong> &#8211; Method to call on the server.  It&#8217;s a url fragment that
comes after the base_url set in __init__().  Note that any
parameters set as extra path information should be listed here,
not in <tt class="docutils literal"><span class="pre">req_params</span></tt>.</li>
<li><strong>req_params</strong> &#8211; dict containing extra parameters to send to the
server</li>
<li><strong>auth_params</strong> &#8211; <p>dict containing one or more means of authenticating
to the server.  Valid entries in this dict are:</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">cookie:</th><td class="field-body"><strong>Deprecated</strong> Use <tt class="docutils literal"><span class="pre">session_id</span></tt> instead.  If both
<tt class="docutils literal"><span class="pre">cookie</span></tt> and <tt class="docutils literal"><span class="pre">session_id</span></tt> are set, only <tt class="docutils literal"><span class="pre">session_id</span></tt> will
be used.  A <tt class="docutils literal"><span class="pre">Cookie.SimpleCookie</span></tt> to send as a session cookie
to the server</td>
</tr>
<tr class="field"><th class="field-name">session_id:</th><td class="field-body">Session id to put in a cookie to construct an identity
for the server</td>
</tr>
<tr class="field"><th class="field-name">username:</th><td class="field-body">Username to send to the server</td>
</tr>
<tr class="field"><th class="field-name">password:</th><td class="field-body">Password to use with username to send to the server</td>
</tr>
<tr class="field"><th class="field-name">httpauth:</th><td class="field-body">If set to <tt class="docutils literal"><span class="pre">basic</span></tt> then use HTTP Basic Authentication
to send the username and password to the server.  This may be
extended in the future to support other httpauth types than
<tt class="docutils literal"><span class="pre">basic</span></tt>.</td>
</tr>
</tbody>
</table>
<p>Note that cookie can be sent alone but if one of username or
password is set the other must as well.  Code can set all of these
if it wants and all of them will be sent to the server.  Be careful
of sending cookies that do not match with the username in this
case as the server can decide what to do in this case.</p>
</li>
<li><strong>file_params</strong> &#8211; dict of files where the key is the name of the
file field used in the remote method and the value is the local
path of the file to be uploaded.  If you want to pass multiple
files to a single file field, pass the paths as a list of paths.</li>
<li><strong>retries</strong> &#8211; if we get an unknown or possibly transient error from
the server, retry this many times.  Setting this to a negative
number makes it try forever.  Defaults to zero, no retries.
number makes it try forever.  Default to use the <a class="reference internal" href="#fedora.client.ProxyClient.retries" title="fedora.client.ProxyClient.retries"><tt class="xref py py-attr docutils literal"><span class="pre">retries</span></tt></a>
value set on the instance or in <tt class="xref py py-meth docutils literal"><span class="pre">__init__()</span></tt>.</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">If ProxyClient is created with session_as_cookie=True (the
default), a tuple of session cookie and data from the server.
If ProxyClient was created with session_as_cookie=False, a tuple
of session_id and data instead.</p>
</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">tuple of session information and data from server</p>
</td>
</tr>
</tbody>
</table>
<p class="versionchanged">
<span class="versionmodified">Changed in version 0.3.17: </span>No longer send tg_format=json parameter.  We rely solely on the
Accept: application/json header now.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 0.3.21: </span>* Return data as a Bunch instead of a DictContainer
* Add file_params to allow uploading files</p>
</dd></dl>

</dd></dl>

</div>
</div>
<div class="section" id="clients-for-specific-services">
<h3>Clients for Specific Services<a class="headerlink" href="#clients-for-specific-services" title="Permalink to this headline">¶</a></h3>
<div class="section" id="wiki">
<h4>Wiki<a class="headerlink" href="#wiki" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="fedora.client.Wiki">
<em class="property">class </em><tt class="descclassname">fedora.client.</tt><tt class="descname">Wiki</tt><big>(</big><em>base_url='https://fedoraproject.org/w/'</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#fedora.client.Wiki" title="Permalink to this definition">¶</a></dt>
<dd><dl class="method">
<dt id="fedora.client.Wiki.check_api_limits">
<tt class="descname">check_api_limits</tt><big>(</big><big>)</big><a class="headerlink" href="#fedora.client.Wiki.check_api_limits" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks whether you have the &#8216;apihighlimits&#8217; right or not.</p>
</dd></dl>

<dl class="method">
<dt id="fedora.client.Wiki.fetch_all_revisions">
<tt class="descname">fetch_all_revisions</tt><big>(</big><em>start=1</em>, <em>flags=True</em>, <em>timestamp=True</em>, <em>user=True</em>, <em>size=False</em>, <em>comment=True</em>, <em>content=False</em>, <em>title=True</em>, <em>ignore_imported_revs=True</em>, <em>ignore_wikibot=False</em>, <em>callback=None</em><big>)</big><a class="headerlink" href="#fedora.client.Wiki.fetch_all_revisions" title="Permalink to this definition">¶</a></dt>
<dd><p>Fetch data for all revisions. This could take a long time. You can start
at a specific revision by modifying the &#8216;start&#8217; keyword argument.</p>
<p>To ignore revisions made by &#8220;ImportUser&#8221; and &#8220;Admin&#8221; set
ignore_imported_revs to True (this is the default). To ignore edits made
by Wikibot set ignore_wikibot to True (False is the default).</p>
<p>Modifying the remainder of the keyword arguments will return less/more
data.</p>
</dd></dl>

<dl class="method">
<dt id="fedora.client.Wiki.get_recent_changes">
<tt class="descname">get_recent_changes</tt><big>(</big><em>now</em>, <em>then</em>, <em>limit=500</em><big>)</big><a class="headerlink" href="#fedora.client.Wiki.get_recent_changes" title="Permalink to this definition">¶</a></dt>
<dd><p>Get recent wiki changes from <cite>now</cite> until <cite>then</cite></p>
</dd></dl>

<dl class="method">
<dt id="fedora.client.Wiki.login">
<tt class="descname">login</tt><big>(</big><em>username</em>, <em>password</em><big>)</big><a class="headerlink" href="#fedora.client.Wiki.login" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="fedora.client.Wiki.print_recent_changes">
<tt class="descname">print_recent_changes</tt><big>(</big><em>days=7</em>, <em>show=10</em><big>)</big><a class="headerlink" href="#fedora.client.Wiki.print_recent_changes" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

</div>
</div>
</div>
<div class="section" id="service">
<h2>Service<a class="headerlink" href="#service" title="Permalink to this headline">¶</a></h2>
<div class="section" id="module-fedora.tg.json">
<span id="transforming-sqlalchemy-objects-into-json"></span><h3>Transforming SQLAlchemy Objects into JSON<a class="headerlink" href="#module-fedora.tg.json" title="Permalink to this headline">¶</a></h3>
<p>JSON Helper functions.  Most JSON code directly related to classes is
implemented via the __json__() methods in model.py.  These methods define
methods of transforming a class into json for a few common types.</p>
<p>A JSON-based API(view) for your app.  Most rules would look like:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nd">@jsonify.when</span><span class="p">(</span><span class="s">&quot;isinstance(obj, YourClass)&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">jsonify_yourclass</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span>
    <span class="k">return</span> <span class="p">[</span><span class="n">obj</span><span class="o">.</span><span class="n">val1</span><span class="p">,</span> <span class="n">obj</span><span class="o">.</span><span class="n">val2</span><span class="p">]</span>
</pre></div>
</div>
<p>&#64;jsonify can convert your objects to following types:
lists, dicts, numbers and strings</p>
<p><em>Module author: Toshio Kuratomi &lt;<a class="reference external" href="mailto:tkuratom&#37;&#52;&#48;redhat&#46;com">tkuratom<span>&#64;</span>redhat<span>&#46;</span>com</a>&gt;</em></p>
<dl class="function">
<dt id="fedora.tg.json.jsonify_sa_select_results">
<tt class="descclassname">fedora.tg.json.</tt><tt class="descname">jsonify_sa_select_results</tt><big>(</big><em>obj</em><big>)</big><a class="headerlink" href="#fedora.tg.json.jsonify_sa_select_results" title="Permalink to this definition">¶</a></dt>
<dd><p>Transform selectresults into lists.</p>
<p>The one special thing is that we bind the special json_props into each
descendent.  This allows us to specify a json_props on the toplevel
query result and it will pass to all of its children.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><strong>obj</strong> &#8211; sqlalchemy Query object to jsonify</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body">list representation of the Query with each element in it given
a json_props attributes</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="fedora.tg.json.jsonify_salist">
<tt class="descclassname">fedora.tg.json.</tt><tt class="descname">jsonify_salist</tt><big>(</big><em>obj</em><big>)</big><a class="headerlink" href="#fedora.tg.json.jsonify_salist" title="Permalink to this definition">¶</a></dt>
<dd><p>Transform SQLAlchemy InstrumentedLists into json.</p>
<p>The one special thing is that we bind the special json_props into each
descendent.  This allows us to specify a json_props on the toplevel
query result and it will pass to all of its children.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><strong>obj</strong> &#8211; One of the sqlalchemy list types to jsonify</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body">list of jsonified elements</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="fedora.tg.json.jsonify_saresult">
<tt class="descclassname">fedora.tg.json.</tt><tt class="descname">jsonify_saresult</tt><big>(</big><em>obj</em><big>)</big><a class="headerlink" href="#fedora.tg.json.jsonify_saresult" title="Permalink to this definition">¶</a></dt>
<dd><p>Transform SQLAlchemy ResultProxy into json.</p>
<p>The one special thing is that we bind the special json_props into each
descendent.  This allows us to specify a json_props on the toplevel
query result and it will pass to all of its children.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><strong>obj</strong> &#8211; sqlalchemy ResultProxy to jsonify</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body">list of jsonified elements</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="fedora.tg.json.jsonify_set">
<tt class="descclassname">fedora.tg.json.</tt><tt class="descname">jsonify_set</tt><big>(</big><em>obj</em><big>)</big><a class="headerlink" href="#fedora.tg.json.jsonify_set" title="Permalink to this definition">¶</a></dt>
<dd><p>Transform a set into a list.</p>
<p>simplejson doesn&#8217;t handle sets natively so transform a set into a list.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><strong>obj</strong> &#8211; set to jsonify</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body">list representation of the set</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="class">
<dt id="fedora.tg.json.SABase">
<em class="property">class </em><tt class="descclassname">fedora.tg.json.</tt><tt class="descname">SABase</tt><a class="headerlink" href="#fedora.tg.json.SABase" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for SQLAlchemy mapped objects.</p>
<p>This base class makes sure we have a __json__() method on each SQLAlchemy
mapped object that knows how to:</p>
<ol class="arabic simple">
<li>Return json for the object.</li>
<li>Selectively add tables pulled in from the table to the data we&#8217;re
returning.</li>
</ol>
<dl class="method">
<dt id="fedora.tg.json.SABase.__json__">
<tt class="descname">__json__</tt><big>(</big><big>)</big><a class="headerlink" href="#fedora.tg.json.SABase.__json__" title="Permalink to this definition">¶</a></dt>
<dd><p>Transform any SA mapped class into json.</p>
<p>This method takes an SA mapped class and turns the &#8220;normal&#8221; python
attributes into json.  The properties (from properties in the mapper)
are also included if they have an entry in json_props.  You make
use of this by setting json_props in the controller.</p>
<p>Example controller:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">john</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">Person</span><span class="o">.</span><span class="n">get_by</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">&#39;John&#39;</span><span class="p">)</span>
<span class="c"># Person has a property, addresses, linking it to an Address class.</span>
<span class="c"># Address has a property, phone_nums, linking it to a Phone class.</span>
<span class="n">john</span><span class="o">.</span><span class="n">json_props</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;Person&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s">&#39;addresses&#39;</span><span class="p">],</span>
      <span class="s">&#39;Address&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s">&#39;phone_nums&#39;</span><span class="p">]}</span>
<span class="k">return</span> <span class="nb">dict</span><span class="p">(</span><span class="n">person</span><span class="o">=</span><span class="n">john</span><span class="p">)</span>
</pre></div>
</div>
<p>json_props is a dict that maps class names to lists of properties you
want to output.  This allows you to selectively pick properties you
are interested in for one class but not another.  You are responsible
for avoiding loops.  ie: <em>don&#8217;t</em> do this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">john</span><span class="o">.</span><span class="n">json_props</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;Person&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s">&#39;addresses&#39;</span><span class="p">],</span> <span class="s">&#39;Address&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s">&#39;people&#39;</span><span class="p">]}</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">API Documentation</a><ul>
<li><a class="reference internal" href="#module-fedora.client">Client</a><ul>
<li><a class="reference internal" href="#generic-clients">Generic Clients</a><ul>
<li><a class="reference internal" href="#baseclient">BaseClient</a></li>
<li><a class="reference internal" href="#proxyclient">ProxyClient</a></li>
</ul>
</li>
<li><a class="reference internal" href="#clients-for-specific-services">Clients for Specific Services</a><ul>
<li><a class="reference internal" href="#wiki">Wiki</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#service">Service</a><ul>
<li><a class="reference internal" href="#module-fedora.tg.json">Transforming SQLAlchemy Objects into JSON</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="javascript.html"
                        title="previous chapter">JavaScript</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="glossary.html"
                        title="next chapter">Glossary</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/api.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <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="glossary.html" title="Glossary"
             >next</a> |</li>
        <li class="right" >
          <a href="javascript.html" title="JavaScript"
             >previous</a> |</li>
        <li><a href="index.html">python-fedora v0.3.25.1 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2007-2011 Red Hat, Inc..
      Last updated on Nov 02, 2011.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>
  </body>
</html>