1
# Copyright (C) 2005-2012, 2016 Canonical Ltd
1
# Copyright (C) 2005-2011 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
138
138
def register_lazy_transport(prefix, module, classname):
139
139
if not prefix in transport_list_registry:
140
140
register_transport_proto(prefix)
141
transport_list_registry.register_lazy_transport_provider(
142
prefix, module, classname)
145
def register_transport(prefix, klass):
141
transport_list_registry.register_lazy_transport_provider(prefix, module, classname)
144
def register_transport(prefix, klass, override=DEPRECATED_PARAMETER):
146
145
if not prefix in transport_list_registry:
147
146
register_transport_proto(prefix)
148
147
transport_list_registry.register_transport_provider(prefix, klass)
873
872
yield self.get(relpath)
876
def put_bytes(self, relpath, raw_bytes, mode=None):
875
def put_bytes(self, relpath, bytes, mode=None):
877
876
"""Atomically put the supplied bytes into the given location.
879
878
:param relpath: The location to put the contents, relative to the
881
:param raw_bytes: A bytestring of data.
880
:param bytes: A bytestring of data.
882
881
:param mode: Create the file with the given mode.
885
if not isinstance(raw_bytes, str):
887
'raw_bytes must be a plain string, not %s' % type(raw_bytes))
888
return self.put_file(relpath, StringIO(raw_bytes), mode=mode)
884
if not isinstance(bytes, str):
885
raise AssertionError(
886
'bytes must be a plain string, not %s' % type(bytes))
887
return self.put_file(relpath, StringIO(bytes), mode=mode)
890
def put_bytes_non_atomic(self, relpath, raw_bytes, mode=None,
889
def put_bytes_non_atomic(self, relpath, bytes, mode=None,
891
890
create_parent_dir=False,
893
892
"""Copy the string into the target location.
896
895
Transport.put_bytes_non_atomic for more information.
898
897
:param relpath: The remote location to put the contents.
899
:param raw_bytes: A string object containing the raw bytes to write
900
into the target file.
898
:param bytes: A string object containing the raw bytes to write into
901
900
:param mode: Possible access permissions for new file.
902
901
None means do not set remote permissions.
903
902
:param create_parent_dir: If we cannot create the target file because
905
904
create it, and then try again.
906
905
:param dir_mode: Possible access permissions for new directories.
908
if not isinstance(raw_bytes, str):
910
'raw_bytes must be a plain string, not %s' % type(raw_bytes))
911
self.put_file_non_atomic(relpath, StringIO(raw_bytes), mode=mode,
907
if not isinstance(bytes, str):
908
raise AssertionError(
909
'bytes must be a plain string, not %s' % type(bytes))
910
self.put_file_non_atomic(relpath, StringIO(bytes), mode=mode,
912
911
create_parent_dir=create_parent_dir,
913
912
dir_mode=dir_mode)
1783
1782
help="Read-only access of branches exported on the web.")
1784
1783
register_transport_proto('https://',
1785
1784
help="Read-only access of branches exported on the web using SSL.")
1786
# The default http implementation is urllib
1785
# The default http implementation is urllib, but https uses pycurl if available
1787
1786
register_lazy_transport('http://', 'bzrlib.transport.http._pycurl',
1788
1787
'PyCurlTransport')
1789
1788
register_lazy_transport('http://', 'bzrlib.transport.http._urllib',
1790
1789
'HttpTransport_urllib')
1790
register_lazy_transport('https://', 'bzrlib.transport.http._urllib',
1791
'HttpTransport_urllib')
1791
1792
register_lazy_transport('https://', 'bzrlib.transport.http._pycurl',
1792
1793
'PyCurlTransport')
1793
register_lazy_transport('https://', 'bzrlib.transport.http._urllib',
1794
'HttpTransport_urllib')
1796
1795
register_transport_proto('ftp://', help="Access using passive FTP.")
1797
1796
register_lazy_transport('ftp://', 'bzrlib.transport.ftp', 'FtpTransport')