Lines Matching refs:Python
1 Six: Python 2 and 3 Compatibility Library
5 :synopsis: Python 2 and 3 compatibility
11 Six provides simple utilities for wrapping over differences between Python 2 and
12 Python 3. It is intended to support codebases that work on both Python 2 and 3
13 without modification. six consists of only one Python file, so it is painless
36 A boolean indicating if the code is running on Python 2.
40 A boolean indicating if the code is running on Python 3.
46 Six provides constants that may differ between Python versions. Ones ending
53 Possible class types. In Python 2, this encompasses old-style
54 :data:`py2:types.ClassType` and new-style ``type`` classes. In Python 3,
60 Possible integer types. In Python 2, this is :func:`py2:long` and
61 :func:`py2:int`, and in Python 3, just :func:`py3:int`.
66 Possible types for text data. This is :func:`py2:basestring` in Python 2 and
67 :func:`py3:str` in Python 3.
73 Python 2 and :func:`py3:str` in Python 3.
78 Type for representing binary data. This is :func:`py2:str` in Python 2 and
79 :func:`py3:bytes` in Python 3. Python 2.6 and 2.7 include ``bytes`` as a
80 builtin alias of ``str``, so six’s version is only necessary for Python 2.5
87 This is equivalent to :data:`py3:sys.maxsize` in Python 2.6 and later
89 :data:`py2:sys.maxint` in Python 2. There is no direct equivalent to
90 :data:`py2:sys.maxint` in Python 3 because its integer type has no limits
110 Python 3 renamed the attributes of several interpreter data structures. The
117 Get the function out of unbound method *meth*. In Python 3, unbound methods
142 to ``func.__closure__`` on Python 2.6+ and ``func.func_closure`` on Python
149 ``func.__code__`` on Python 2.6+ and ``func.func_code`` on Python 2.5.
155 ``func.__defaults__`` on Python 2.6+ and ``func.func_defaults`` on Python
162 Python 2.6+ and ``func.func_globals`` on Python 2.5.
170 in Python 2 and ``next(it)`` in Python 3. Python 2.6 and above have a
171 builtin ``next`` function, so six's version is only necessary for Python 2.5
177 Check if *obj* can be called. Note ``callable`` has returned in Python 3.2,
178 so using six's version is only necessary when supporting Python 3.0 or 3.1.
184 ``dictionary.iterkeys()`` on Python 2 and ``dictionary.keys()`` on
185 Python 3. *kwargs* are passed through to the underlying method.
191 ``dictionary.itervalues()`` on Python 2 and ``dictionary.values()`` on
192 Python 3. *kwargs* are passed through to the underlying method.
198 ``dictionary.iteritems()`` on Python 2 and ``dictionary.items()`` on
199 Python 3. *kwargs* are passed through to the underlying method.
204 Calls ``dictionary.iterlists()`` on Python 2 and ``dictionary.lists()`` on
205 Python 3. No builtin Python mapping type has such a method; this method is
214 :meth:`py2:dict.viewkeys` on Python 2.7 and :meth:`py3:dict.keys` on
215 Python 3.
221 :meth:`py2:dict.viewvalues` on Python 2.7 and :meth:`py3:dict.values` on
222 Python 3.
228 :meth:`py2:dict.viewitems` on Python 2.7 and :meth:`py3:dict.items` on
229 Python 3.
234 Return a method object wrapping *func* and bound to *obj*. On both Python 2
236 this wrapper exists is that on Python 2, the ``MethodType`` constructor
242 Return an unbound method object wrapping *func*. In Python 2, this will
243 return a :func:`py2:types.MethodType` object. In Python 3, unbound methods
250 and subclasses provide a ``__next__`` method. In Python 2, :class:`Iterator`
254 ``__next__``. :class:`Iterator` is empty on Python 3. (In fact, it is just
260 This is Python 3.2's :func:`py3:functools.wraps` decorator. It sets the
270 Python 2 and 3.
282 Python 3's :func:`py3:exec` doesn't take keyword arguments, so calling
294 In Python 2, this function imitates Python 3's :func:`py3:print` by not
301 Raise an exception from a context. On Python 3, this is equivalent to
302 ``raise exc_value from exc_value_from``. On Python 2, which does not support
313 Python will attach the call frame of :func:`reraise` to whatever traceback is
351 on Python 3 or ::
356 on Python 2.
358 Note that class decorators require Python 2.6. However, the effect of the
359 decorator can be emulated on Python 2.5 like so::
369 Python 3 enforces the distinction between byte strings and text strings far more
370 rigorously than Python 2 does; binary data cannot be automatically coerced to
372 string data in all Python versions.
378 Python 2, :func:`b` returns an 8-bit string. In Python 3, *data* is encoded
384 Since all Python versions 2.6 and after support the ``b`` prefix,
391 In Python 2, :func:`u` returns unicode, and in Python 3, a string. Also, in
392 Python 2, the string is decoded with the ``unicode-escape`` codec, which
398 In Python 3.3, the ``u`` prefix has been reintroduced. Code that only
399 supports Python 3 versions of 3.3 and higher thus does not need
404 On Python 2, :func:`u` doesn't know what the encoding of the literal
413 equivalent to :func:`py2:unichr` on Python 2 and :func:`py3:chr` on Python 3.
419 equivalent to :func:`py2:chr` in Python 2 and ``bytes((i,))`` in Python 3.
425 ``ord(bs[0])`` on Python 2 and ``bs[0]`` on Python 3.
431 indexing a bytes object in Python 3.
437 a bytes object iterator in Python 3.
461 :class:`py2:StringIO.StringIO` in Python 2 and :class:`py3:io.StringIO` in
462 Python 3.
467 This is a fake file object for binary data. In Python 2, it's an alias for
468 :class:`py2:StringIO.StringIO`, but in Python 3, it's an alias for
475 Python 3, the decorator does nothing. On Python 2, it aliases the
494 Note these functions are only available on Python 2.7 or later.
498 Alias for :meth:`~py3:unittest.TestCase.assertCountEqual` on Python 3 and
499 :meth:`~py2:unittest.TestCase.assertItemsEqual` on Python 2.
504 Alias for :meth:`~py3:unittest.TestCase.assertRaisesRegex` on Python 3 and
505 :meth:`~py2:unittest.TestCase.assertRaisesRegexp` on Python 2.
510 Alias for :meth:`~py3:unittest.TestCase.assertRegex` on Python 3 and
511 :meth:`~py2:unittest.TestCase.assertRegexpMatches` on Python 2.
515 Alias for :meth:`~py3:unittest.TestCase.assertNotRegex` on Python 3 and
516 :meth:`~py2:unittest.TestCase.assertNotRegexpMatches` on Python 2.
525 Python 3 reorganized the standard library and moved several functions to
528 Python 2 or 3, write::
538 Python 3. When the new Python 3 name is a package, the components of the name
541 Python 2 name is retained. This is so the appropriate modules can be found when
542 running on Python 2. For example, ``BaseHTTPServer`` which is in
543 ``http.server`` in Python 3 is aliased as ``BaseHTTPServer``.
545 Some modules which had two implementations have been merged in Python 3. For
546 example, ``cPickle`` no longer exists in Python 3; it was merged with
548 Python 2 and the merged module in Python 3.
551 been combined in the :mod:`py3:urllib` package in Python 3. The
553 functionality; its structure mimics the structure of the Python 3
564 will fail if the underlying module is not available in the Python
581 | Name | Python 2 name | Python 3 name …
652 | | | on Python 3.4+ …
727 …ff from :mod:`py2:urlparse` and :mod:`py2:urllib` in Python 2 and :mod:`py3:urllib.parse` in Pytho…
729 Contains functions from Python 3's :mod:`py3:urllib.parse` and Python 2's:
766 …uff from :mod:`py2:urllib` and :mod:`py2:urllib2` in Python 2 and :mod:`py3:urllib.error` in Pytho…
768 Contains exceptions from Python 3's :mod:`py3:urllib.error` and Python 2's:
784 …ff from :mod:`py2:urllib` and :mod:`py2:urllib2` in Python 2 and :mod:`py3:urllib.request` in Pyth…
786 Contains items from Python 3's :mod:`py3:urllib.request` and Python 2's:
834 :synopsis: Stuff from :mod:`py2:urllib` in Python 2 and :mod:`py3:urllib.response` in Python 3
836 Contains classes from Python 3's :mod:`py3:urllib.response` and Python 2's:
873 modules in Python 2 and 3. *old_mod* is the name of the Python 2 module.
874 *new_mod* is the name of the Python 3 module.
880 attributes in Python 2 and 3. *old_mod* is the name of the Python 2 module.
881 *new_mod* is the name of the Python 3 module. If *new_attr* is not given, it