Skip to content

Commit f5518da

Browse files
committed
Small update
1 parent edd226d commit f5518da

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

pyarchivefile/pyfile.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,35 @@
6060
except Exception:
6161
shared_memory = None
6262

63+
def running_interactively():
64+
main = sys.modules.get("__main__")
65+
no_main_file = not hasattr(main, "__file__")
66+
interactive_flag = bool(getattr(sys.flags, "interactive", 0))
67+
return no_main_file or interactive_flag
68+
69+
if running_interactively():
70+
logging.basicConfig(format="%(message)s", stream=PY_STDOUT_TEXT, level=logging.DEBUG)
71+
72+
# Windows-specific setup
73+
if os.name == "nt":
74+
def _wrap(stream):
75+
buf = getattr(stream, "buffer", None)
76+
is_tty = getattr(stream, "isatty", lambda: False)()
77+
if buf is not None and is_tty:
78+
try:
79+
return io.TextIOWrapper(buf, encoding="UTF-8", errors="replace", line_buffering=True)
80+
except Exception:
81+
return stream
82+
return stream
83+
sys.stdout = _wrap(sys.stdout)
84+
sys.stderr = _wrap(sys.stderr)
85+
86+
hashlib_guaranteed = False
87+
# Environment setup
88+
os.environ["PYTHONIOENCODING"] = "UTF-8"
89+
90+
from io import UnsupportedOperation
91+
6392
__upload_proto_support__ = "^(http|https|ftp|ftps|sftp|scp|tcp|udp|sctp|data|file|bt|rfcomm|l2cap|bluetooth|unixstream|unixdgram|unixseqpacket)://"
6493
__download_proto_support__ = "^(http|https|ftp|ftps|sftp|scp|tcp|udp|sctp|data|file|bt|rfcomm|l2cap|bluetooth|unixstream|unixdgram|unixseqpacket)://"
6594
if(platform.python_implementation() != ""):

pyarchivefile/pywwwget.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ def randbits(k):
7474
from urllib.parse import quote_from_bytes, unquote_to_bytes, urlencode
7575
from urllib.request import install_opener, build_opener
7676

77+
NOISY_LOGGERS = (
78+
"httpx",
79+
"httpcore",
80+
"h2",
81+
"hpack",
82+
"urllib3",
83+
"requests",
84+
)
85+
86+
for name in NOISY_LOGGERS:
87+
logging.getLogger(name).setLevel(logging.WARNING)
88+
logging.getLogger(name).disabled = True
7789

7890
_TEXT_MIME_DEFAULT = 'text/plain; charset=utf-8'
7991
_BIN_MIME_DEFAULT = 'application/octet-stream'

0 commit comments

Comments
 (0)