1586
1586
return location
1589
def get_transport(base, possible_transports=None):
1590
"""Open a transport to access a URL or directory.
1592
:param base: either a URL or a directory name.
1589
def get_transport_from_path(path, possible_transports=None):
1590
"""Open a transport for a local path.
1592
:param path: Local path as byte or unicode string
1593
:return: Transport object for path
1595
return get_transport_from_url(urlutils.local_path_to_url(path),
1596
possible_transports)
1599
def get_transport_from_url(url, possible_transports=None):
1600
"""Open a transport to access a URL.
1594
1603
:param transports: optional reusable transports list. If not None, created
1595
1604
transports will be added to the list.
1597
1606
:return: A new transport optionally sharing its connection with one of
1598
1607
possible_transports.
1602
base = location_to_url(base)
1604
1609
transport = None
1605
1610
if possible_transports is not None:
1606
1611
for t in possible_transports:
1607
t_same_connection = t._reuse_for(base)
1612
t_same_connection = t._reuse_for(url)
1608
1613
if t_same_connection is not None:
1609
1614
# Add only new transports
1610
1615
if t_same_connection not in possible_transports:
1614
1619
last_err = None
1615
1620
for proto, factory_list in transport_list_registry.items():
1616
if proto is not None and base.startswith(proto):
1617
transport, last_err = _try_transport_factories(base, factory_list)
1621
if proto is not None and url.startswith(proto):
1622
transport, last_err = _try_transport_factories(url, factory_list)
1619
1624
if possible_transports is not None:
1620
1625
if transport in possible_transports:
1621
1626
raise AssertionError()
1622
1627
possible_transports.append(transport)
1623
1628
return transport
1624
raise errors.UnsupportedProtocol(base, last_err)
1629
if not urlutils.is_url(url):
1630
raise errors.InvalidURL(path=url)
1631
raise errors.UnsupportedProtocol(url, last_err)
1634
def get_transport(base, possible_transports=None):
1635
"""Open a transport to access a URL or directory.
1637
:param base: either a URL or a directory name.
1639
:param transports: optional reusable transports list. If not None, created
1640
transports will be added to the list.
1642
:return: A new transport optionally sharing its connection with one of
1643
possible_transports.
1647
return get_transport_from_url(location_to_url(base), possible_transports)
1627
1650
def _try_transport_factories(base, factory_list):