source: ftputil/compat.py @ 1713:f146a1ea66aa

Last change on this file since 1713:f146a1ea66aa was 1713:f146a1ea66aa, checked in by Stefan Schwarzer <sschwarzer@…>, 12 months ago
Remove `__future__` imports With the switch to Python 3.x-only, the `__future__` imports are no longer needed. Update copyright years along with the `__future__` import removal.
File size: 968 bytes
Line 
1# encoding: utf-8
2# Copyright (C) 2011-2018, Stefan Schwarzer <sschwarzer@sschwarzer.net>
3# and ftputil contributors (see `doc/contributors.txt`)
4# See the file LICENSE for licensing terms.
5
6"""
7Help make the same code work in both Python 2 and 3.
8
9Comments given for the Python 2 versions of the helpers apply to
10the Python 3 helpers as well.
11"""
12
13import sys
14
15
16__all__ = ["int_types", "unicode_type", "bytes_type", "bytes_from_ints",
17           "default_string_type"]
18
19
20python_version = sys.version_info[0]
21
22
23if python_version == 2:
24
25    int_types = (int, long)
26
27    unicode_type = unicode
28    bytes_type = str
29
30    def bytes_from_ints(int_list):
31        """Return a `bytes` object from a list of integers."""
32        return b"".join((chr(i) for i in int_list))
33
34else:
35
36    int_types = (int,)
37
38    unicode_type = str
39    bytes_type = bytes
40
41    bytes_from_ints = bytes
42
43# For Python 2 `str` means byte strings, for Python 3 unicode strings.
44default_string_type = str
Note: See TracBrowser for help on using the repository browser.