summaryrefslogtreecommitdiff
path: root/reference/kombu.serialization.html
blob: f1c5aa13e64a6147f14cde64617daab89099aecb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317

<!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>kombu.serialization &mdash; Kombu v1.4.0 documentation</title>
    <link rel="stylesheet" href="../_static/celery.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '1.4.0',
        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="top" title="Kombu v1.4.0 documentation" href="../index.html" />
    <link rel="up" title="API Reference" href="index.html" />
    <link rel="next" title="kombu.compression" href="kombu.compression.html" />
    <link rel="prev" title="kombu.transport.virtual.scheduling" href="kombu.transport.virtual.scheduling.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="kombu.compression.html" title="kombu.compression"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="kombu.transport.virtual.scheduling.html" title="kombu.transport.virtual.scheduling"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">Kombu v1.4.0 documentation</a> &raquo;</li>
          <li><a href="index.html" accesskey="U">API Reference</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <span class="target" id="module-kombu.serialization"></span><div class="section" id="kombu-serialization">
<h1>kombu.serialization<a class="headerlink" href="#kombu-serialization" title="Permalink to this headline">¶</a></h1>
<p>Serialization utilities.</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">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
<li>2009 - 2011 by Ask Solem</li>
</ol>
</td>
</tr>
<tr class="field"><th class="field-name">license:</th><td class="field-body"><p class="first last">BSD, see LICENSE for more details.</p>
</td>
</tr>
</tbody>
</table>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#overview" id="id1">Overview</a></li>
<li><a class="reference internal" href="#exceptions" id="id2">Exceptions</a></li>
<li><a class="reference internal" href="#serialization" id="id3">Serialization</a></li>
<li><a class="reference internal" href="#registry" id="id4">Registry</a></li>
</ul>
</div>
<div class="section" id="overview">
<h2><a class="toc-backref" href="#id1">Overview</a><a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
<p>Centralized support for encoding/decoding of data structures.
Contains json, pickle, msgpack, and yaml serializers.</p>
<p>Optionally installs support for YAML if the <a class="reference external" href="http://pyyaml.org/">PyYAML</a> package
is installed.</p>
<p>Optionally installs support for <a class="reference external" href="http://msgpack.sourceforge.net/">msgpack</a> if the <a class="reference external" href="http://pypi.python.org/pypi/msgpack-python/">msgpack-python</a>
package is installed.</p>
</div>
<div class="section" id="exceptions">
<h2><a class="toc-backref" href="#id2">Exceptions</a><a class="headerlink" href="#exceptions" title="Permalink to this headline">¶</a></h2>
<dl class="exception">
<dt id="kombu.serialization.SerializerNotInstalled">
<em class="property">exception </em><tt class="descclassname">kombu.serialization.</tt><tt class="descname">SerializerNotInstalled</tt><a class="headerlink" href="#kombu.serialization.SerializerNotInstalled" title="Permalink to this definition">¶</a></dt>
<dd><p>Support for the requested serialization type is not installed</p>
</dd></dl>

</div>
<div class="section" id="serialization">
<h2><a class="toc-backref" href="#id3">Serialization</a><a class="headerlink" href="#serialization" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="kombu.serialization.encode">
<tt class="descclassname">kombu.serialization.</tt><tt class="descname">encode</tt><big>(</big><em>self</em>, <em>data</em>, <em>serializer=None</em><big>)</big><a class="headerlink" href="#kombu.serialization.encode" title="Permalink to this definition">¶</a></dt>
<dd><dl class="function">
<dt>
<tt class="descname">decode(data, content_type, content_encoding):</tt></dt>
<dd><p>Deserialize a data stream as serialized using <cite>encode</cite>
based on <cite>content_type</cite>.</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>data</strong> &#8211; The message data to deserialize.</li>
<li><strong>content_type</strong> &#8211; The content-type of the data.
(e.g., <cite>application/json</cite>).</li>
<li><strong>content_encoding</strong> &#8211; The content-encoding of the data.
(e.g., <cite>utf-8</cite>, <cite>binary</cite>, or <cite>us-ascii</cite>).</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">The unserialized data.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<dl class="function">
<dt id="kombu.serialization.decode">
<tt class="descclassname">kombu.serialization.</tt><tt class="descname">decode</tt><big>(</big><em>self</em>, <em>data</em>, <em>content_type</em>, <em>content_encoding</em><big>)</big><a class="headerlink" href="#kombu.serialization.decode" title="Permalink to this definition">¶</a></dt>
<dd><dl class="function">
<dt>
<tt class="descname">register(name, encoder, decoder, content_type,</tt></dt>
<dt>
<tt class="descname">content_encoding=&quot;utf-8&quot;):</tt></dt>
<dt>
<tt class="descname">Register a new encoder/decoder.</tt></dt>
<dd><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 last simple">
<li><strong>name</strong> &#8211; A convenience name for the serialization method.</li>
<li><strong>encoder</strong> &#8211; A method that will be passed a python data structure
and should return a string representing the serialized data.
If <tt class="xref py py-const xref docutils literal"><span class="pre">None</span></tt>, then only a decoder will be registered. Encoding
will not be possible.</li>
<li><strong>decoder</strong> &#8211; A method that will be passed a string representing
serialized data and should return a python data structure.
If <tt class="xref py py-const xref docutils literal"><span class="pre">None</span></tt>, then only an encoder will be registered.
Decoding will not be possible.</li>
<li><strong>content_type</strong> &#8211; The mime-type describing the serialized
structure.</li>
<li><strong>content_encoding</strong> &#8211; The content encoding (character set) that
the <cite>decoder</cite> method will be returning. Will usually be
utf-8`, <cite>us-ascii</cite>, or <cite>binary</cite>.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<dl class="function">
<dt id="kombu.serialization.raw_encode">
<tt class="descclassname">kombu.serialization.</tt><tt class="descname">raw_encode</tt><big>(</big><em>data</em><big>)</big><a class="headerlink" href="#kombu.serialization.raw_encode" title="Permalink to this definition">¶</a></dt>
<dd><p>Special case serializer.</p>
</dd></dl>

</div>
<div class="section" id="registry">
<h2><a class="toc-backref" href="#id4">Registry</a><a class="headerlink" href="#registry" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="kombu.serialization.register">
<tt class="descclassname">kombu.serialization.</tt><tt class="descname">register</tt><big>(</big><em>self</em>, <em>name</em>, <em>encoder</em>, <em>decoder</em>, <em>content_type</em>, <em>content_encoding='utf-8'</em><big>)</big><a class="headerlink" href="#kombu.serialization.register" title="Permalink to this definition">¶</a></dt>
<dd><dl class="function">
<dt>
<tt class="descname">unregister(name):</tt></dt>
<dt>
<tt class="descname">Unregister registered encoder/decoder.</tt></dt>
<dd><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>name</strong> &#8211; Registered serialization method name.</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<dl class="data">
<dt id="kombu.serialization.registry">
<tt class="descclassname">kombu.serialization.</tt><tt class="descname">registry</tt><a class="headerlink" href="#kombu.serialization.registry" title="Permalink to this definition">¶</a></dt>
<dd><dl class="function">
<dt>
<tt class="descclassname">kombu.serialization.</tt><tt class="descname">encode</tt><big>(</big><em>data</em>, <em>serializer=default_serializer</em><big>)</big></dt>
<dd><p>Serialize a data structure into a string suitable for sending
as an AMQP message body.</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>data</strong> &#8211; The message data to send. Can be a list,
dictionary or a string.</li>
<li><strong>serializer</strong> &#8211; <p>An optional string representing
the serialization method you want the data marshalled
into. (For example, <cite>json</cite>, <cite>raw</cite>, or <cite>pickle</cite>).</p>
<p>If <tt class="xref py py-const xref docutils literal"><span class="pre">None</span></tt> (default), then json will be used, unless
<cite>data</cite> is a <tt class="xref py py-class docutils literal"><span class="pre">str</span></tt> or <tt class="xref py py-class docutils literal"><span class="pre">unicode</span></tt> object. In this
latter case, no serialization occurs as it would be
unnecessary.</p>
<p>Note that if <cite>serializer</cite> is specified, then that
serialization method will be used even if a <tt class="xref py py-class docutils literal"><span class="pre">str</span></tt>
or <tt class="xref py py-class docutils literal"><span class="pre">unicode</span></tt> object is passed in.</p>
</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A three-item tuple containing the content type
(e.g., <cite>application/json</cite>), content encoding, (e.g.,
<cite>utf-8</cite>) and a string containing the serialized
data.</p>
</td>
</tr>
<tr class="field"><th class="field-name" colspan="2">Raises SerializerNotInstalled:</th></tr>
<tr class="field"><td>&nbsp;</td><td class="field-body"><p class="first last">If the serialization method
requested is not available.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper"><p class="logo"><a href="../index.html">
  <img class="logo" width="128" height="128" src="http://cloud.github.com/downloads/ask/kombu/kombusmall.jpg" alt="Logo"/>
</a></p>
  <h3><a href="../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">kombu.serialization</a><ul>
<li><a class="reference internal" href="#overview">Overview</a></li>
<li><a class="reference internal" href="#exceptions">Exceptions</a></li>
<li><a class="reference internal" href="#serialization">Serialization</a></li>
<li><a class="reference internal" href="#registry">Registry</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="kombu.transport.virtual.scheduling.html"
                        title="previous chapter">kombu.transport.virtual.scheduling</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="kombu.compression.html"
                        title="next chapter">kombu.compression</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../_sources/reference/kombu.serialization.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="kombu.compression.html" title="kombu.compression"
             >next</a> |</li>
        <li class="right" >
          <a href="kombu.transport.virtual.scheduling.html" title="kombu.transport.virtual.scheduling"
             >previous</a> |</li>
        <li><a href="../index.html">Kombu v1.4.0 documentation</a> &raquo;</li>
          <li><a href="index.html" >API Reference</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2009-2011, Ask Solem.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>
  </body>
</html>