def getcontents(self, path, mode="rb", encoding=None, errors=None, newline=None): path = normpath(path) contents = StringIO() self.ftp.retrbinary('RETR %s' % _encode(path), contents.write, blocksize=1024*64) data = contents.getvalue() if 'b' in data: return data return iotools.decode_binary(data, encoding=encoding, errors=errors)
def getcontents(self, path, mode="rb", encoding=None, errors=None, newline=None): dir_entry = self._get_dir_entry(path) if dir_entry is None: raise ResourceNotFoundError(path) if not dir_entry.isfile(): raise ResourceInvalidError(path, msg="not a file: %(path)s") data = dir_entry.data or b('') if 'b' not in mode: return iotools.decode_binary(data, encoding=encoding, errors=errors, newline=newline) return data
def getcontents(self, path, mode="rb", encoding=None, errors=None, newline=None): if not self.exists(path): raise ResourceNotFoundError(path) path = normpath(relpath(path)) try: contents = self.zf.read(self._encode_path(path)) except KeyError: raise ResourceNotFoundError(path) except RuntimeError: raise OperationFailedError( "read file", path=path, msg="3 Zip file must be opened with 'r' or 'a' to read") if 'b' in mode: return contents return iotools.decode_binary(contents, encoding=encoding, errors=errors, newline=newline)