PYTHON-686 - Finish updating docs related to python 3.
Mostly removing references to 2to3, which we no longer use.
This commit is contained in:
parent
b26459cd6a
commit
0a55f923c4
@ -19,13 +19,8 @@ that might not be of interest or that has already been addressed.
|
||||
Supported Interpreters
|
||||
----------------------
|
||||
|
||||
PyMongo supports CPython 2.4 and newer, PyPy, and Jython. Language
|
||||
features not supported by all interpreters can not be used (e.g.
|
||||
the `with statement
|
||||
<http://docs.python.org/reference/compound_stmts.html#the-with-statement>`_
|
||||
is not supported in Python 2.4). Please also ensure that your code is
|
||||
properly converted by `2to3 <http://docs.python.org/library/2to3.html>`_ for
|
||||
Python 3 support.
|
||||
PyMongo supports CPython 2.6, 2.7, 3.2 and newer, and PyPy. Language
|
||||
features not supported by all interpreters can not be used.
|
||||
|
||||
Style Guide
|
||||
-----------
|
||||
|
||||
@ -278,9 +278,8 @@ def _get_timestamp(
|
||||
|
||||
|
||||
def _get_long(data, position, as_class, tz_aware, uuid_subtype, compile_re):
|
||||
# Have to cast to long; on 32-bit unpack may return an int.
|
||||
# 2to3 will change long to int. That's fine since long doesn't
|
||||
# exist in python3.
|
||||
# Have to cast to long (for python 2.x); on 32-bit unpack may return
|
||||
# an int.
|
||||
value = long(struct.unpack("<q", data[position:position + 8])[0])
|
||||
position += 8
|
||||
return value, position
|
||||
@ -304,7 +303,7 @@ _element_getter = {
|
||||
BSONCWS: _get_code_w_scope,
|
||||
BSONINT: _get_int, # number_int
|
||||
BSONTIM: _get_timestamp,
|
||||
BSONLON: _get_long, # Same as _get_int after 2to3 runs.
|
||||
BSONLON: _get_long,
|
||||
BSONMIN: lambda u, v, w, x, y, z: (MinKey(), v),
|
||||
BSONMAX: lambda u, v, w, x, y, z: (MaxKey(), v)}
|
||||
|
||||
@ -424,8 +423,6 @@ def _element_to_bson(key, value, check_keys, uuid_subtype):
|
||||
if value > MAX_INT32 or value < MIN_INT32:
|
||||
return BSONLON + name + struct.pack("<q", value)
|
||||
return BSONINT + name + struct.pack("<i", value)
|
||||
# 2to3 will convert long to int here since there is no long in python3.
|
||||
# That's OK. The previous if block will match instead.
|
||||
if not PY3 and isinstance(value, long):
|
||||
if value > MAX_INT64 or value < MIN_INT64:
|
||||
raise OverflowError("BSON can only handle up to 8-byte ints")
|
||||
|
||||
@ -134,39 +134,3 @@ version older than 3.2.3::
|
||||
ObjectId('5b37392c203135302c203234362c2034352c203235312c203136352c2033342c203532...')
|
||||
|
||||
|
||||
Why do I get a syntax error importing pymongo after installing from source?
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
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 ``python setup.py install`` the untranslated modules
|
||||
will be the first thing in your path. Importing pymongo will result in an
|
||||
exception similar to::
|
||||
|
||||
Python 3.2.5 (default, Feb 26 2014, 12:40:25)
|
||||
[GCC 4.7.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 77, in <module>
|
||||
version = get_version_string()
|
||||
File "pymongo/__init__.py", line 73, in get_version_string
|
||||
if isinstance(version_tuple[-1], basestring):
|
||||
NameError: global name 'basestring' is not defined
|
||||
|
||||
Note the path in the traceback (``pymongo/__init__.py``). Changing out of the
|
||||
source directory takes the untranslated modules out of your path::
|
||||
|
||||
$ cd ..
|
||||
$ python
|
||||
Python 3.2.5 (default, Feb 26 2014, 12:40:25)
|
||||
[GCC 4.7.3] on linux2
|
||||
Type "help", "copyright", "credits" or "license" for more information.
|
||||
>>> import pymongo
|
||||
>>> pymongo.__file__
|
||||
'/home/behackett/py3k/lib/python3.2/site-packages/pymongo-2.7-py3.2-linux-x86_64.egg/pymongo/__init__.py'
|
||||
|
||||
|
||||
|
||||
@ -1022,7 +1022,7 @@ class Collection(common.BaseObject):
|
||||
warnings.warn("ttl is deprecated. Please use cache_for instead.",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
|
||||
# The types supported by datetime.timedelta. 2to3 removes long.
|
||||
# The types supported by datetime.timedelta.
|
||||
if not (isinstance(cache_for, integer_types) or
|
||||
isinstance(cache_for, float)):
|
||||
raise TypeError("cache_for must be an integer or float.")
|
||||
|
||||
@ -384,7 +384,6 @@ class TestGridfs(unittest.TestCase):
|
||||
self.assertEqual(3, self.fs.find({"filename":"two"}).count())
|
||||
self.assertEqual(4, self.fs.find().count())
|
||||
cursor = self.fs.find(timeout=False).sort("uploadDate", -1).skip(1).limit(2)
|
||||
# 2to3 hint...
|
||||
gout = next(cursor)
|
||||
self.assertEqual(b"test1", gout.read())
|
||||
cursor.rewind()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user