Пример #1
0
def read(stream: TextIO) -> 'Drawing':
    """ Read a DXF document from a text-stream. Open stream in text mode
    (``mode='rt'``) and set correct text encoding, the stream requires at least
    a :meth:`readline` method.

    Since DXF version R2007 (AC1021) file encoding is always "utf-8",
    use the helper function :func:`dxf_stream_info` to detect the required
    text encoding for prior DXF versions. To preserve possible binary data in
    use :code:`errors='surrogateescape'` as error handler for the import stream.

    If this function struggles to load the DXF document and raises a
    :class:`DXFStructureError` exception, try the :func:`ezdxf.recover.read`
    function to load this corrupt DXF document.

    Args:
        stream: input text stream opened with correct encoding

    Raises:
        DXFStructureError: for invalid or corrupted DXF structures

    .. deprecated:: v0.14

        argument `legacy_mode`, use module :mod:`ezdxf.recover`
        to load DXF documents with structural flaws.

    """
    from ezdxf.document import Drawing
    return Drawing.read(stream)
Пример #2
0
def read(stream: TextIO, legacy_mode: bool = False) -> 'Drawing':
    """ Read a DXF document from a text-stream. Open stream in text mode
    (``mode='rt'``) and set correct text encoding, the stream requires at least
    a :meth:`readline` method.

    Since DXF version R2007 (AC1021) file encoding is always "utf-8",
    use the helper function :func:`dxf_stream_info` to detect the required
    text encoding for prior DXF versions.

    If this function struggles to load the DXF document and raises a
    :class:`DXFStructureError` exception, try the :func:`ezdxf.recover.read`
    function to load this corrupt DXF document.

    Args:
        stream: input text stream opened with correct encoding
        legacy_mode: adds an extra trouble shooting import layer if ``True``
            (deprecated)

    Raises:
        DXFStructureError: for invalid DXF structure

    .. deprecated:: v0.14

        argument `legacy_mode`, use module :mod:`ezdxf.recover`
        to load DXF documents with structural flaws.

    """
    from ezdxf.document import Drawing
    if legacy_mode:
        warnings.warn(
            '"legacy_mode" is deprecated (removed in v0.16), replace call by '
            'ezdxf.recover.readfile().', DeprecationWarning)
    return Drawing.read(stream, legacy_mode=legacy_mode)