File: path_encoding.py

package info (click to toggle)
python-ftputil 5.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 552 kB
  • sloc: python: 5,879; sh: 10; makefile: 6
file content (33 lines) | stat: -rw-r--r-- 1,013 bytes parent folder | download | duplicates (2)
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