py2: reduce ram usage

This commit is contained in:
ed 2024-08-01 20:01:42 +00:00
parent 72361c99e1
commit ebb1981803
12 changed files with 45 additions and 5 deletions

View file

@ -67,6 +67,9 @@ if True: # pylint: disable=using-constant-test
from typing import Any, Optional from typing import Any, Optional
if PY2:
range = xrange
try: try:
if os.environ.get("PRTY_NO_TLS"): if os.environ.get("PRTY_NO_TLS"):
raise Exception() raise Exception()

View file

@ -12,7 +12,7 @@ import threading
import time import time
from datetime import datetime 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 .bos import bos
from .cfg import flagdescs, permdescs, vf_bmap, vf_cmap, vf_vmap from .cfg import flagdescs, permdescs, vf_bmap, vf_cmap, vf_vmap
from .pwhash import PWHash from .pwhash import PWHash
@ -56,6 +56,9 @@ if TYPE_CHECKING:
# Vflags: TypeAlias = dict[str, Any] # Vflags: TypeAlias = dict[str, Any]
# Mflags: TypeAlias = dict[str, Vflags] # Mflags: TypeAlias = dict[str, Vflags]
if PY2:
range = xrange
LEELOO_DALLAS = "leeloo_dallas" LEELOO_DALLAS = "leeloo_dallas"

View file

@ -41,6 +41,9 @@ if True: # pylint: disable=using-constant-test
import typing import typing
from typing import Any, Optional, Union from typing import Any, Optional, Union
if PY2:
range = xrange
class FSE(FilesystemError): class FSE(FilesystemError):
def __init__(self, msg: str, severity: int = 0) -> None: def __init__(self, msg: str, severity: int = 0) -> None:

View file

@ -12,7 +12,7 @@ import time
import queue 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: try:
MNFE = ModuleNotFoundError MNFE = ModuleNotFoundError
@ -84,6 +84,9 @@ if TYPE_CHECKING:
if True: # pylint: disable=using-constant-test if True: # pylint: disable=using-constant-test
from typing import Any, Optional from typing import Any, Optional
if PY2:
range = xrange
class HttpSrv(object): class HttpSrv(object):
""" """

View file

@ -12,6 +12,12 @@ from .label import DNSBuffer, DNSLabel
from .ranges import IP4, IP6, H, I, check_bytes from .ranges import IP4, IP6, H, I, check_bytes
try:
range = xrange
except:
pass
class DNSError(Exception): class DNSError(Exception):
pass pass

View file

@ -17,6 +17,7 @@ if not PY2:
U: Callable[[str], str] = str U: Callable[[str], str] = str
else: else:
U = unicode # noqa: F821 # pylint: disable=undefined-variable,self-assigning-variable 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): class Adapter(object):

View file

@ -16,6 +16,11 @@ if True: # pylint: disable=using-constant-test
from typing import Callable, List, Optional, Tuple, Union from typing import Callable, List, Optional, Tuple, Union
try:
range = xrange
except:
pass
def num_char_count_bits(ver: int) -> int: def num_char_count_bits(ver: int) -> int:
return 16 if (ver + 7) // 17 else 8 return 16 if (ver + 7) // 17 else 8

View file

@ -28,7 +28,7 @@ if True: # pylint: disable=using-constant-test
import typing import typing
from typing import Any, Optional, Union 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 .authsrv import BAD_CFG, AuthSrv
from .cert import ensure_cert from .cert import ensure_cert
from .mtag import HAVE_FFMPEG, HAVE_FFPROBE from .mtag import HAVE_FFMPEG, HAVE_FFPROBE
@ -65,6 +65,9 @@ if TYPE_CHECKING:
except: except:
pass pass
if PY2:
range = xrange
class SvcHub(object): class SvcHub(object):
""" """

View file

@ -44,6 +44,9 @@ if True: # pylint: disable=using-constant-test
if TYPE_CHECKING: if TYPE_CHECKING:
from .svchub import SvcHub from .svchub import SvcHub
if PY2:
range = xrange
lg = logging.getLogger("tftp") lg = logging.getLogger("tftp")
debug, info, warning, error = (lg.debug, lg.info, lg.warning, lg.error) debug, info, warning, error = (lg.debug, lg.info, lg.warning, lg.error)

View file

@ -12,7 +12,7 @@ import time
from queue import Queue from queue import Queue
from .__init__ import ANYWIN, TYPE_CHECKING from .__init__ import ANYWIN, PY2, TYPE_CHECKING
from .authsrv import VFS from .authsrv import VFS
from .bos import bos from .bos import bos
from .mtag import HAVE_FFMPEG, HAVE_FFPROBE, au_unpk, ffprobe from .mtag import HAVE_FFMPEG, HAVE_FFPROBE, au_unpk, ffprobe
@ -38,6 +38,9 @@ if True: # pylint: disable=using-constant-test
if TYPE_CHECKING: if TYPE_CHECKING:
from .svchub import SvcHub from .svchub import SvcHub
if PY2:
range = xrange
HAVE_PIL = False HAVE_PIL = False
HAVE_PILF = False HAVE_PILF = False
HAVE_HEIF = False HAVE_HEIF = False

View file

@ -8,7 +8,7 @@ import threading
import time import time
from operator import itemgetter 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 .authsrv import LEELOO_DALLAS, VFS
from .bos import bos from .bos import bos
from .up2k import up2k_wark_from_hashlist from .up2k import up2k_wark_from_hashlist
@ -38,6 +38,9 @@ if True: # pylint: disable=using-constant-test
if TYPE_CHECKING: if TYPE_CHECKING:
from .httpsrv import HttpSrv from .httpsrv import HttpSrv
if PY2:
range = xrange
class U2idx(object): class U2idx(object):
def __init__(self, hsrv: "HttpSrv") -> None: def __init__(self, hsrv: "HttpSrv") -> None:

View file

@ -59,6 +59,10 @@ except:
UTC = _UTC() UTC = _UTC()
if PY2:
range = xrange
if sys.version_info >= (3, 7) or ( if sys.version_info >= (3, 7) or (
sys.version_info >= (3, 6) and platform.python_implementation() == "CPython" sys.version_info >= (3, 6) and platform.python_implementation() == "CPython"
): ):