Skip to content

Commit 53a7bea

Browse files
committed
PYTHON-1022 - Drop support for Python 3.2
This change removes the u() helper from bson.py3compat and all of its uses in the driver and tests. PyPy3 continues to be supported since, even though it is based on python 3.2.5, it has always supported the u string prefix. The README and install docs are now explicit about PyPy(3) support.
1 parent 7afca2f commit 53a7bea

28 files changed

+143
-217
lines changed

CONTRIBUTING.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ that might not be of interest or that has already been addressed.
1919
Supported Interpreters
2020
----------------------
2121

22-
PyMongo supports CPython 2.6, 2.7, 3.2 and newer, and PyPy. Language
22+
PyMongo supports CPython 2.6, 2.7, 3.3+, PyPy, and PyPy3. Language
2323
features not supported by all interpreters can not be used.
2424

2525
Style Guide

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ with PyMongo.
8686
Dependencies
8787
============
8888

89-
PyMongo supports Python 2.6, 2.7, and 3.2+.
89+
PyMongo supports CPython 2.6, 2.7, 3.3+, PyPy, and PyPy3.
9090

9191
Optional dependencies for GSSAPI and TLS:
9292

bson/py3compat.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ def b(s):
3434
# See http://python3porting.com/problems.html#nicer-solutions
3535
return codecs.latin_1_encode(s)[0]
3636

37-
def u(s):
38-
# PY3 strings may already be treated as unicode literals
39-
return s
40-
4137
def bytes_from_hex(h):
4238
return bytes.fromhex(h)
4339

@@ -71,10 +67,6 @@ def b(s):
7167
# See comments above. In python 2.x b('foo') is just 'foo'.
7268
return s
7369

74-
def u(s):
75-
"""Replacement for unicode literal prefix."""
76-
return unicode(s.replace('\\', '\\\\'), 'unicode_escape')
77-
7870
def bytes_from_hex(h):
7971
return h.decode('hex')
8072

doc/faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ thread, all sockets are closed.
8585
Does PyMongo support Python 3?
8686
------------------------------
8787

88-
PyMongo supports Python 3.x where x >= 2. See the :doc:`python3` for details.
88+
PyMongo supports CPython 3.3+ and PyPy3. See the :doc:`python3` for details.
8989

9090
Does PyMongo support asynchronous frameworks like Gevent, asyncio, Tornado, or Twisted?
9191
---------------------------------------------------------------------------------------

doc/installation.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ To upgrade do::
4545
Dependencies
4646
------------
4747

48-
PyMongo supports Python 2.6, 2.7, and 3.2+.
48+
PyMongo supports CPython 2.6, 2.7, 3.3+, PyPy, and PyPy3.
4949

5050
Optional dependencies for GSSAPI and TLS:
5151

@@ -132,7 +132,7 @@ See `http://bugs.python.org/issue11623 <http://bugs.python.org/issue11623>`_
132132
for a more detailed explanation.
133133

134134
**Lion (10.7) and newer** - PyMongo's C extensions can be built against
135-
versions of Python 2.7 >= 2.7.4 or Python 3.x >= 3.2.4 downloaded from
135+
versions of Python 2.7 >= 2.7.4 or Python 3.3+ downloaded from
136136
python.org. In all cases Xcode must be installed with 'UNIX Development
137137
Support'.
138138

@@ -167,7 +167,7 @@ requirements apply to both CPython and ActiveState's ActivePython:
167167
~~~~~~~~~~~~~~
168168

169169
For Python 3.5 and newer install Visual Studio 2015. For Python 3.3 and 3.4
170-
install Visual Studio 2010. For Python 3.2 and older install Visual Studio
170+
install Visual Studio 2010. For Python 2.6 and 2.7 install Visual Studio
171171
2008, or the Microsoft Visual C++ Compiler for Python 2.7. You must use the
172172
full version of Visual Studio 2010 or 2008 as Visual C++ Express does not
173173
provide 64-bit compilers. Make sure that you check the "x64 Compilers and
@@ -180,7 +180,7 @@ For Python 3.5 and newer install Visual Studio 2015.
180180

181181
For Python 3.3 and 3.4 install Visual C++ 2010 Express.
182182

183-
For Python 2.6 through 3.2 install Visual C++ 2008 Express SP1.
183+
For Python 2.6 and 2.7 install Visual C++ 2008 Express SP1.
184184

185185
.. _install-no-c:
186186

doc/python3.rst

Lines changed: 9 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Python 3 FAQ
66
What 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

1111
Are there any PyMongo behavior changes with Python 3?
1212
-----------------------------------------------------
@@ -20,8 +20,8 @@ with subtype 0.
2020
For example, let's insert a :class:`bytes` instance using Python 3 then
2121
read 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

4848
Instances 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

5451
If you pickled an ObjectId using Python 2 and want to unpickle it using
5552
Python 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

7673
If 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\x02cbson.objectid\nObjectId\nq\x00)\x81q\x01c__builtin__\nbytes\...)
134-
ObjectId('5b37392c203135302c203234362c2034352c203235312c203136352c2033342c203532...')
135-
136-

pymongo/bulk.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"""
1919

2020
from bson.objectid import ObjectId
21-
from bson.py3compat import u
2221
from bson.raw_bson import RawBSONDocument
2322
from bson.son import SON
2423
from pymongo.common import (validate_is_mapping,
@@ -50,11 +49,11 @@
5049
# These string literals are used when we create fake server return
5150
# documents client side. We use unicode literals in python 2.x to
5251
# match the actual return values from the server.
53-
_UID = u("_id")
54-
_UCODE = u("code")
55-
_UERRMSG = u("errmsg")
56-
_UINDEX = u("index")
57-
_UOP = u("op")
52+
_UID = u"_id"
53+
_UCODE = u"code"
54+
_UERRMSG = u"errmsg"
55+
_UINDEX = u"index"
56+
_UOP = u"op"
5857

5958

6059
class _Run(object):

pymongo/collection.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
from bson.objectid import ObjectId
2323
from bson.py3compat import (_unicode,
2424
integer_types,
25-
string_type,
26-
u)
25+
string_type)
2726
from bson.raw_bson import RawBSONDocument
2827
from bson.codec_options import CodecOptions
2928
from bson.son import SON
@@ -52,7 +51,7 @@
5251
_ORDERED_TYPES = (SON,)
5352

5453
_NO_OBJ_ERROR = "No matching object found"
55-
_UJOIN = u("%s.%s")
54+
_UJOIN = u"%s.%s"
5655

5756

5857
class ReturnDocument(object):

pymongo/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import bson
2424
from bson.codec_options import CodecOptions
25-
from bson.py3compat import itervalues, string_type, iteritems, u
25+
from bson.py3compat import itervalues, string_type, iteritems
2626
from bson.son import SON
2727
from pymongo import ASCENDING
2828
from pymongo.errors import (CursorNotFound,
@@ -38,7 +38,7 @@
3838
from pymongo.read_concern import DEFAULT_READ_CONCERN
3939

4040

41-
_UUNDER = u("_")
41+
_UUNDER = u"_"
4242

4343
_UNICODE_REPLACE_CODEC_OPTIONS = CodecOptions(
4444
unicode_decode_error_handler='replace')

pymongo/message.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import bson
2828
from bson.codec_options import DEFAULT_CODEC_OPTIONS
29-
from bson.py3compat import b, StringIO, u
29+
from bson.py3compat import b, StringIO
3030
from bson.son import SON
3131
try:
3232
from pymongo import _cmessage
@@ -61,7 +61,7 @@
6161
_DELETE: b'\x04deletes\x00\x00\x00\x00\x00',
6262
}
6363

64-
_UJOIN = u("%s.%s")
64+
_UJOIN = u"%s.%s"
6565

6666

6767
def _randint():

0 commit comments

Comments
 (0)