MCPcopy Index your code
hub / github.com/pyload/pyload / parse_name

Function parse_name

module/plugins/internal/misc.py:609–636  ·  view source on GitHub ↗
(value, safechar=True)

Source from the content-addressed store, hash-verified

607
608
609def parse_name(value, safechar=True):
610 path = urllib.unquote(decode(value))
611
612 try:
613 path = path.encode('latin1').decode('utf8')
614 except (UnicodeEncodeError, UnicodeDecodeError):
615 pass
616
617 #: 'unicode-escape' that work with unicode strings too
618 path = re.sub(r'\\u(\d{4})', lambda x: unichr(int(x.group(1))), path, flags=re.I)
619
620 #: Decode HTML escape
621 path = html_unescape(path)
622
623 #: Decode rfc2047
624 path = rfc2047_dec(path)
625
626 #: Remove redundant '/'
627 path = re.sub(r'(?<!:)/{2,}', '/', path).strip().lstrip('.')
628
629 url_p = urlparse.urlparse(path.rstrip('/'))
630 name = (url_p.path.split('/')[-1] or
631 url_p.query.split('=', 1)[::-1][0].split('&', 1)[0] or
632 url_p.netloc.split('.', 1)[0])
633
634 name = os.path.basename(name)
635
636 return safename(name) if safechar else name
637
638
639def parse_size(value, unit=""): #: returns bytes

Callers 8

get_infoMethod · 0.85
isresourceMethod · 0.85
get_infoMethod · 0.85
_generate_packagesMethod · 0.85
_create_packagesMethod · 0.85
get_infoMethod · 0.85
adult_confirmationMethod · 0.85
processMethod · 0.85

Calls 7

rfc2047_decFunction · 0.85
safenameFunction · 0.85
decodeMethod · 0.80
splitMethod · 0.80
decodeFunction · 0.70
html_unescapeFunction · 0.70
encodeMethod · 0.45

Tested by

no test coverage detected