Skip to content

Commit ba95c88

Browse files
authored
Add files via upload
1 parent 3d5c11f commit ba95c88

1 file changed

Lines changed: 40 additions & 75 deletions

File tree

pyfoxfile.py

Lines changed: 40 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
import stat
2727
import zlib
2828
import mmap
29+
import hmac
2930
import base64
3031
import shutil
3132
import socket
3233
import struct
3334
import hashlib
3435
import inspect
3536
import datetime
36-
import tempfile
3737
import logging
3838
import zipfile
3939
import binascii
@@ -346,8 +346,8 @@ def _is_printable(ch):
346346
__use_ini_name__ = "foxfile.ini"
347347
__use_json_file__ = False
348348
__use_json_name__ = "foxfile.json"
349-
if(__use_ini_file__ and __use_json_name__):
350-
__use_json_name__ = False
349+
if(__use_ini_file__ and __use_json_file__):
350+
__use_json_file__ = False
351351
if('PYARCHIVEFILE_CONFIG_FILE' in os.environ and os.path.exists(os.environ['PYARCHIVEFILE_CONFIG_FILE']) and __use_env_file__):
352352
scriptconf = os.environ['PYARCHIVEFILE_CONFIG_FILE']
353353
else:
@@ -622,8 +622,8 @@ def _get(section_dict, key, default=None):
622622

623623
# Deterministic category order (handy for consistent output/printing).
624624
CATEGORY_ORDER = [
625-
"files", "hardlinks", "symlinks", "character", "block",
626-
"directories", "fifo", "sockets", "doors", "ports",
625+
"files", "hardlinks", "symlinks", "characters", "blocks",
626+
"directories", "fifos", "sockets", "doors", "ports",
627627
"whiteouts", "sparsefiles", "junctions", "links", "devices"
628628
]
629629

@@ -808,46 +808,6 @@ def VerbosePrintOutReturn(dbgtxt, outtype="log", dbgenable=True, dgblevel=20):
808808
return dbgtxt
809809

810810

811-
# --- Helpers ---
812-
def _normalize_initial_data(data, isbytes, encoding):
813-
"""Return data in the correct type for write(): bytes (if isbytes) or text (if not)."""
814-
if data is None:
815-
return None
816-
817-
if isbytes:
818-
# Want bytes
819-
if isinstance(data, bytes):
820-
return data
821-
# Py2: str is already bytes, unicode needs encode
822-
if sys.version_info[0] == 2:
823-
try:
824-
unicode # noqa: F821
825-
except NameError:
826-
pass
827-
else:
828-
if isinstance(data, unicode): # noqa: F821
829-
return data.encode(encoding)
830-
# Py3 str -> encode
831-
return str(data).encode(encoding)
832-
else:
833-
# Want text (unicode/str)
834-
if sys.version_info[0] == 2:
835-
try:
836-
unicode # noqa: F821
837-
if isinstance(data, unicode): # noqa: F821
838-
return data
839-
# bytes/str -> decode
840-
return data.decode(encoding) if isinstance(data, str) else unicode(data) # noqa: F821
841-
except NameError:
842-
# Very defensive; shouldn't happen
843-
return data
844-
else:
845-
# Py3: want str
846-
if isinstance(data, bytes):
847-
return data.decode(encoding)
848-
return str(data)
849-
850-
851811
def _split_posix(path_text):
852812
"""Split POSIX paths regardless of OS; return list of components."""
853813
# Normalize leading './'
@@ -1751,51 +1711,56 @@ def MkTempFile(data=None, inmem=__use_inmemfile__, isbytes=True, prefix=__projec
17511711
return f
17521712

17531713

1754-
def _normalize_initial_data(data, isbytes, encoding):
1755-
"""
1756-
Coerce `data` to the correct type for the chosen mode:
1757-
- bytes mode: return `bytes` (Py2: str; Py3: bytes)
1758-
- text mode : return unicode/str (Py2: unicode; Py3: str)
1759-
"""
1714+
def _as_bytes_like(data):
1715+
if isinstance(data, bytes):
1716+
return data
1717+
if isinstance(data, bytearray):
1718+
return bytes(data)
1719+
try:
1720+
mv = memoryview
1721+
except NameError:
1722+
mv = ()
1723+
if mv and isinstance(data, mv):
1724+
return bytes(data)
1725+
return None
1726+
1727+
def _normalize_initial_data(data, isbytes, encoding, *, errors="strict"):
1728+
"""Return bytes (if isbytes) or text (unicode on Py2, str on Py3)."""
17601729
if data is None:
17611730
return None
17621731

17631732
if isbytes:
1764-
# Need a byte sequence
1765-
if isinstance(data, bytes):
1766-
return data
1767-
if isinstance(data, bytearray):
1768-
return bytes(data)
1769-
# memoryview may not exist on very old Py2 builds; guard dynamically
1770-
mv_t = getattr(__builtins__, 'memoryview', type(None))
1771-
if isinstance(data, mv_t):
1772-
return bytes(data)
1773-
if isinstance(data, str):
1774-
# Py2 str is already bytes; Py3 str must be encoded
1775-
return data if PY2 else data.encode(encoding)
1776-
if PY2 and isinstance(data, unicode): # noqa: F821 (unicode only in Py2)
1777-
return data.encode(encoding)
1733+
b = _as_bytes_like(data)
1734+
if b is not None:
1735+
return b
1736+
if PY2:
1737+
if isinstance(data, unicode_type):
1738+
return data.encode(encoding, errors)
1739+
if isinstance(data, str): # Py2: str is already bytes-like
1740+
return data
1741+
else:
1742+
if isinstance(data, str):
1743+
return data.encode(encoding, errors)
17781744
raise TypeError("data must be bytes-like or text for isbytes=True (got %r)" % (type(data),))
17791745
else:
1780-
# Need text (unicode in Py2, str in Py3)
17811746
if PY2:
1782-
if isinstance(data, unicode): # noqa: F821
1747+
if isinstance(data, unicode_type):
17831748
return data
1749+
b = _as_bytes_like(data)
1750+
if b is not None:
1751+
return b.decode(encoding, errors)
17841752
if isinstance(data, str):
1785-
return data.decode(encoding)
1786-
if isinstance(data, bytearray):
1787-
return bytes(data).decode(encoding)
1788-
mv_t = getattr(__builtins__, 'memoryview', type(None))
1789-
if isinstance(data, mv_t):
1790-
return bytes(data).decode(encoding)
1753+
return data.decode(encoding, errors)
17911754
raise TypeError("data must be unicode or bytes-like for text mode (got %r)" % (type(data),))
17921755
else:
17931756
if isinstance(data, str):
17941757
return data
1795-
if isinstance(data, (bytes, bytearray, memoryview)):
1796-
return bytes(data).decode(encoding)
1758+
b = _as_bytes_like(data)
1759+
if b is not None:
1760+
return b.decode(encoding, errors)
17971761
raise TypeError("data must be str or bytes-like for text mode (got %r)" % (type(data),))
17981762

1763+
17991764
def MkTempFile(data=None,
18001765
inmem=True,
18011766
isbytes=True,

0 commit comments

Comments
 (0)