Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
scheme, netloc, path, query, fragment = urllib.parse.urlsplit(part)
# trick to escape '/' in query and fragment and trailing
if not re.match(re.escape(sep) + '+$', path):
path = re.sub('%s+$' % (re.escape(sep),), lambda m: '\\x00' * len(m.group(0)), path)
path = urllib.parse.urlunsplit(('', '', path, query.replace('/', '\\x00'), fragment.replace('/', '\\x00')))
drive = urllib.parse.urlunsplit((scheme, netloc, '', '', ''))
root, path = re.match('^(%s*)(.*)$' % (re.escape(sep),), path).groups()
return drive, root, path
class URL(urllib.parse._NetlocResultMixinStr, PurePath):
_flavour = _URLFlavour()
_parse_qsl_args = {}
_urlencode_args = {'doseq': True}
@classmethod
def _parse_args(cls, args):
return super()._parse_args((cls._canonicalize_arg(a) for a in args))
@classmethod
def _canonicalize_arg(cls, a):
if isinstance(a, urllib.parse.SplitResult):
return urllib.parse.urlunsplit(a)
if isinstance(a, urllib.parse.ParseResult):
return urllib.parse.urlunparse(a)
if webob and isinstance(a, webob.Request):