def macStyle_fixture(self):
     bytes_ = b"xxxxyyyy....................................\xF0\xBA........"
     stream = _Stream(BytesIO(bytes_))
     offset, length = 0, len(bytes_)
     head_table = _HeadTable(None, stream, offset, length)
     expected_value = 61626
     return head_table, expected_value
Ejemplo n.º 2
0
 def from_stream_fixture(self, video_, from_blob_):
     with open(TEST_VIDEO_PATH, "rb") as f:
         blob = f.read()
         movie_stream = BytesIO(blob)
     mime_type = "video/mp4"
     from_blob_.return_value = video_
     return movie_stream, mime_type, blob, video_
Ejemplo n.º 3
0
 def it_can_open_a_worksheet_in_a_context(self):
     xlsx_file = BytesIO()
     with WorkbookWriter._open_worksheet(xlsx_file) as worksheet:
         assert isinstance(worksheet, Worksheet)
     zipf = ZipFile(xlsx_file)
     assert 'xl/worksheets/sheet1.xml' in zipf.namelist()
     zipf.close
Ejemplo n.º 4
0
    def it_constructs_ZipPkgReader_when_pkg_is_file_like(
            self, _ZipPkgReader_, zip_pkg_reader_):
        _ZipPkgReader_.return_value = zip_pkg_reader_
        file_like_pkg = BytesIO(b"pkg-bytes")

        phys_reader = _PhysPkgReader.factory(file_like_pkg)

        _ZipPkgReader_.assert_called_once_with(file_like_pkg)
        assert phys_reader is zip_pkg_reader_
Ejemplo n.º 5
0
    def _poster_frame_image_file(self):
        """Return the image file for video placeholder image.

        If no poster frame file is provided, the default "media loudspeaker"
        image is used.
        """
        poster_frame_file = self._poster_frame_file
        if poster_frame_file is None:
            return BytesIO(SPEAKER_IMAGE_BYTES)
        return poster_frame_file
Ejemplo n.º 6
0
 def _pil_props(self):
     """
     A tuple containing useful image properties extracted from this image
     using Pillow (Python Imaging Library, or 'PIL').
     """
     stream = BytesIO(self._blob)
     pil_image = PIL_Image.open(stream)
     format = pil_image.format
     width_px, height_px = pil_image.size
     dpi = pil_image.info.get("dpi")
     stream.close()
     return (format, (width_px, height_px), dpi)
Ejemplo n.º 7
0
    def it_can_write_a_blob(self, _zipf_prop_):
        """Integrates with zipfile.ZipFile."""
        pack_uri = PackURI("/part/name.xml")
        _zipf_prop_.return_value = zipf = zipfile.ZipFile(BytesIO(), "w")
        pkg_writer = _ZipPkgWriter(None)

        pkg_writer.write(pack_uri, b"blob")

        members = {
            PackURI("/%s" % name): zipf.read(name)
            for name in zipf.namelist()
        }
        assert len(members) == 1
        assert members[pack_uri] == b"blob"
Ejemplo n.º 8
0
def when_open_presentation_stream(context):
    with open(test_pptx("test"), "rb") as f:
        stream = BytesIO(f.read())
    context.prs = Presentation(stream)
    stream.close()
Ejemplo n.º 9
0
def when_save_presentation_to_stream(context):
    context.stream = BytesIO()
    context.prs.save(context.stream)
Ejemplo n.º 10
0
def when_I_add_the_stream_image_filename_using_add_picture(context, filename):
    shapes = context.slide.shapes
    with open(test_image(filename), "rb") as f:
        stream = BytesIO(f.read())
    shapes.add_picture(stream, Inches(1.25), Inches(1.25))
Ejemplo n.º 11
0
 def from_stream_fixture(self, from_blob_, image_):
     with open(test_image_path, 'rb') as f:
         blob = f.read()
         image_file = BytesIO(blob)
     from_blob_.return_value = image_
     return image_file, blob, image_