~sschwarzer/ftputil

ftputil/ftputil/path_encoding.py -rw-r--r-- 1013 bytes
77f2ca24Stefan Schwarzer Move item "Push to repository" a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Copyright (C) 2021, Stefan Schwarzer <sschwarzer@sschwarzer.net>
# and ftputil contributors (see `doc/contributors.txt`)
# See the file LICENSE for licensing terms.

"""
Compatibility code for Python versions <= 3.8 vs. >= 3.9

Python 3.9 changed the default encoding for FTP remote paths from latin-1 to
UTF-8 which causes a few headaches for ftputil.
"""

import sys


__all__ = ["DEFAULT_ENCODING", "RUNNING_UNDER_PY39_AND_UP", "FTPLIB_DEFAULT_ENCODING"]


RUNNING_UNDER_PY39_AND_UP = (sys.version_info.major, sys.version_info.minor) >= (3, 9)

# FTP path default encoding for Python 3.8 and below
FTPLIB_PY38_ENCODING = "latin-1"

# FTP path default encoding for Python 3.9 and above
FTPLIB_PY39_ENCODING = "utf-8"

# Default encoding for ftputil. Stay compatible to the behavior of former
# ftputil versions and Python <= 3.8.
DEFAULT_ENCODING = FTPLIB_PY38_ENCODING

if RUNNING_UNDER_PY39_AND_UP:
    FTPLIB_DEFAULT_ENCODING = FTPLIB_PY39_ENCODING
else:
    FTPLIB_DEFAULT_ENCODING = FTPLIB_PY38_ENCODING