Use voussoirkit safeprint instead of duplicate function.

This commit is contained in:
Ethan Dalool 2020-09-25 15:30:49 -07:00
parent 6b546b39df
commit ade7d63231

View file

@ -8,6 +8,7 @@ import warnings
from voussoirkit import bytestring from voussoirkit import bytestring
from voussoirkit import ratelimiter from voussoirkit import ratelimiter
from voussoirkit import clipext from voussoirkit import clipext
from voussoirkit import safeprint
warnings.simplefilter('ignore') warnings.simplefilter('ignore')
@ -53,8 +54,8 @@ def download_file(
localname = os.path.abspath(localname) localname = os.path.abspath(localname)
if verbose: if verbose:
safeprint(' URL:', url) safeprint.safeprint(f' URL: {url}')
safeprint('File:', localname) safeprint.safeprint(f'File: {localname}')
plan = prepare_plan( plan = prepare_plan(
url, url,
@ -371,10 +372,6 @@ def request(method, url, stream=False, headers=None, timeout=TIMEOUT, verify_ssl
req.raise_for_status() req.raise_for_status()
return req return req
def safeprint(*texts, **kwargs):
texts = [str(text).encode('ascii', 'replace').decode() for text in texts]
print(*texts, **kwargs)
def sanitize_filename(text, exclusions=''): def sanitize_filename(text, exclusions=''):
to_remove = FILENAME_BADCHARS to_remove = FILENAME_BADCHARS
for exclude in exclusions: for exclude in exclusions: