Last change
on this file since 1719:560867ae70f0 was
1719:560867ae70f0,
checked in by Stefan Schwarzer <sschwarzer@…>, 2 years 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 | """ |
---|
6 | Help make the same code work in both Python 2 and 3. |
---|
7 | |
---|
8 | Comments given for the Python 2 versions of the helpers apply to |
---|
9 | the Python 3 helpers as well. |
---|
10 | """ |
---|
11 | |
---|
12 | import sys |
---|
13 | |
---|
14 | |
---|
15 | __all__ = ["int_types", "unicode_type", "bytes_type", "bytes_from_ints", |
---|
16 | "default_string_type"] |
---|
17 | |
---|
18 | |
---|
19 | python_version = sys.version_info[0] |
---|
20 | |
---|
21 | |
---|
22 | if 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 | |
---|
33 | else: |
---|
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. |
---|
43 | default_string_type = str |
---|
Note: See
TracBrowser
for help on using the repository browser.