/usr/share/doc/python-pymongo-doc/html/python3.html is in python-pymongo-doc 2.6.3-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <!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>Python 3 FAQ — PyMongo 2.6.3 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: '2.6.3',
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>
<script type="text/javascript" src="_static/sidebar.js"></script>
<link rel="top" title="PyMongo 2.6.3 documentation" href="index.html" />
<link rel="prev" title="Requests" href="examples/requests.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="examples/requests.html" title="Requests"
accesskey="P">previous</a> |</li>
<li><a href="index.html">PyMongo 2.6.3 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="python-3-faq">
<h1><a class="toc-backref" href="#id1">Python 3 FAQ</a><a class="headerlink" href="#python-3-faq" title="Permalink to this headline">¶</a></h1>
<div class="contents topic" id="contents">
<p class="topic-title first">Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#python-3-faq" id="id1">Python 3 FAQ</a><ul>
<li><a class="reference internal" href="#what-python-3-versions-are-supported" id="id2">What Python 3 versions are supported?</a></li>
<li><a class="reference internal" href="#are-there-any-pymongo-behavior-changes-with-python-3" id="id3">Are there any PyMongo behavior changes with Python 3?</a></li>
<li><a class="reference internal" href="#why-can-t-i-share-pickled-objectids-between-some-versions-of-python-2-and-3" id="id4">Why can’t I share pickled ObjectIds between some versions of Python 2 and 3?</a></li>
<li><a class="reference internal" href="#why-do-i-get-a-syntax-error-importing-pymongo-after-installing-from-source" id="id5">Why do I get a syntax error importing pymongo after installing from source?</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="what-python-3-versions-are-supported">
<h2><a class="toc-backref" href="#id2">What Python 3 versions are supported?</a><a class="headerlink" href="#what-python-3-versions-are-supported" title="Permalink to this headline">¶</a></h2>
<p>PyMongo supports Python 3.x where x >= 1.</p>
<p>We <strong>do not</strong> support Python 3.0.x. It has many problems
(some that directly impact PyMongo) and was <a class="reference external" href="http://www.python.org/download/releases/3.0.1/">end-of-lifed</a>
with the release of Python 3.1.</p>
</div>
<div class="section" id="are-there-any-pymongo-behavior-changes-with-python-3">
<h2><a class="toc-backref" href="#id3">Are there any PyMongo behavior changes with Python 3?</a><a class="headerlink" href="#are-there-any-pymongo-behavior-changes-with-python-3" title="Permalink to this headline">¶</a></h2>
<p>Only one intentional change. Instances of <tt class="xref py py-class docutils literal"><span class="pre">bytes</span></tt>
are encoded as BSON type 5 (Binary data) with subtype 0.
In Python 3 they are decoded back to <tt class="xref py py-class docutils literal"><span class="pre">bytes</span></tt>. In
Python 2 they will be decoded to <a class="reference internal" href="api/bson/binary.html#bson.binary.Binary" title="bson.binary.Binary"><tt class="xref py py-class docutils literal"><span class="pre">Binary</span></tt></a>
with subtype 0.</p>
<p>For example, let’s insert a <tt class="xref py py-class docutils literal"><span class="pre">bytes</span></tt> instance using Python 3 then
read it back. Notice the byte string is decoded back to <tt class="xref py py-class docutils literal"><span class="pre">bytes</span></tt>:</p>
<div class="highlight-python"><pre>Python 3.1.4 (default, Mar 21 2012, 14:34:01)
[GCC 4.5.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>> c = pymongo.MongoClient()
>>> c.test.bintest.insert({'binary': b'this is a byte string'})
ObjectId('4f9086b1fba5222021000000')
>>> c.test.bintest.find_one()
{'binary': b'this is a byte string', '_id': ObjectId('4f9086b1fba5222021000000')}</pre>
</div>
<p>Now retrieve the same document in Python 2. Notice the byte string is decoded
to <a class="reference internal" href="api/bson/binary.html#bson.binary.Binary" title="bson.binary.Binary"><tt class="xref py py-class docutils literal"><span class="pre">Binary</span></tt></a>:</p>
<div class="highlight-python"><pre>Python 2.7.3 (default, Apr 12 2012, 10:35:17)
[GCC 4.5.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>> c = pymongo.MongoClient()
>>> c.test.bintest.find_one()
{u'binary': Binary('this is a byte string', 0), u'_id': ObjectId('4f9086b1fba5222021000000')}</pre>
</div>
</div>
<div class="section" id="why-can-t-i-share-pickled-objectids-between-some-versions-of-python-2-and-3">
<h2><a class="toc-backref" href="#id4">Why can’t I share pickled ObjectIds between some versions of Python 2 and 3?</a><a class="headerlink" href="#why-can-t-i-share-pickled-objectids-between-some-versions-of-python-2-and-3" title="Permalink to this headline">¶</a></h2>
<p>Instances of <a class="reference internal" href="api/bson/objectid.html#bson.objectid.ObjectId" title="bson.objectid.ObjectId"><tt class="xref py py-class docutils literal"><span class="pre">ObjectId</span></tt></a> pickled using Python 2
can always be unpickled using Python 3. Due to
<a class="reference external" href="http://bugs.python.org/issue13505">http://bugs.python.org/issue13505</a>
you must use Python 3.2.3 or newer to pickle instances of ObjectId if you
need to unpickle them in Python 2.</p>
<p>If you pickled an ObjectId using Python 2 and want to unpickle it using
Python 3 you must pass <tt class="docutils literal"><span class="pre">encoding='latin-1'</span></tt> to pickle.loads:</p>
<div class="highlight-python"><pre>Python 2.7.3 (default, Apr 12 2012, 10:35:17)
[GCC 4.5.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> from bson.objectid import ObjectId
>>> oid = ObjectId()
>>> oid
ObjectId('4f919ba2fba5225b84000000')
>>> pickle.dumps(oid)
'ccopy_reg\n_reconstructor\np0\n(cbson.objectid\...'
Python 3.1.4 (default, Mar 21 2012, 14:34:01)
[GCC 4.5.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> pickle.loads(b'ccopy_reg\n_reconstructor\np0\n(cbson.objectid\...', encoding='latin-1')
ObjectId('4f919ba2fba5225b84000000')</pre>
</div>
<p>If you need to pickle ObjectIds using Python 3 and unpickle them using Python 2
you must use Python 3.2.3 or newer and <tt class="docutils literal"><span class="pre">protocol</span> <span class="pre"><=</span> <span class="pre">2</span></tt>:</p>
<div class="highlight-python"><pre>Python 3.2.3 (v3.2.3:3d0686d90f55, Apr 10 2012, 11:25:50)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> from bson.objectid import ObjectId
>>> oid = ObjectId()
>>> oid
ObjectId('4f96f20c430ee6bd06000000')
>>> pickle.dumps(oid, protocol=2)
b'\x80\x02cbson.objectid\nObjectId\nq\x00)\x81q\x01c_codecs\nencode\...'
Python 2.4.4 (#1, Oct 18 2006, 10:34:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> pickle.loads('\x80\x02cbson.objectid\nObjectId\nq\x00)\x81q\x01c_codecs\nencode\...')
ObjectId('4f96f20c430ee6bd06000000')</pre>
</div>
<p>Unfortunately this won’t work if you pickled the ObjectId using a Python 3
version older than 3.2.3:</p>
<div class="highlight-python"><pre>Python 3.2.2 (default, Mar 21 2012, 14:32:23)
[GCC 4.5.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> from bson.objectid import ObjectId
>>> oid = ObjectId()
>>> pickle.dumps(oid, protocol=2)
b'\x80\x02cbson.objectid\nObjectId\nq\x00)\x81q\x01c__builtin__\nbytes\...'
Python 2.4.6 (#1, Apr 12 2012, 14:48:24)
[GCC 4.5.3] on linux3
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> pickle.loads('\x80\x02cbson.objectid\nObjectId\nq\x00)\x81q\x01c__builtin__\nbytes\...')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/pickle.py", line 1394, in loads
return Unpickler(file).load()
File "/usr/lib/python2.4/pickle.py", line 872, in load
dispatch[key](self)
File "/usr/lib/python2.4/pickle.py", line 1104, in load_global
klass = self.find_class(module, name)
File "/usr/lib/python2.4/pickle.py", line 1140, in find_class
klass = getattr(mod, name)
AttributeError: 'module' object has no attribute 'bytes'</pre>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p>Unpickling in Python 2.6 or 2.7 an ObjectId pickled in a Python 3 version
older than 3.2.3 will seem to succeed but the resulting ObjectId instance
will contain garbage data.</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">pickle</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="s">'</span><span class="se">\x80\x02</span><span class="s">cbson.objectid</span><span class="se">\n</span><span class="s">ObjectId</span><span class="se">\n</span><span class="s">q</span><span class="se">\x00</span><span class="s">)</span><span class="se">\x81</span><span class="s">q</span><span class="se">\x01</span><span class="s">c__builtin__</span><span class="se">\n</span><span class="s">bytes\...)</span>
<span class="go">ObjectId('5b37392c203135302c203234362c2034352c203235312c203136352c2033342c203532...')</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="why-do-i-get-a-syntax-error-importing-pymongo-after-installing-from-source">
<h2><a class="toc-backref" href="#id5">Why do I get a syntax error importing pymongo after installing from source?</a><a class="headerlink" href="#why-do-i-get-a-syntax-error-importing-pymongo-after-installing-from-source" title="Permalink to this headline">¶</a></h2>
<p>PyMongo makes use of the 2to3 tool to translate much of its code to valid
Python 3 syntax at install time. The translated modules are written to the
build subdirectory before being installed, leaving the original source files
intact. If you start the python interactive shell from the top level source
directory after running <tt class="docutils literal"><span class="pre">python</span> <span class="pre">setup.py</span> <span class="pre">install</span></tt> the untranslated modules
will be the first thing in your path. Importing pymongo will result in an
exception similar to:</p>
<div class="highlight-python"><pre>Python 3.1.5 (default, Jun 2 2012, 12:24:49)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pymongo/__init__.py", line 58, in <module>
version = get_version_string()
File "pymongo/__init__.py", line 54, in get_version_string
if isinstance(version_tuple[-1], basestring):
NameError: global name 'basestring' is not defined</pre>
</div>
<p>Note the path in the traceback (<tt class="docutils literal"><span class="pre">pymongo/__init__.py</span></tt>). Changing out of the
source directory takes the untranslated modules out of your path:</p>
<div class="highlight-python"><pre>$ cd ..
$ python
Python 3.1.5 (default, Jun 2 2012, 12:24:49)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>> pymongo.__file__
'/home/behackett/py3k/lib/python3.1/site-packages/pymongo-2.2-py3.1-linux-x86_64.egg/pymongo/__init__.py'</pre>
</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="#">Python 3 FAQ</a><ul>
<li><a class="reference internal" href="#what-python-3-versions-are-supported">What Python 3 versions are supported?</a></li>
<li><a class="reference internal" href="#are-there-any-pymongo-behavior-changes-with-python-3">Are there any PyMongo behavior changes with Python 3?</a></li>
<li><a class="reference internal" href="#why-can-t-i-share-pickled-objectids-between-some-versions-of-python-2-and-3">Why can’t I share pickled ObjectIds between some versions of Python 2 and 3?</a></li>
<li><a class="reference internal" href="#why-do-i-get-a-syntax-error-importing-pymongo-after-installing-from-source">Why do I get a syntax error importing pymongo after installing from source?</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="examples/requests.html"
title="previous chapter">Requests</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/python3.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" />
<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="examples/requests.html" title="Requests"
>previous</a> |</li>
<li><a href="index.html">PyMongo 2.6.3 documentation</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2008 - 2012, 10gen, Inc..
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.
</div>
</body>
</html>
|