source: ftputil/compat.py @ 1564:c5b353a1c23d

Last change on this file since 1564:c5b353a1c23d was 1564:c5b353a1c23d, checked in by Stefan Schwarzer <sschwarzer@…>, 5 years ago
List contributors in `doc/contributors.txt`. So far, individual files had copyright notices for contributors. However, this makes it difficult to properly adapt files in case of refactoring: If a piece of code is moved to another file, I would need to find out if this code was contributed by someone else and change the copyright notice in the target file accordingly. With the new approach, every file refers to the file `doc/contributors.txt`, which contains the names of contributors.
File size: 1009 bytes
Line 
1# encoding: utf-8
2# Copyright (C) 2011-2013, 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
13from __future__ import unicode_literals
14
15import sys
16
17
18__all__ = ["int_types", "unicode_type", "bytes_type", "bytes_from_ints",
19           "default_string_type"]
20
21
22python_version = sys.version_info[0]
23
24
25if python_version == 2:
26
27    int_types = (int, long)
28
29    unicode_type = unicode
30    bytes_type = str
31
32    def bytes_from_ints(int_list):
33        """Return a `bytes` object from a list of integers."""
34        return b"".join((chr(i) for i in int_list))
35
36else:
37
38    int_types = (int,)
39
40    unicode_type = str
41    bytes_type = bytes
42
43    bytes_from_ints = bytes
44
45# For Python 2 `str` means byte strings, for Python 3 unicode strings.
46default_string_type = str
Note: See TracBrowser for help on using the repository browser.