135
134
register_netloc=False):
136
135
transport_list_registry.register_transport(prefix, help)
137
136
if register_netloc:
138
assert prefix.endswith('://')
137
if not prefix.endswith('://'):
138
raise ValueError(prefix)
139
139
register_urlparse_netloc_protocol(prefix[:-3])
179
179
transport_list_registry.remove(scheme)
183
@deprecated_function(zero_ninety)
185
# TODO: jam 20060606 urls should only be ascii, or they should raise InvalidURL
186
if isinstance(url, unicode):
187
url = url.encode('utf-8')
188
(scheme, netloc, path, params,
189
query, fragment) = urlparse.urlparse(url, allow_fragments=False)
190
username = password = host = port = None
192
username, host = netloc.split('@', 1)
194
username, password = username.split(':', 1)
195
password = urllib.unquote(password)
196
username = urllib.unquote(username)
201
host, port = host.rsplit(':', 1)
205
# TODO: Should this be ConnectionError?
206
raise errors.TransportError(
207
'invalid port number %s in url:\n%s' % (port, url))
208
host = urllib.unquote(host)
210
path = urllib.unquote(path)
212
return (scheme, username, password, host, port, path)
215
182
class _CoalescedOffset(object):
216
183
"""A data container for keeping track of coalesced offsets."""
326
293
_bytes_to_read_before_seek = 0
328
295
def __init__(self, base):
329
super(Transport, self).__init__()
296
super(Transport, self).__init__(base=base)
332
299
def _translate_error(self, e, path, raise_generic=True):
404
371
object or string to another one.
405
372
This just gives them something easy to call.
407
assert not isinstance(from_file, basestring), \
408
'_pump should only be called on files not %s' % (type(from_file,))
409
374
return osutils.pumpfile(from_file, to_file)
411
376
def _get_total(self, multi):
1001
966
:returns: the length of relpath before the content was written to it.
1003
assert isinstance(bytes, str), \
1004
'bytes must be a plain string, not %s' % type(bytes)
968
if not isinstance(bytes, str):
970
'bytes must be a plain string, not %s' % type(bytes))
1005
971
return self.append_file(relpath, StringIO(bytes), mode=mode)
1007
973
def append_multi(self, files, pb=None):
1540
1506
return transport
1543
@deprecated_function(zero_ninety)
1544
def urlescape(relpath):
1545
urlutils.escape(relpath)
1548
@deprecated_function(zero_ninety)
1549
def urlunescape(url):
1550
urlutils.unescape(url)
1552
1509
# We try to recognize an url lazily (ignoring user, password, etc)
1553
1510
_urlRE = re.compile(r'^(?P<proto>[^:/\\]+)://(?P<rest>.*)$')
1604
1561
transport, last_err = _try_transport_factories(base, factory_list)
1606
1563
if possible_transports is not None:
1607
assert transport not in possible_transports
1564
if transport in possible_transports:
1565
raise AssertionError()
1608
1566
possible_transports.append(transport)
1609
1567
return transport