def urlparse(urlstring, scheme='', allow_fragments=True, *args, **kwargs): """A wrapper for :py:func:`urlparse.urlparse` with the following differences: * Handles buckets in S3 URIs correctly. (:py:func:`~urlparse.urlparse` does this correctly sometime after 2.6.1; this is just a patch for older Python versions.) * Splits the fragment correctly in all URIs, not just Web-related ones. This behavior was fixed in the Python 2.7.4 standard library but we have to back-port it for previous versions. """ # we're probably going to mess with at least one of these values and # re-pack the whole thing before we return it. # NB: urlparse_buggy()'s second argument changes names from # 'default_scheme' to 'scheme' in Python 2.6, so urlparse_buggy() should # be called with positional arguments. (scheme, netloc, path, params, query, fragment) = (urlparse_buggy(urlstring, scheme, allow_fragments, *args, **kwargs)) if netloc == '' and path.startswith('//'): m = NETLOC_RE.match(path) netloc = m.group(1) path = m.group(2) if allow_fragments and '#' in path and not fragment: path, fragment = path.split('#', 1) return ParseResult(scheme, netloc, path, params, query, fragment)
def urlparse(urlstring, scheme='', allow_fragments=True, *args, **kwargs): """A wrapper for :py:func:`urlparse.urlparse` with the following differences: * Handles buckets in S3 URIs correctly. (:py:func:`~urlparse.urlparse` does this correctly sometime after 2.6.1; this is just a patch for older Python versions.) * Splits the fragment correctly in all URIs, not just Web-related ones. This behavior was fixed in the Python 2.7.4 standard library but we have to back-port it for previous versions. """ # we're probably going to mess with at least one of these values and # re-pack the whole thing before we return it. # NB: urlparse_buggy()'s second argument changes names from # 'default_scheme' to 'scheme' in Python 2.6, so urlparse_buggy() should # be called with positional arguments. (scheme, netloc, path, params, query, fragment) = ( urlparse_buggy(urlstring, scheme, allow_fragments, *args, **kwargs)) if netloc == '' and path.startswith('//'): m = NETLOC_RE.match(path) netloc = m.group(1) path = m.group(1) if allow_fragments and '#' in path and not fragment: path, fragment = path.split('#', 1) return ParseResult(scheme, netloc, path, params, query, fragment)
def urlparse(*args, **kwargs): """A wrapper for :py:func:`urlparse.urlparse` that handles buckets in S3 URIs correctly. (:py:func:`~urlparse.urlparse` does this correctly on its own in Python 2.6+; this is just a patch for Python 2.5.)""" components = urlparse_buggy(*args, **kwargs) if components.netloc == '' and components.path.startswith('//'): m = NETLOC_RE.match(components.path) return ParseResult(components.scheme, m.group(1), m.group(2), components.params, components.query, components.fragment) else: return components
def urlparse(*args, **kwargs): """A wrapper for :py:func:`urlparse.urlparse` that handles buckets in S3 URIs correctly. (:py:func:`~urlparse.urlparse` does this correctly sometime after 2.6.1; this is just a patch for older Python versions.)""" components = urlparse_buggy(*args, **kwargs) if components.netloc == '' and components.path.startswith('//'): m = NETLOC_RE.match(components.path) return ParseResult(components.scheme, m.group(1), m.group(2), components.params, components.query, components.fragment) else: return components