Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-release > by-pkgid > bc55833f04f370ac3ed453ef5b0ad686 > files > 219

python2-gridfs-3.7.2-1.mga7.i586.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="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>codec_options – Tools for specifying BSON codec options &#8212; PyMongo 3.7.2 documentation</title>
    <link rel="stylesheet" href="../../_static/pydoctheme.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="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="dbref – Tools for manipulating DBRefs (references to documents stored in MongoDB)" href="dbref.html" />
    <link rel="prev" title="code – Tools for representing JavaScript code" href="code.html" /> 
  </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="dbref.html" title="dbref – Tools for manipulating DBRefs (references to documents stored in MongoDB)"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="code.html" title="code – Tools for representing JavaScript code"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">PyMongo 3.7.2 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >API Documentation</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" accesskey="U"><code class="docutils literal notranslate"><span class="pre">bson</span></code> – BSON (Binary JSON) Encoding and Decoding</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="module-bson.codec_options">
<span id="codec-options-tools-for-specifying-bson-codec-options"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">codec_options</span></code> – Tools for specifying BSON codec options<a class="headerlink" href="#module-bson.codec_options" title="Permalink to this headline">¶</a></h1>
<p>Tools for specifying BSON codec options.</p>
<dl class="class">
<dt id="bson.codec_options.CodecOptions">
<em class="property">class </em><code class="descclassname">bson.codec_options.</code><code class="descname">CodecOptions</code><a class="headerlink" href="#bson.codec_options.CodecOptions" title="Permalink to this definition">¶</a></dt>
<dd><p>Encapsulates options used encoding and / or decoding BSON.</p>
<p>The <cite>document_class</cite> option is used to define a custom type for use
decoding BSON documents. Access to the underlying raw BSON bytes for
a document is available using the <a class="reference internal" href="raw_bson.html#bson.raw_bson.RawBSONDocument" title="bson.raw_bson.RawBSONDocument"><code class="xref py py-class docutils literal notranslate"><span class="pre">RawBSONDocument</span></code></a>
type:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">bson.raw_bson</span> <span class="k">import</span> <span class="n">RawBSONDocument</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">bson.codec_options</span> <span class="k">import</span> <span class="n">CodecOptions</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">codec_options</span> <span class="o">=</span> <span class="n">CodecOptions</span><span class="p">(</span><span class="n">document_class</span><span class="o">=</span><span class="n">RawBSONDocument</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">coll</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">get_collection</span><span class="p">(</span><span class="s1">&#39;test&#39;</span><span class="p">,</span> <span class="n">codec_options</span><span class="o">=</span><span class="n">codec_options</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">doc</span> <span class="o">=</span> <span class="n">coll</span><span class="o">.</span><span class="n">find_one</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">doc</span><span class="o">.</span><span class="n">raw</span>
<span class="go">&#39;\x16\x00\x00\x00\x07_id\x00[0\x165\x91\x10\xea\x14\xe8\xc5\x8b\x93\x00&#39;</span>
</pre></div>
</div>
<p>The document class can be any type that inherits from
<code class="xref py py-class docutils literal notranslate"><span class="pre">MutableMapping</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">AttributeDict</span><span class="p">(</span><span class="nb">dict</span><span class="p">):</span>
<span class="gp">... </span>    <span class="c1"># A dict that supports attribute access.</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">__getattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
<span class="gp">... </span>        <span class="k">return</span> <span class="bp">self</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">__setattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="gp">... </span>        <span class="bp">self</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">codec_options</span> <span class="o">=</span> <span class="n">CodecOptions</span><span class="p">(</span><span class="n">document_class</span><span class="o">=</span><span class="n">AttributeDict</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">coll</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">get_collection</span><span class="p">(</span><span class="s1">&#39;test&#39;</span><span class="p">,</span> <span class="n">codec_options</span><span class="o">=</span><span class="n">codec_options</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">doc</span> <span class="o">=</span> <span class="n">coll</span><span class="o">.</span><span class="n">find_one</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">doc</span><span class="o">.</span><span class="n">_id</span>
<span class="go">ObjectId(&#39;5b3016359110ea14e8c58b93&#39;)</span>
</pre></div>
</div>
<p>See <a class="reference internal" href="../../examples/datetimes.html"><span class="doc">Datetimes and Timezones</span></a> for examples using the <cite>tz_aware</cite> and
<cite>tzinfo</cite> options.</p>
<p>See <a class="reference internal" href="binary.html#bson.binary.UUIDLegacy" title="bson.binary.UUIDLegacy"><code class="xref py py-class docutils literal notranslate"><span class="pre">UUIDLegacy</span></code></a> for examples using the
<cite>uuid_representation</cite> option.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><cite>document_class</cite>: BSON documents returned in queries will be decoded
to an instance of this class. Must be a subclass of
<code class="xref py py-class docutils literal notranslate"><span class="pre">MutableMapping</span></code>. Defaults to <code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code>.</li>
<li><cite>tz_aware</cite>: If <code class="docutils literal notranslate"><span class="pre">True</span></code>, BSON datetimes will be decoded to timezone
aware instances of <code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code>. Otherwise they will be
naive. Defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code>.</li>
<li><cite>uuid_representation</cite>: The BSON representation to use when encoding
and decoding instances of <code class="xref py py-class docutils literal notranslate"><span class="pre">UUID</span></code>. Defaults to
<a class="reference internal" href="binary.html#bson.binary.PYTHON_LEGACY" title="bson.binary.PYTHON_LEGACY"><code class="xref py py-data docutils literal notranslate"><span class="pre">PYTHON_LEGACY</span></code></a>.</li>
<li><cite>unicode_decode_error_handler</cite>: The error handler to apply when
a Unicode-related error occurs during BSON decoding that would
otherwise raise <code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeDecodeError</span></code>. Valid options include
‘strict’, ‘replace’, and ‘ignore’. Defaults to ‘strict’.</li>
<li><cite>tzinfo</cite>: A <code class="xref py py-class docutils literal notranslate"><span class="pre">tzinfo</span></code> subclass that specifies the
timezone to/from which <code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code> objects should be
encoded/decoded.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">Care must be taken when changing
<cite>unicode_decode_error_handler</cite> from its default value (‘strict’).
The ‘replace’ and ‘ignore’ modes should not be used when documents
retrieved from the server will be modified in the client application
and stored back to the server.</p>
</div>
<dl class="method">
<dt id="bson.codec_options.CodecOptions.with_options">
<code class="descname">with_options</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#bson.codec_options.CodecOptions.with_options" title="Permalink to this definition">¶</a></dt>
<dd><p>Make a copy of this CodecOptions, overriding some options:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">bson.codec_options</span> <span class="k">import</span> <span class="n">DEFAULT_CODEC_OPTIONS</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">DEFAULT_CODEC_OPTIONS</span><span class="o">.</span><span class="n">tz_aware</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">options</span> <span class="o">=</span> <span class="n">DEFAULT_CODEC_OPTIONS</span><span class="o">.</span><span class="n">with_options</span><span class="p">(</span><span class="n">tz_aware</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">options</span><span class="o">.</span><span class="n">tz_aware</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.5.</span></p>
</div>
</dd></dl>

</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="code.html"
                        title="previous chapter"><code class="docutils literal notranslate"><span class="pre">code</span></code> – Tools for representing JavaScript code</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="dbref.html"
                        title="next chapter"><code class="docutils literal notranslate"><span class="pre">dbref</span></code> – Tools for manipulating DBRefs (references to documents stored in MongoDB)</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/api/bson/codec_options.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" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </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="dbref.html" title="dbref – Tools for manipulating DBRefs (references to documents stored in MongoDB)"
             >next</a> |</li>
        <li class="right" >
          <a href="code.html" title="code – Tools for representing JavaScript code"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">PyMongo 3.7.2 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >API Documentation</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" ><code class="docutils literal notranslate"><span class="pre">bson</span></code> – BSON (Binary JSON) Encoding and Decoding</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright MongoDB, Inc. 2008-present. MongoDB, Mongo, and the leaf logo are registered trademarks of MongoDB, Inc.
    </div>
  </body>
</html>