~dkuhlman/python-training-materials/Materials

« back to all changes in this revision

Viewing changes to python-3.5.1-docs-html/c-api/marshal.html

  • Committer: Dave Kuhlman
  • Date: 2017-04-15 16:24:56 UTC
  • Revision ID: dkuhlman@davekuhlman.org-20170415162456-iav9vozzg4iwqwv3
Updated docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
 
 
4
 
 
5
 
<html xmlns="http://www.w3.org/1999/xhtml">
6
 
  <head>
7
 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8
 
    
9
 
    <title>Data marshalling support &mdash; Python 3.5.1 documentation</title>
10
 
    
11
 
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
12
 
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
13
 
    
14
 
    <script type="text/javascript">
15
 
      var DOCUMENTATION_OPTIONS = {
16
 
        URL_ROOT:    '../',
17
 
        VERSION:     '3.5.1',
18
 
        COLLAPSE_INDEX: false,
19
 
        FILE_SUFFIX: '.html',
20
 
        HAS_SOURCE:  true
21
 
      };
22
 
    </script>
23
 
    <script type="text/javascript" src="../_static/jquery.js"></script>
24
 
    <script type="text/javascript" src="../_static/underscore.js"></script>
25
 
    <script type="text/javascript" src="../_static/doctools.js"></script>
26
 
    <script type="text/javascript" src="../_static/sidebar.js"></script>
27
 
    <link rel="search" type="application/opensearchdescription+xml"
28
 
          title="Search within Python 3.5.1 documentation"
29
 
          href="../_static/opensearch.xml"/>
30
 
    <link rel="author" title="About these documents" href="../about.html" />
31
 
    <link rel="copyright" title="Copyright" href="../copyright.html" />
32
 
    <link rel="top" title="Python 3.5.1 documentation" href="../contents.html" />
33
 
    <link rel="up" title="Utilities" href="utilities.html" />
34
 
    <link rel="next" title="Parsing arguments and building values" href="arg.html" />
35
 
    <link rel="prev" title="Importing Modules" href="import.html" />
36
 
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
37
 
    <script type="text/javascript" src="../_static/copybutton.js"></script>
38
 
    <script type="text/javascript" src="../_static/version_switch.js"></script>
39
 
    
40
 
 
41
 
 
42
 
  </head>
43
 
  <body role="document">  
44
 
    <div class="related" role="navigation" aria-label="related navigation">
45
 
      <h3>Navigation</h3>
46
 
      <ul>
47
 
        <li class="right" style="margin-right: 10px">
48
 
          <a href="../genindex.html" title="General Index"
49
 
             accesskey="I">index</a></li>
50
 
        <li class="right" >
51
 
          <a href="../py-modindex.html" title="Python Module Index"
52
 
             >modules</a> |</li>
53
 
        <li class="right" >
54
 
          <a href="arg.html" title="Parsing arguments and building values"
55
 
             accesskey="N">next</a> |</li>
56
 
        <li class="right" >
57
 
          <a href="import.html" title="Importing Modules"
58
 
             accesskey="P">previous</a> |</li>
59
 
        <li><img src="../_static/py.png" alt=""
60
 
                 style="vertical-align: middle; margin-top: -1px"/></li>
61
 
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
62
 
        <li>
63
 
          <span class="version_switcher_placeholder">3.5.1</span>
64
 
          <a href="../index.html">Documentation </a> &raquo;
65
 
        </li>
66
 
 
67
 
          <li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> &raquo;</li>
68
 
          <li class="nav-item nav-item-2"><a href="utilities.html" accesskey="U">Utilities</a> &raquo;</li> 
69
 
      </ul>
70
 
    </div>    
71
 
 
72
 
    <div class="document">
73
 
      <div class="documentwrapper">
74
 
        <div class="bodywrapper">
75
 
          <div class="body" role="main">
76
 
            
77
 
  <div class="section" id="data-marshalling-support">
78
 
<span id="marshalling-utils"></span><h1>Data marshalling support<a class="headerlink" href="#data-marshalling-support" title="Permalink to this headline">¶</a></h1>
79
 
<p>These routines allow C code to work with serialized objects using the same
80
 
data format as the <a class="reference internal" href="../library/marshal.html#module-marshal" title="marshal: Convert Python objects to streams of bytes and back (with different constraints)."><code class="xref py py-mod docutils literal"><span class="pre">marshal</span></code></a> module.  There are functions to write data
81
 
into the serialization format, and additional functions that can be used to
82
 
read the data back.  Files used to store marshalled data must be opened in
83
 
binary mode.</p>
84
 
<p>Numeric values are stored with the least significant byte first.</p>
85
 
<p>The module supports two versions of the data format: version 0 is the
86
 
historical version, version 1 shares interned strings in the file, and upon
87
 
unmarshalling.  Version 2 uses a binary format for floating point numbers.
88
 
<em>Py_MARSHAL_VERSION</em> indicates the current file format (currently 2).</p>
89
 
<dl class="function">
90
 
<dt id="c.PyMarshal_WriteLongToFile">
91
 
void <code class="descname">PyMarshal_WriteLongToFile</code><span class="sig-paren">(</span>long<em>&nbsp;value</em>, FILE<em>&nbsp;*file</em>, int<em>&nbsp;version</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyMarshal_WriteLongToFile" title="Permalink to this definition">¶</a></dt>
92
 
<dd><p>Marshal a <code class="xref c c-type docutils literal"><span class="pre">long</span></code> integer, <em>value</em>, to <em>file</em>.  This will only write
93
 
the least-significant 32 bits of <em>value</em>; regardless of the size of the
94
 
native <code class="xref c c-type docutils literal"><span class="pre">long</span></code> type.  <em>version</em> indicates the file format.</p>
95
 
</dd></dl>
96
 
 
97
 
<dl class="function">
98
 
<dt id="c.PyMarshal_WriteObjectToFile">
99
 
void <code class="descname">PyMarshal_WriteObjectToFile</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*value</em>, FILE<em>&nbsp;*file</em>, int<em>&nbsp;version</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyMarshal_WriteObjectToFile" title="Permalink to this definition">¶</a></dt>
100
 
<dd><p>Marshal a Python object, <em>value</em>, to <em>file</em>.
101
 
<em>version</em> indicates the file format.</p>
102
 
</dd></dl>
103
 
 
104
 
<dl class="function">
105
 
<dt id="c.PyMarshal_WriteObjectToString">
106
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyMarshal_WriteObjectToString</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*value</em>, int<em>&nbsp;version</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyMarshal_WriteObjectToString" title="Permalink to this definition">¶</a></dt>
107
 
<dd><em class="refcount">Return value: New reference.</em><p>Return a string object containing the marshalled representation of <em>value</em>.
108
 
<em>version</em> indicates the file format.</p>
109
 
</dd></dl>
110
 
 
111
 
<p>The following functions allow marshalled values to be read back in.</p>
112
 
<p>XXX What about error detection?  It appears that reading past the end of the
113
 
file will always result in a negative numeric value (where that&#8217;s relevant),
114
 
but it&#8217;s not clear that negative values won&#8217;t be handled properly when there&#8217;s
115
 
no error.  What&#8217;s the right way to tell? Should only non-negative values be
116
 
written using these routines?</p>
117
 
<dl class="function">
118
 
<dt id="c.PyMarshal_ReadLongFromFile">
119
 
long <code class="descname">PyMarshal_ReadLongFromFile</code><span class="sig-paren">(</span>FILE<em>&nbsp;*file</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyMarshal_ReadLongFromFile" title="Permalink to this definition">¶</a></dt>
120
 
<dd><p>Return a C <code class="xref c c-type docutils literal"><span class="pre">long</span></code> from the data stream in a <code class="xref c c-type docutils literal"><span class="pre">FILE*</span></code> opened
121
 
for reading.  Only a 32-bit value can be read in using this function,
122
 
regardless of the native size of <code class="xref c c-type docutils literal"><span class="pre">long</span></code>.</p>
123
 
<p>On error, raise an exception and return <code class="docutils literal"><span class="pre">-1</span></code>.</p>
124
 
</dd></dl>
125
 
 
126
 
<dl class="function">
127
 
<dt id="c.PyMarshal_ReadShortFromFile">
128
 
int <code class="descname">PyMarshal_ReadShortFromFile</code><span class="sig-paren">(</span>FILE<em>&nbsp;*file</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyMarshal_ReadShortFromFile" title="Permalink to this definition">¶</a></dt>
129
 
<dd><p>Return a C <code class="xref c c-type docutils literal"><span class="pre">short</span></code> from the data stream in a <code class="xref c c-type docutils literal"><span class="pre">FILE*</span></code> opened
130
 
for reading.  Only a 16-bit value can be read in using this function,
131
 
regardless of the native size of <code class="xref c c-type docutils literal"><span class="pre">short</span></code>.</p>
132
 
<p>On error, raise an exception and return <code class="docutils literal"><span class="pre">-1</span></code>.</p>
133
 
</dd></dl>
134
 
 
135
 
<dl class="function">
136
 
<dt id="c.PyMarshal_ReadObjectFromFile">
137
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyMarshal_ReadObjectFromFile</code><span class="sig-paren">(</span>FILE<em>&nbsp;*file</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyMarshal_ReadObjectFromFile" title="Permalink to this definition">¶</a></dt>
138
 
<dd><em class="refcount">Return value: New reference.</em><p>Return a Python object from the data stream in a <code class="xref c c-type docutils literal"><span class="pre">FILE*</span></code> opened for
139
 
reading.</p>
140
 
<p>On error, sets the appropriate exception (<a class="reference internal" href="../library/exceptions.html#EOFError" title="EOFError"><code class="xref py py-exc docutils literal"><span class="pre">EOFError</span></code></a> or
141
 
<a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal"><span class="pre">TypeError</span></code></a>) and returns <em>NULL</em>.</p>
142
 
</dd></dl>
143
 
 
144
 
<dl class="function">
145
 
<dt id="c.PyMarshal_ReadLastObjectFromFile">
146
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyMarshal_ReadLastObjectFromFile</code><span class="sig-paren">(</span>FILE<em>&nbsp;*file</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyMarshal_ReadLastObjectFromFile" title="Permalink to this definition">¶</a></dt>
147
 
<dd><em class="refcount">Return value: New reference.</em><p>Return a Python object from the data stream in a <code class="xref c c-type docutils literal"><span class="pre">FILE*</span></code> opened for
148
 
reading.  Unlike <a class="reference internal" href="#c.PyMarshal_ReadObjectFromFile" title="PyMarshal_ReadObjectFromFile"><code class="xref c c-func docutils literal"><span class="pre">PyMarshal_ReadObjectFromFile()</span></code></a>, this function
149
 
assumes that no further objects will be read from the file, allowing it to
150
 
aggressively load file data into memory so that the de-serialization can
151
 
operate from data in memory rather than reading a byte at a time from the
152
 
file.  Only use these variant if you are certain that you won&#8217;t be reading
153
 
anything else from the file.</p>
154
 
<p>On error, sets the appropriate exception (<a class="reference internal" href="../library/exceptions.html#EOFError" title="EOFError"><code class="xref py py-exc docutils literal"><span class="pre">EOFError</span></code></a> or
155
 
<a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal"><span class="pre">TypeError</span></code></a>) and returns <em>NULL</em>.</p>
156
 
</dd></dl>
157
 
 
158
 
<dl class="function">
159
 
<dt id="c.PyMarshal_ReadObjectFromString">
160
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyMarshal_ReadObjectFromString</code><span class="sig-paren">(</span>const char<em>&nbsp;*string</em>, Py_ssize_t<em>&nbsp;len</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyMarshal_ReadObjectFromString" title="Permalink to this definition">¶</a></dt>
161
 
<dd><em class="refcount">Return value: New reference.</em><p>Return a Python object from the data stream in a character buffer
162
 
containing <em>len</em> bytes pointed to by <em>string</em>.</p>
163
 
<p>On error, sets the appropriate exception (<a class="reference internal" href="../library/exceptions.html#EOFError" title="EOFError"><code class="xref py py-exc docutils literal"><span class="pre">EOFError</span></code></a> or
164
 
<a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal"><span class="pre">TypeError</span></code></a>) and returns <em>NULL</em>.</p>
165
 
</dd></dl>
166
 
 
167
 
</div>
168
 
 
169
 
 
170
 
          </div>
171
 
        </div>
172
 
      </div>
173
 
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
174
 
        <div class="sphinxsidebarwrapper">
175
 
  <h4>Previous topic</h4>
176
 
  <p class="topless"><a href="import.html"
177
 
                        title="previous chapter">Importing Modules</a></p>
178
 
  <h4>Next topic</h4>
179
 
  <p class="topless"><a href="arg.html"
180
 
                        title="next chapter">Parsing arguments and building values</a></p>
181
 
<h3>This Page</h3>
182
 
<ul class="this-page-menu">
183
 
  <li><a href="../bugs.html">Report a Bug</a></li>
184
 
  <li><a href="../_sources/c-api/marshal.txt"
185
 
         rel="nofollow">Show Source</a></li>
186
 
</ul>
187
 
 
188
 
<div id="searchbox" style="display: none" role="search">
189
 
  <h3>Quick search</h3>
190
 
    <form class="search" action="../search.html" method="get">
191
 
      <input type="text" name="q" />
192
 
      <input type="submit" value="Go" />
193
 
      <input type="hidden" name="check_keywords" value="yes" />
194
 
      <input type="hidden" name="area" value="default" />
195
 
    </form>
196
 
    <p class="searchtip" style="font-size: 90%">
197
 
    Enter search terms or a module, class or function name.
198
 
    </p>
199
 
</div>
200
 
<script type="text/javascript">$('#searchbox').show(0);</script>
201
 
        </div>
202
 
      </div>
203
 
      <div class="clearer"></div>
204
 
    </div>  
205
 
    <div class="related" role="navigation" aria-label="related navigation">
206
 
      <h3>Navigation</h3>
207
 
      <ul>
208
 
        <li class="right" style="margin-right: 10px">
209
 
          <a href="../genindex.html" title="General Index"
210
 
             >index</a></li>
211
 
        <li class="right" >
212
 
          <a href="../py-modindex.html" title="Python Module Index"
213
 
             >modules</a> |</li>
214
 
        <li class="right" >
215
 
          <a href="arg.html" title="Parsing arguments and building values"
216
 
             >next</a> |</li>
217
 
        <li class="right" >
218
 
          <a href="import.html" title="Importing Modules"
219
 
             >previous</a> |</li>
220
 
        <li><img src="../_static/py.png" alt=""
221
 
                 style="vertical-align: middle; margin-top: -1px"/></li>
222
 
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
223
 
        <li>
224
 
          <span class="version_switcher_placeholder">3.5.1</span>
225
 
          <a href="../index.html">Documentation </a> &raquo;
226
 
        </li>
227
 
 
228
 
          <li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> &raquo;</li>
229
 
          <li class="nav-item nav-item-2"><a href="utilities.html" >Utilities</a> &raquo;</li> 
230
 
      </ul>
231
 
    </div>  
232
 
    <div class="footer">
233
 
    &copy; <a href="../copyright.html">Copyright</a> 1990-2016, Python Software Foundation.
234
 
    <br />
235
 
    The Python Software Foundation is a non-profit corporation.
236
 
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
237
 
    <br />
238
 
    Last updated on Jan 22, 2016.
239
 
    <a href="../bugs.html">Found a bug</a>?
240
 
    <br />
241
 
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
242
 
    </div>
243
 
 
244
 
  </body>
245
 
</html>
 
 
b'\\ No newline at end of file'