def put(self, key, headers, src): """ Add a file to the store, overwriting an existing file with the same key. :arg key: unique key that identifies the file. :arg headers: list of (name, value) pairs that will be associated with the file. :arg src: readable file-like object """ # XXX We should only allow strings as headers keys and values. # Open the file with minimal permissions.. filename = os.path.join(self._root_dir, safefilename.encode(key)) fd = os.open(filename, os.O_RDWR | os.O_CREAT, self._mode) dest = os.fdopen(fd, 'wb') try: if isinstance(headers, dict): headers = headers.items() for name, value in headers: if isinstance(value, unicode): value = value.encode('utf-8') dest.write('%s: %s\n' % (name, value)) dest.write('\n') _copyfile.copyfileobj(src, dest) finally: dest.close()
def put(self, key, headers, src): """ Add a file to the store, overwriting an existing file with the same key. :arg key: unique key that identifies the file. :arg headers: list of (name, value) pairs that will be associated with the file. :arg src: readable file-like object """ # XXX We should only allow strings as headers keys and values. # Open the file with minimal permissions.. filename = os.path.join(self._root_dir, safefilename.encode(key)) fd = os.open(filename, os.O_RDWR|os.O_CREAT, self._mode) dest = os.fdopen(fd, 'wb') try: if isinstance(headers, dict): headers = headers.items() for name, value in headers: if isinstance(value, unicode): value = value.encode('utf-8') dest.write('%s: %s\n' % (name, value)) dest.write('\n') _copyfile.copyfileobj(src, dest) finally: dest.close()
def put(self, key, headers, src): """ Add a file to the store, overwriting an existing file with the same key. :arg key: unique key that identifies the file. :arg headers: list of (name, value) pairs that will be associated with the file. :arg src: readable file-like object """ # XXX We should only allow strings as headers keys and values. # Open the file with minimal permissions.. filename = os.path.join(self._root_dir, key) fd = os.open(filename, os.O_RDWR | os.O_CREAT, self._mode) dest = os.fdopen(fd, 'wb') try: _copyfile.copyfileobj(src, dest) finally: dest.close()
def put(self, key, headers, src): """ Add a file to the store, overwriting an existing file with the same key. :arg key: unique key that identifies the file. :arg headers: list of (name, value) pairs that will be associated with the file. :arg src: readable file-like object """ # XXX We should only allow strings as headers keys and values. # Open the file with minimal permissions.. filename = os.path.join(self._root_dir, key) fd = os.open(filename, os.O_RDWR|os.O_CREAT, self._mode) dest = os.fdopen(fd, 'wb') try: _copyfile.copyfileobj(src, dest) finally: dest.close()