diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 9392713d..e644b8e3 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -67,6 +67,9 @@ if True: # pylint: disable=using-constant-test from typing import Any, Optional +if PY2: + range = xrange + try: if os.environ.get("PRTY_NO_TLS"): raise Exception() diff --git a/copyparty/authsrv.py b/copyparty/authsrv.py index 8f053f68..0965103e 100644 --- a/copyparty/authsrv.py +++ b/copyparty/authsrv.py @@ -12,7 +12,7 @@ import threading import time from datetime import datetime -from .__init__ import ANYWIN, TYPE_CHECKING, WINDOWS, E +from .__init__ import ANYWIN, PY2, TYPE_CHECKING, WINDOWS, E from .bos import bos from .cfg import flagdescs, permdescs, vf_bmap, vf_cmap, vf_vmap from .pwhash import PWHash @@ -56,6 +56,9 @@ if TYPE_CHECKING: # Vflags: TypeAlias = dict[str, Any] # Mflags: TypeAlias = dict[str, Vflags] +if PY2: + range = xrange + LEELOO_DALLAS = "leeloo_dallas" diff --git a/copyparty/ftpd.py b/copyparty/ftpd.py index fdedab44..d034190a 100644 --- a/copyparty/ftpd.py +++ b/copyparty/ftpd.py @@ -41,6 +41,9 @@ if True: # pylint: disable=using-constant-test import typing from typing import Any, Optional, Union +if PY2: + range = xrange + class FSE(FilesystemError): def __init__(self, msg: str, severity: int = 0) -> None: diff --git a/copyparty/httpsrv.py b/copyparty/httpsrv.py index 0350de44..9d28e374 100644 --- a/copyparty/httpsrv.py +++ b/copyparty/httpsrv.py @@ -12,7 +12,7 @@ import time import queue -from .__init__ import ANYWIN, CORES, EXE, MACOS, TYPE_CHECKING, EnvParams, unicode +from .__init__ import ANYWIN, CORES, EXE, MACOS, PY2, TYPE_CHECKING, EnvParams, unicode try: MNFE = ModuleNotFoundError @@ -84,6 +84,9 @@ if TYPE_CHECKING: if True: # pylint: disable=using-constant-test from typing import Any, Optional +if PY2: + range = xrange + class HttpSrv(object): """ diff --git a/copyparty/stolen/dnslib/dns.py b/copyparty/stolen/dnslib/dns.py index 2bd6b680..74f26ad7 100644 --- a/copyparty/stolen/dnslib/dns.py +++ b/copyparty/stolen/dnslib/dns.py @@ -12,6 +12,12 @@ from .label import DNSBuffer, DNSLabel from .ranges import IP4, IP6, H, I, check_bytes +try: + range = xrange +except: + pass + + class DNSError(Exception): pass diff --git a/copyparty/stolen/ifaddr/_shared.py b/copyparty/stolen/ifaddr/_shared.py index 519c4598..1f8ae931 100644 --- a/copyparty/stolen/ifaddr/_shared.py +++ b/copyparty/stolen/ifaddr/_shared.py @@ -17,6 +17,7 @@ if not PY2: U: Callable[[str], str] = str else: U = unicode # noqa: F821 # pylint: disable=undefined-variable,self-assigning-variable + range = xrange # noqa: F821 # pylint: disable=undefined-variable,self-assigning-variable class Adapter(object): diff --git a/copyparty/stolen/qrcodegen.py b/copyparty/stolen/qrcodegen.py index 98dc804b..3bee4dc9 100644 --- a/copyparty/stolen/qrcodegen.py +++ b/copyparty/stolen/qrcodegen.py @@ -16,6 +16,11 @@ if True: # pylint: disable=using-constant-test from typing import Callable, List, Optional, Tuple, Union +try: + range = xrange +except: + pass + def num_char_count_bits(ver: int) -> int: return 16 if (ver + 7) // 17 else 8 diff --git a/copyparty/svchub.py b/copyparty/svchub.py index aed389ad..21581a7d 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -28,7 +28,7 @@ if True: # pylint: disable=using-constant-test import typing from typing import Any, Optional, Union -from .__init__ import ANYWIN, EXE, MACOS, TYPE_CHECKING, E, EnvParams, unicode +from .__init__ import ANYWIN, EXE, MACOS, PY2, TYPE_CHECKING, E, EnvParams, unicode from .authsrv import BAD_CFG, AuthSrv from .cert import ensure_cert from .mtag import HAVE_FFMPEG, HAVE_FFPROBE @@ -65,6 +65,9 @@ if TYPE_CHECKING: except: pass +if PY2: + range = xrange + class SvcHub(object): """ diff --git a/copyparty/tftpd.py b/copyparty/tftpd.py index 785a4b5b..5e0fea30 100644 --- a/copyparty/tftpd.py +++ b/copyparty/tftpd.py @@ -44,6 +44,9 @@ if True: # pylint: disable=using-constant-test if TYPE_CHECKING: from .svchub import SvcHub +if PY2: + range = xrange + lg = logging.getLogger("tftp") debug, info, warning, error = (lg.debug, lg.info, lg.warning, lg.error) diff --git a/copyparty/th_srv.py b/copyparty/th_srv.py index aab47e4d..51e6f2e9 100644 --- a/copyparty/th_srv.py +++ b/copyparty/th_srv.py @@ -12,7 +12,7 @@ import time from queue import Queue -from .__init__ import ANYWIN, TYPE_CHECKING +from .__init__ import ANYWIN, PY2, TYPE_CHECKING from .authsrv import VFS from .bos import bos from .mtag import HAVE_FFMPEG, HAVE_FFPROBE, au_unpk, ffprobe @@ -38,6 +38,9 @@ if True: # pylint: disable=using-constant-test if TYPE_CHECKING: from .svchub import SvcHub +if PY2: + range = xrange + HAVE_PIL = False HAVE_PILF = False HAVE_HEIF = False diff --git a/copyparty/u2idx.py b/copyparty/u2idx.py index bde7bdbf..2e340da6 100644 --- a/copyparty/u2idx.py +++ b/copyparty/u2idx.py @@ -8,7 +8,7 @@ import threading import time from operator import itemgetter -from .__init__ import ANYWIN, TYPE_CHECKING, unicode +from .__init__ import ANYWIN, PY2, TYPE_CHECKING, unicode from .authsrv import LEELOO_DALLAS, VFS from .bos import bos from .up2k import up2k_wark_from_hashlist @@ -38,6 +38,9 @@ if True: # pylint: disable=using-constant-test if TYPE_CHECKING: from .httpsrv import HttpSrv +if PY2: + range = xrange + class U2idx(object): def __init__(self, hsrv: "HttpSrv") -> None: diff --git a/copyparty/util.py b/copyparty/util.py index a0589760..89de4430 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -59,6 +59,10 @@ except: UTC = _UTC() +if PY2: + range = xrange + + if sys.version_info >= (3, 7) or ( sys.version_info >= (3, 6) and platform.python_implementation() == "CPython" ):