def open(self, dxf_file_name: str = None) -> None:
        def open_dxf_file() -> BinaryIO:
            return self.zip_archive.open(self.dxf_file_name)  # open always in binary mode

        self.zip_archive = zipfile.ZipFile(self.zip_archive_name)
        self.dxf_file_name = dxf_file_name if dxf_file_name is not None else self.get_first_dxf_file_name()
        self.dxf_file = open_dxf_file()

        # reading with standard encoding 'cp1252' - readline() fails if leading comments contain none ascii characters
        if not is_dxf_stream(cast(TextIO, self)):
            raise IOError("'{}' is not a DXF file.".format(self.dxf_file_name))
        self.dxf_file = open_dxf_file()  # restart
        self.get_dxf_info()
        self.dxf_file = open_dxf_file()  # restart
Esempio n. 2
0
    def open(self, dxf_file_name: str = None) -> None:
        def open_dxf_file() -> BinaryIO:
            # Open always in binary mode:
            return cast(BinaryIO, self.zip_archive.open(self.dxf_file_name))  # type: ignore

        self.zip_archive = zipfile.ZipFile(self.zip_archive_name)
        self.dxf_file_name = (
            dxf_file_name
            if dxf_file_name is not None
            else self.get_first_dxf_file_name()
        )
        self.dxf_file = open_dxf_file()

        # Reading with standard encoding 'cp1252' - readline() fails if leading
        # comments contain none ASCII characters.
        if not is_dxf_stream(cast(TextIO, self)):
            raise IOError(f"'{self.dxf_file_name}' is not a DXF file.")
        self.dxf_file = open_dxf_file()  # restart
        self.get_dxf_info()
        self.dxf_file = open_dxf_file()  # restart