source: ftputil/compat.py @ 1719:560867ae70f0

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