示例#1
0
    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()
示例#2
0
文件: csvz.py 项目: BenOussama180/pfe
    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)
示例#3
0
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")
示例#4
0
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")
示例#5
0
 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)
示例#6
0
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')
示例#7
0
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
示例#8
0
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
示例#9
0
 def set_sheet_name(self, name):
     self.content = StringIO()
     self.writer = csv.writer(self.content, **self._keywords)
示例#10
0
 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)
示例#11
0
def test_load_csvz_data_from_memory():
    if not PY2:
        io = StringIO()
        get_data(io, file_type="csvz")
    else:
        raise BadZipfile("pass it")