Ejemplo n.º 1
0
def readzip(zipfile: str,
            filename: str = None,
            errors: str = 'surrogateescape') -> 'Drawing':
    """ Load a DXF document specified by `filename` from a zip archive, or if
    `filename` is ``None`` the first DXF document in the zip archive.

    Args:
        zipfile: name of the zip archive
        filename: filename of DXF file, or ``None`` to load the first DXF
            document from the zip archive.
        errors: specify decoding error handler

            - "surrogateescape" to preserve possible binary data (default)
            - "ignore" to use the replacement char U+FFFD "\ufffd" for invalid data
            - "strict" to raise an :class:`UnicodeDecodeError` exception for invalid data

    Raises:
        IOError: not a DXF file or file does not exist or
            if `filename` is ``None`` - no DXF file found
        DXFStructureError: for invalid or corrupted DXF structures
        UnicodeDecodeError: if `errors` is "strict" and a decoding error occurs

    """
    from ezdxf.tools.zipmanager import ctxZipReader

    with ctxZipReader(zipfile, filename, errors=errors) as zipstream:
        doc = read(zipstream)
        doc.filename = zipstream.dxf_file_name
    return doc
Ejemplo n.º 2
0
def readzip(zipfile: str, filename: str = None) -> 'Drawing':
    """
    Read DXF drawing specified by filename from a zip archive, or if filename is None the first DXF file in the zip
    archive.

    Supported DXF versions:

    - pre AC1009 DXF versions will be upgraded to AC1009
    - AC1009: AutoCAD R12 (DXF12)
    - AC1012: AutoCAD R13 upgraded to AC1015
    - AC1014: AutoCAD R14 upgraded to AC1015
    - AC1015: AutoCAD 2000
    - AC1018: AutoCAD 2004
    - AC1021: AutoCAD 2007
    - AC1024: AutoCAD 2010
    - AC1027: AutoCAD 2013
    - AC1032: AutoCAD 2018

    Args:
        zipfile: name of the zip archive
        filename: filename of DXF file, or None to read the first DXF file from the zip archive.

    """
    from ezdxf.tools.zipmanager import ctxZipReader

    with ctxZipReader(zipfile, filename) as zipstream:
        dwg = read(zipstream, dxfversion=zipstream.dxfversion)
        dwg.filename = zipstream.dxf_file_name
    return dwg
Ejemplo n.º 3
0
def readzip(zipfile: str, filename: str = None) -> 'Drawing':
    """
    Read DXF drawing specified by `filename` from a zip archive, or if `filename` is ``None`` the first DXF file in the
    zip archive.

    Args:
        zipfile: name of the zip archive
        filename: filename of DXF file, or ``None`` to read the first DXF file from the zip archive.

    """
    from ezdxf.tools.zipmanager import ctxZipReader

    with ctxZipReader(zipfile, filename) as zipstream:
        doc = read(zipstream)
        doc.filename = zipstream.dxf_file_name
    return doc