1
# Copyright (C) 2005-2011 Canonical Ltd
1
# Copyright (C) 2005-2012, 2016 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
873
873
yield self.get(relpath)
876
def put_bytes(self, relpath, bytes, mode=None):
876
def put_bytes(self, relpath, raw_bytes, mode=None):
877
877
"""Atomically put the supplied bytes into the given location.
879
879
:param relpath: The location to put the contents, relative to the
881
:param bytes: A bytestring of data.
881
:param raw_bytes: A bytestring of data.
882
882
:param mode: Create the file with the given mode.
885
if not isinstance(bytes, str):
886
raise AssertionError(
887
'bytes must be a plain string, not %s' % type(bytes))
888
return self.put_file(relpath, StringIO(bytes), mode=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)
890
def put_bytes_non_atomic(self, relpath, bytes, mode=None,
890
def put_bytes_non_atomic(self, relpath, raw_bytes, mode=None,
891
891
create_parent_dir=False,
893
893
"""Copy the string into the target location.
896
896
Transport.put_bytes_non_atomic for more information.
898
898
:param relpath: The remote location to put the contents.
899
:param bytes: A string object containing the raw bytes to write into
899
:param raw_bytes: A string object containing the raw bytes to write
900
into the target file.
901
901
:param mode: Possible access permissions for new file.
902
902
None means do not set remote permissions.
903
903
:param create_parent_dir: If we cannot create the target file because
905
905
create it, and then try again.
906
906
:param dir_mode: Possible access permissions for new directories.
908
if not isinstance(bytes, str):
909
raise AssertionError(
910
'bytes must be a plain string, not %s' % type(bytes))
911
self.put_file_non_atomic(relpath, StringIO(bytes), mode=mode,
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,
912
912
create_parent_dir=create_parent_dir,
913
913
dir_mode=dir_mode)