def read_sheet(self, native_sheet): content = self.zipfile.read(native_sheet.payload) if PY2: sheet = StringIO(content) else: sheet = StringIO(content.decode("utf-8")) reader = CSVinMemoryReader(NamedContent(native_sheet.name, sheet), **self._keywords) return reader.to_array()
def read_sheet(self, index): name = self.content_array[index].name content = self.zipfile.read(self.content_array[index].payload) encoding_guess = chardet.detect(content) sheet = StringIO(content.decode(encoding_guess["encoding"])) return CSVinMemoryReader(NamedContent(name, sheet), **self.keywords)
def test_writer_csvz_data_from_memory(): if not PY2: io = StringIO() writer = get_writer(io, file_type="csvz") writer.write({"adb": [[2, 3]]}) else: raise Exception("pass it")
def test_writer_csvz_data_from_memory(): if not PY2: io = StringIO() writer = get_writer(io, file_type="csvz") writer.write({'adb': [[2, 3]]}) else: raise NotImplementedError("pass it")
def set_sheet_name(self, name): self.content = StringIO() if PY2: self.writer = UnicodeWriter(self.content, encoding=self._encoding, **self._keywords) else: import csv self.writer = csv.writer(self.content, **self._keywords)
def test_utf16_memory_encoding(): content = [[u'Äkkilähdöt', u'Matkakirjoituksia', u'Matkatoimistot']] io = StringIO() writer = CSVMemoryWriter(io, None, lineterminator="\n", single_sheet_in_book=True, encoding="utf-16") writer.write_array(content) actual = io.getvalue() if PY2: actual = actual.decode('utf-16') eq_(actual, u'Äkkilähdöt,Matkakirjoituksia,Matkatoimistot\n')
def get_io(file_type): """A utility function to help you generate a correct io stream :param file_type: a supported file type :returns: a appropriate io stream, None otherwise """ __file_type = None if file_type: __file_type = file_type.lower() if __file_type in text_stream_types: return StringIO() elif __file_type in binary_stream_types: return BytesIO() else: return None
def get_io(file_type): """A utility function to help you generate a correct io stream :param file_type: a supported file type :returns: a appropriate io stream, None otherwise """ __file_type = None if file_type: __file_type = file_type.lower() if __file_type in TEXT_STREAM_TYPES: return StringIO() elif __file_type in BINARY_STREAM_TYPES: return BytesIO() else: return None
def set_sheet_name(self, name): self.content = StringIO() self.writer = csv.writer(self.content, **self._keywords)
def __init__(self, zipfile, sheetname, file_extension, **keywords): self.file_extension = file_extension keywords["single_sheet_in_book"] = False self.content = StringIO() super().__init__(zipfile, sheetname, **keywords)
def test_load_csvz_data_from_memory(): if not PY2: io = StringIO() get_data(io, file_type="csvz") else: raise BadZipfile("pass it")