Make exchange_from_url() use parse_url()
This commit is contained in:
parent
3e3a13eefd
commit
5cd662a517
@ -66,6 +66,8 @@ def parse_url(url, default_exchange=None):
|
|||||||
:type default_exchange: str
|
:type default_exchange: str
|
||||||
:returns: A dictionary with the parsed data
|
:returns: A dictionary with the parsed data
|
||||||
"""
|
"""
|
||||||
|
if not url:
|
||||||
|
return dict(exchange=default_exchange)
|
||||||
|
|
||||||
# NOTE(flaper87): Not PY3K compliant
|
# NOTE(flaper87): Not PY3K compliant
|
||||||
if not isinstance(url, basestring):
|
if not isinstance(url, basestring):
|
||||||
@ -75,12 +77,11 @@ def parse_url(url, default_exchange=None):
|
|||||||
|
|
||||||
parsed = dict(transport=url.scheme)
|
parsed = dict(transport=url.scheme)
|
||||||
|
|
||||||
# NOTE(flaper87): Set the exchange.
|
exchange = None
|
||||||
# if it is / or None then use the
|
if url.path.startswith('/'):
|
||||||
# default one.
|
exchange = url.path[1:].split('/')[0]
|
||||||
exchange = default_exchange
|
if not exchange:
|
||||||
if url.path and url.path != "/":
|
exchange = default_exchange
|
||||||
exchange = url.path[1:].split("/")[0]
|
|
||||||
parsed["exchange"] = exchange
|
parsed["exchange"] = exchange
|
||||||
|
|
||||||
# NOTE(flaper87): Parse netloc.
|
# NOTE(flaper87): Parse netloc.
|
||||||
@ -128,13 +129,4 @@ def exchange_from_url(url, default_exchange=None):
|
|||||||
:param default_exchange: what to return if no exchange found in URL
|
:param default_exchange: what to return if no exchange found in URL
|
||||||
:type default_exchange: str
|
:type default_exchange: str
|
||||||
"""
|
"""
|
||||||
if not url:
|
return parse_url(url, default_exchange)['exchange']
|
||||||
return default_exchange
|
|
||||||
|
|
||||||
url = urlparse.urlparse(url)
|
|
||||||
if not url.path.startswith('/'):
|
|
||||||
return default_exchange
|
|
||||||
|
|
||||||
parts = url.path[1:].split('/')
|
|
||||||
|
|
||||||
return parts[0] if parts[0] else default_exchange
|
|
||||||
|
Loading…
Reference in New Issue
Block a user