|
2 | 2 | A selection of cross-compatible functions for Python 2 and 3. |
3 | 3 |
|
4 | 4 | These come from several sources: |
5 | | -* Jinja2 (BSD licensed: see https://github.com/mitsuhiko/jinja2/blob/master/LICENSE |
6 | | -* Pandas compatibility module pandas.compat |
7 | | -* six.py by Benjamin Peterson |
8 | | -* Django |
| 5 | +
|
| 6 | + * Jinja2 (BSD licensed: see |
| 7 | + https://github.com/mitsuhiko/jinja2/blob/master/LICENSE) |
| 8 | + * Pandas compatibility module pandas.compat |
| 9 | + * six.py by Benjamin Peterson |
| 10 | + * Django |
9 | 11 |
|
10 | 12 | This exports useful functions for 2/3 compatible code that are not |
11 | 13 | builtins on Python 3: |
12 | | -* bind_method: binds functions to classes |
13 | | -* ``native_str_to_bytes`` and ``bytes_to_native_str`` |
14 | | -* ``native_str``: always equal to the native platform string object (because |
15 | | - this may be shadowed by imports from future.builtins) |
16 | | -* lists: lrange(), lmap(), lzip(), lfilter() |
17 | | -* iterable method compatibility: iteritems, iterkeys, itervalues |
18 | | - * Uses the original method if available, otherwise uses items, keys, values. |
19 | | -* types: |
20 | | - * text_type: unicode in Python 2, str in Python 3 |
21 | | - * binary_type: str in Python 2, bythes in Python 3 |
22 | | - * string_types: basestring in Python 2, str in Python 3 |
23 | | -
|
24 | | -* bchr(c): |
25 | | - Take an integer and make a 1-character byte string |
26 | | -* bord(c) |
27 | | - Take the result of indexing on a byte string and make an integer |
28 | | -* tobytes(s) |
29 | | - Take a text string, a byte string, or a sequence of characters taken |
30 | | - from a byte string, and make a byte string. |
| 14 | +
|
| 15 | + * bind_method: binds functions to classes |
| 16 | + * ``native_str_to_bytes`` and ``bytes_to_native_str`` |
| 17 | + * ``native_str``: always equal to the native platform string object (because |
| 18 | + this may be shadowed by imports from future.builtins) |
| 19 | + * lists: lrange(), lmap(), lzip(), lfilter() |
| 20 | + * iterable method compatibility: iteritems, iterkeys, itervalues |
| 21 | +
|
| 22 | + * Uses the original method if available, otherwise uses items, keys, values. |
| 23 | +
|
| 24 | + * types: |
| 25 | +
|
| 26 | + * text_type: unicode in Python 2, str in Python 3 |
| 27 | + * binary_type: str in Python 2, bythes in Python 3 |
| 28 | + * string_types: basestring in Python 2, str in Python 3 |
| 29 | +
|
| 30 | + * bchr(c): |
| 31 | + Take an integer and make a 1-character byte string |
| 32 | + * bord(c) |
| 33 | + Take the result of indexing on a byte string and make an integer |
| 34 | + * tobytes(s) |
| 35 | + Take a text string, a byte string, or a sequence of characters taken |
| 36 | + from a byte string, and make a byte string. |
31 | 37 |
|
32 | 38 | This module also defines a simple decorator called |
33 | 39 | ``python_2_unicode_compatible`` (from django.utils.encoding) which |
|
0 commit comments