
    hh'                    2   S SK Jr  S SKJrJrJrJrJr  S SKrS SK	r	S SK
r
S SKrS SKJr  S SKJr  S SKJr  \(       a  S SKJr  \SS	4       SS
 jjrSS jr  S       SS jjrSS jrSS jr  S       SS jjrSSS jjr S     SS jjrg)    )annotations)TextIOTYPE_CHECKINGUnionSequenceOptionalN)setup_drawing)DXF2013Drawing)DXFInfoF   c                    [         R                  " U 5      nX#l        US;   a  SOSUR                  S'   U(       a	  [	        X1S9  U$ )a  Create a new :class:`~ezdxf.drawing.Drawing` from scratch, `dxfversion`
can be either "AC1009" the official DXF version name or "R12" the
AutoCAD release name.

:func:`new` can create drawings for following DXF versions:

======= ========================
Version AutoCAD Release
======= ========================
AC1009  AutoCAD R12
AC1015  AutoCAD R2000
AC1018  AutoCAD R2004
AC1021  AutoCAD R2007
AC1024  AutoCAD R2010
AC1027  AutoCAD R2013
AC1032  AutoCAD R2018
======= ========================

The `units` argument defines th document and modelspace units. The header
variable $MEASUREMENT will be set according to the given `units`, 0 for
inch, feet, miles, ... and 1 for metric units. For more information go to
module :mod:`ezdxf.units`

Args:
    dxfversion: DXF version specifier as string, default is "AC1027"
        respectively "R2013"
    setup: setup default styles, ``False`` for no setup,
        ``True`` to setup everything or a list of topics as strings,
        e.g. ["linetypes", "styles"] to setup only some topics:

        ================== ========================================
        Topic              Description
        ================== ========================================
        linetypes          setup line types
        styles             setup text styles
        dimstyles          setup default `ezdxf` dimension styles
        visualstyles       setup 25 standard visual styles
        ================== ========================================
    units: document and modelspace units, default is 6 for meters

)            	   
   r   r   z$MEASUREMENT)topics)r   newunitsheaderr	   )
dxfversionsetupr   docs       F/var/www/html/env/lib/python3.13/site-packages/ezdxf/filemanagement.pyr   r      s@    \ ++j
!CI&+/B&BCJJ~c(J    c                2    SSK Jn  UR                  " U 5      $ )a  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

r   r   )ezdxf.documentr   read)streamr   s     r   r!   r!   H   s    * '<<r   c                $   SSK JnJn  SSKJn  SSKJn  [        U 5      n U" U 5      (       aJ  [        U S5       nUR                  5       nU" XS9n	[        R                  " U	5      n
X
l        U
sSSS5        $ U" U 5      (       d  [        SU  S	35      e[        U 5      nUb  Xl        [        U S
UR                  US9 n[        U5      n
SSS5        U W
l        Ub  U" U5      (       a  Xl        U
$ ! , (       d  f       N= f! , (       d  f       N>= f)u  Read the DXF document `filename` from the file-system.

This is the preferred method to load existing ASCII or Binary DXF files,
the required text encoding will be detected automatically and decoding
errors will be ignored.

Override encoding detection by setting argument `encoding` to the
estimated encoding. (use Python encoding names like in the :func:`open`
function).

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

Args:
    filename: filename of the ASCII- or Binary DXF document
    encoding: use ``None`` for auto detect (default), or set a specific
        encoding like "utf-8", argument is ignored for Binary DXF files
    errors: specify decoding error handler

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

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

r   )is_dxf_fileis_binary_dxf_file)is_supported_encoding)binary_tags_loaderrberrorsNzFile 'z' is not a DXF file.rtmodeencodingr*   )ezdxf.lldxf.validatorr$   r%   ezdxf.tools.codepager&   ezdxf.lldxf.taggerr'   stropenr!   r   loadfilenameIOErrordxf_file_infor.   )r5   r.   r*   r$   r%   r&   r'   fpdataloaderr   infos               r   readfiler<   b   s    F F:58}H(##(D!R779D'<F,,v&C#L "! x  xj(<=>>"D 	hTDMM&	IR2h 
J CL 5h ? ?  J/ "! 
J	Is   4C0=D0
C>
Dc                |    [        U 5      n [        U SSSS9 n[        U5      sSSS5        $ ! , (       d  f       g= f)zZReads basic file information from a DXF document: DXF version, encoding
and handle seed.

r+   utf-8ignorer,   N)r2   r3   dxf_stream_info)r5   r8   s     r   r7   r7      s2    
 8}H	hTGH	Er" 
F	E	Es   -
;c                P    SSK Jn  U" U 5      nUR                  S:  a  SUl        U$ )zXReads basic DXF information from a text stream: DXF version, encoding
and handle seed.

r   )dxf_infoAC1021r>   )r/   rB   versionr.   )r"   rB   r;   s      r   r@   r@      s)    
 /FD||xKr   c                    SSK Jn  U" [        U 5      XS9 n[        U5      nUR                  Ul        SSS5        U$ ! , (       d  f       W$ = f)u8  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 "�" 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

r   )ctxZipReaderr)   N)ezdxf.tools.zipmanagerrF   r2   r!   dxf_file_namer5   )zipfiler5   r*   rF   	zipstreamr   s         r   readziprK      sI    2 4	c'lH	<	9o .. 
= J 
=	< Js	   >
Ac                n   [         R                  " U 5      nUR                  SS5      nUR                  SSS9n[        R
                  " U5      n[        U5      nUR                  5         UR                  UR                  US9n[        R
                  " U5      n[        U5      nUR                  5         U$ )uA  Load a DXF document from base64 encoded binary data, like uploaded data
to web applications.

Args:
    data: DXF document base64 encoded binary data
    errors: specify decoding error handler

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

Raises:
    DXFStructureError: for invalid or corrupted DXF structures
    UnicodeDecodeError: if `errors` is "strict" and a decoding error occurs

s   
   
r>   r?   r)   )
base64	b64decodereplacedecodeioStringIOr@   closer.   r!   )r9   r*   binary_datatextr"   r;   r   s          r   decode_base64rW      s    ( ""4(K %%gu5K
 gh7D[[F6"D
LLN dmmF;D[[F v,C
LLNJr   c                ,   [         R                  " U 5      R                  5       (       a  U $ Uc  / nU H]  nUR                  S5      n[         R                  " U5      R	                  5       U -  nUR                  5       (       d  MR  [        U5      s  $    U $ )z1Find file `filename` in the support directories`.z"')pathlibPathexistsstrip
expanduserr2   )r5   support_dirs	directoryfilepaths       r   find_support_filera   	  s~     ||H$$&&!	OOE*	<<	*557(B??x= 	 "
 Or   )r   r2   r   zUnion[str, bool, Sequence[str]]r   intreturnr   )r"   r   rc   r   )Nsurrogateescape)r5   str | os.PathLiker.   Optional[str]r*   r2   rc   r   )r5   re   rc   r   )r"   r   rc   r   )rI   re   r5   rf   r*   r2   rc   r   )rd   )r9   bytesr*   r2   rc   r   )N)r5   r2   r^   zOptional[Sequence[str]]rc   r2   )
__future__r   typingr   r   r   r   r   rN   rR   rY   osezdxf.tools.standardsr	   ezdxf.lldxf.constr
   r    r   r/   r   r   r!   r<   r7   r@   rK   rW   ra    r   r   <module>rn      s   # C C  	  	 / % "- -233*3 3 	3l 8 ##@@@ @ 	@F#  ##  	B(X <@!8r   