@@ -6,7 +6,7 @@ Python 3 FAQ
66What Python 3 versions are supported?
77-------------------------------------
88
9- PyMongo supports Python 3.x where x >= 2 .
9+ PyMongo supports CPython 3.3+ and PyPy3 .
1010
1111Are there any PyMongo behavior changes with Python 3?
1212-----------------------------------------------------
@@ -20,8 +20,8 @@ with subtype 0.
2020For example, let's insert a :class: `bytes ` instance using Python 3 then
2121read it back. Notice the byte string is decoded back to :class: `bytes `::
2222
23- Python 3.2 .5 (default, Feb 26 2014, 12:40:25 )
24- [GCC 4.7 .3] on linux2
23+ Python 3.3 .5 (default, Apr 29 2016, 11:04:32 )
24+ [GCC 4.9 .3] on linux
2525 Type "help", "copyright", "credits" or "license" for more information.
2626 >>> import pymongo
2727 >>> c = pymongo.MongoClient()
@@ -46,10 +46,7 @@ Why can't I share pickled ObjectIds between some versions of Python 2 and 3?
4646----------------------------------------------------------------------------
4747
4848Instances of :class: `~bson.objectid.ObjectId ` pickled using Python 2
49- can always be unpickled using Python 3. Due to
50- `http://bugs.python.org/issue13505 <http://bugs.python.org/issue13505 >`_
51- you must use Python 3.2.3 or newer to pickle instances of ObjectId if you
52- need to unpickle them in Python 2.
49+ can always be unpickled using Python 3.
5350
5451If you pickled an ObjectId using Python 2 and want to unpickle it using
5552Python 3 you must pass ``encoding='latin-1' `` to pickle.loads::
@@ -65,19 +62,19 @@ Python 3 you must pass ``encoding='latin-1'`` to pickle.loads::
6562 >>> pickle.dumps(oid)
6663 'ccopy_reg\n_reconstructor\np0\n(cbson.objectid\...'
6764
68- Python 3.2 .5 (default, Feb 26 2014, 12:40:25 )
69- [GCC 4.7 .3] on linux2
65+ Python 3.3 .5 (default, Apr 29 2016, 11:04:32 )
66+ [GCC 4.9 .3] on linux
7067 Type "help", "copyright", "credits" or "license" for more information.
7168 >>> import pickle
7269 >>> pickle.loads(b'ccopy_reg\n_reconstructor\np0\n(cbson.objectid\...', encoding='latin-1')
7370 ObjectId('4f919ba2fba5225b84000000')
7471
7572
7673If you need to pickle ObjectIds using Python 3 and unpickle them using Python 2
77- you must use Python 3.2.3 or newer and ``protocol <= 2 ``::
74+ you must use ``protocol <= 2 ``::
7875
79- Python 3.2.3 (v3.2.3:3d0686d90f55 , Apr 10 2012 , 11:25:50 )
80- [GCC 4.2.1 (Apple Inc. build 5666) (dot 3) ] on darwin
76+ Python 3.3.5 (default , Apr 29 2016 , 11:04:32 )
77+ [GCC 4.9.3 ] on linux
8178 Type "help", "copyright", "credits" or "license" for more information.
8279 >>> import pickle
8380 >>> from bson.objectid import ObjectId
@@ -94,43 +91,3 @@ you must use Python 3.2.3 or newer and ``protocol <= 2``::
9491 >>> pickle.loads('\x80\x02cbson.objectid\nObjectId\nq\x00)\x81q\x01c_codecs\nencode\...')
9592 ObjectId('4f96f20c430ee6bd06000000')
9693
97-
98- Unfortunately this won't work if you pickled the ObjectId using a Python 3
99- version older than 3.2.3::
100-
101- Python 3.2.2 (default, Mar 21 2012, 14:32:23)
102- [GCC 4.5.3] on linux2
103- Type "help", "copyright", "credits" or "license" for more information.
104- >>> import pickle
105- >>> from bson.objectid import ObjectId
106- >>> oid = ObjectId()
107- >>> pickle.dumps(oid, protocol=2)
108- b'\x80\x02cbson.objectid\nObjectId\nq\x00)\x81q\x01c__builtin__\nbytes\...'
109-
110- Python 2.4.6 (#1, Apr 12 2012, 14:48:24)
111- [GCC 4.5.3] on linux3
112- Type "help", "copyright", "credits" or "license" for more information.
113- >>> import pickle
114- >>> pickle.loads('\x80\x02cbson.objectid\nObjectId\nq\x00)\x81q\x01c__builtin__\nbytes\...')
115- Traceback (most recent call last):
116- File "<stdin>", line 1, in ?
117- File "/usr/lib/python2.4/pickle.py", line 1394, in loads
118- return Unpickler(file).load()
119- File "/usr/lib/python2.4/pickle.py", line 872, in load
120- dispatch[key](self)
121- File "/usr/lib/python2.4/pickle.py", line 1104, in load_global
122- klass = self.find_class(module, name)
123- File "/usr/lib/python2.4/pickle.py", line 1140, in find_class
124- klass = getattr(mod, name)
125- AttributeError: 'module' object has no attribute 'bytes'
126-
127- .. warning ::
128-
129- Unpickling in Python 2.6 or 2.7 an ObjectId pickled in a Python 3 version
130- older than 3.2.3 will seem to succeed but the resulting ObjectId instance
131- will contain garbage data.
132-
133- >>> pickle.loads(' \x80\x02 cbson.objectid\n ObjectId\n q\x00 )\x81 q\x01 c__builtin__\n bytes\...)
134- ObjectId('5b37392c203135302c203234362c2034352c203235312c203136352c2033342c203532...')
135-
136-
0 commit comments