
    he%                    F   S r SSKJr  SSKJrJrJrJrJrJ	r	J
r
  SSKJr  SSKJr  SSKJrJr  SSKJr  SSKJrJr  SS	KJr  SS
KJr  \(       a  SSKJr  SrSrSrSr Sr!Sr"Sr#Sr$Sr%Sr&Sr'SS/r( " S S5      r)S!S jr*S"S jr+S#S jr,S$S jr-S%S jr. " S S5      r/S&S jr0g )'a
  
UserRecord(): store user data in a XRECORD entity.

The group code 302 is used as a structure tag.

All supported data types have a fixed group code:
    - str: 1
    - int: 90 - 32-bit values
    - float: 40 - doubles
    - Vec3, Vec2: 10, 20, 30 - Vec2 is stored as Vec3
    - list, tuple: starts with tag (302, "[") and ends with tag (302, "]")
    - dict: starts with tag (302, "{") and ends with tag (302, "}")

The str type can have a max. length of 2049 characters and cannot contain "
"
or "".

This is an advanced feature for experienced programmers, handle with care!
The attribute UserRecord.data is a simple Python list with read/write access.

The UserRecord can store nested list and dict objects.

BinaryData(): store arbitrary binary data in a XRECORD entity

    )annotations)TYPE_CHECKINGOptionalIterableSequenceMappingMutableSequencecast)const)XRecord)Tagsbinary_data_to_dxf_tags)dxftag)Vec3Vec2)take2)bytes_to_hexstr)Drawing      Z   (   
   i.  []{}
UserRecordBinaryRecordc                  h    \ rS rSr S\SS.     SS jjjr\SS j5       rS rS r	S r
SS	 jrS
rg)r   ?   N)namedocc                  UcC  Uc  [         R                  " 5       nO*[        [         UR                  R	                  S0 5      5      nXl        [        U5      U l        [        U R
                  U R                  5      U l	        g)aR  Setup a :class:`UserRecord` with the given `name`.

The data is stored in the given `xrecord` object, or in a new created
:class:`~ezdxf.entities.XRecord` instance if ``None``. If `doc` is not
``None`` the new xrecord is added to the OBJECTS section of the DXF
document.

Changes of the content has to be committed at the end to be stored in
the underlying :attr:`xrecord` object.

Args:
    xrecord (XRecord): underlying :class:`~ezdxf.entities.XRecord` instance,
        if ``None`` a new one will be created
    name (str): name of the user list
    doc (Drawing): DXF document or ``None``

NXRECORD)
r   newr
   objects
new_entityxrecordstrr"   parse_xrecorddata)selfr)   r"   r#   s       ?/var/www/html/env/lib/python3.13/site-packages/ezdxf/urecord.py__init__UserRecord.__init__@   s\    0 ?{!++-w(>(>y"(MNI	%24<<%K	    c                L    U R                   R                  R                  S5      $ zGDXF handle of the underlying :class:`~ezdxf.entities.XRecord` instance.handler)   dxfgetr-   s    r.   r4   UserRecord.handleb        ||##H--r1   c                    U $ N r8   s    r.   	__enter__UserRecord.__enter__g       r1   c                $    U R                  5         g r<   commitr-   exc_typeexc_valexc_tbs       r.   __exit__UserRecord.__exit__j       r1   c                ,    [        U R                  5      $ zReturn str(self).)r*   r,   r8   s    r.   __str__UserRecord.__str__m   s    499~r1   c                x    [        U R                  U R                  5      U R                  l        U R                  $ )a  Store :attr:`data` in the underlying :class:`~ezdxf.entities.XRecord`
instance. This call is not required if using the class by the ``with``
statement.

Raises:
    DXFValueError: invalid chars ``"\n"`` or ``"\r"`` in a string
    DXFTypeError: invalid data type

)compile_user_recordr"   r,   r)   tagsr8   s    r.   rC   UserRecord.commitq   s)     0		499E||r1   )r,   r"   r)   r<   )r)   Optional[XRecord]r"   r*   r#   Optional[Drawing]returnzOptional[str]rV   r   )__name__
__module____qualname____firstlineno__DEFAULT_NAMEr/   propertyr4   r>   rH   rM   rC   __static_attributes__r=   r1   r.   r   r   ?   sc     &* L !!% L" L 	 L
  LD . .r1   c                    / nU R                   nU(       a^  US   u  pEU[        :w  a)  XQ:w  a$  [        R                  " [	        U 5       SU 35      eUR                  S [        USS  5       5       5        U$ )Nr   z is not an user record of type c              3  $   #    U  H  ov   M     g 7fr<   r=   ).0items     r.   	<genexpr> parse_xrecord.<locals>.<genexpr>   s     ;%:TD%:s   r   )rQ   TYPE_GROUP_CODEr   DXFTypeErrorr*   extendparse_items)r)   r"   r,   rQ   codevalues         r.   r+   r+      st    D<<D1g?"u}$$w<. ?vF  	;[ab%:;;Kr1   c                ~   / n/ nU  GH`  nUu  pEU[         :X  a  UR                  [        U5      5        M.  U[        :X  a  UR                  [	        U5      5        MT  U[
        :X  a  UR                  [        U5      5        Mz  U[        :X  a  UR                  [        U5      5        M  U[        :X  a)  U[        :X  d
  U[        :X  a  UR                  U5        / nM  U[        :X  ai  U[        :X  d
  U[        :X  aU   UR                  5       nU[        :X  a$  UR                  [%        ['        U5      5      5        OUR                  U5        UnGMF  [         R(                  " SU SU S35      e   U(       a  [         R"                  " S[         S35      eU$ ! [         a    [         R"                  " S[         S35      ef = f)Nz6invalid nested structure, mismatch of structure tags (z, ...)zinvalid group code in tag: (z, )z5invalid nested structure, mismatch of structure tags()STR_GROUP_CODEappendr*   INT_GROUP_CODEintFLOAT_GROUP_CODEfloatVEC3_GROUP_CODEr   COLLECTION_GROUP_CODE
START_LIST
START_DICTEND_LISTEND_DICTpop
IndexErrorr   DXFStructureErrordictr   DXFValueError)rQ   stackitemstagri   rj   
prev_levels          r.   rh   rh      s   EE>!LLU$^#LLU$%%LLu&_$LLe%**Z5J#6LLE**X(!2"YY[
  !!$uU|"45!!%(E%%.tfBugQ? ? D %%%&f.
 	
 L'  --./v7 s   9F)F<c                    [        5       nUR                  [        [        U 5      5        UR	                  [        U5      5        U$ r<   )r   rn   r   re   rg   tags_from_list)r"   r,   rQ   s      r.   rP   rP      s2    6DKK-.KKt$%Kr1   c           	         [        5       nU  GH|  n[        U[        5      (       ah  [        U5      S:  a  [        R
                  " S5      eSU;   d  SU;   a  [        R
                  " S5      eUR                  [        [        U5      5        M  [        U[        5      (       a!  UR                  [        [        U5      5        M  [        U[        5      (       a!  UR                  [        [        U5      5        M  [        U[        5      (       a"  UR                  [        [        U5      5        GM$  [        U[        5      (       a+  UR                  [        [        [        U5      5      5        GMd  [        U[         5      (       ac  UR                  [        ["        [$        5      5        UR'                  [)        U5      5        UR                  [        ["        [*        5      5        GM  [        U[,        5      (       al  UR                  [        ["        [.        5      5        UR'                  [)        [1        U5      5      5        UR                  [        ["        [2        5      5        GM]  [        R4                  " S[7        U5       35      e   U$ )Ni  z%string too long, max. 2049 characters
z%found invalid line break '\n' or '\r'zunsupported type: )r   
isinstancer*   lenr   r}   rn   r   rm   rp   ro   rr   rq   r   rs   r   r   rt   ru   rg   r   rw   r   rv   key_value_listrx   rf   type)r   rQ   rb   s      r.   r   r      s   6DdC  4y4));  t|tt|))=  KK~t45c""KK~t45e$$KK/67d##KK56d##KKT
;<h''KK4jABKKt,-KK4h?@g&&KK4jABKK~d';<=KK4h?@$$'9$t*%FGG9 : Kr1   c              #  N   #    U R                  5        H  u  pUv   Uv   M     g 7fr<   )r   )r,   kvs      r.   r   r      s!     

 s   #%c                  f    \ rS rSr SSS.   SS jjjr\SS j5       rS rS rSS jr	SS	 jr
S
rg)r      N)r#   c                   UcC  Uc  [         R                  " 5       nO*[        [         UR                  R	                  S0 5      5      nXl        [        U R
                  R                  5      U l        g)a  Setup a :class:`BinaryRecord`.

The data is stored in the given `xrecord` object, or in a new created
:class:`~ezdxf.entities.XRecord` instance if ``None``. If `doc` is not
``None`` the new xrecord is added to the OBJECTS section of the DXF
document.

Changes of the content has to be committed at the end to be stored in
the underlying :attr:`xrecord` object.

Args:
    xrecord (XRecord): underlying :class:`~ezdxf.entities.XRecord` instance,
        if ``None`` a new one will be created
    doc (Drawing): DXF document or ``None``

Nr%   )	r   r&   r
   r'   r(   r)   parse_binary_datarQ   r,   )r-   r)   r#   s      r.   r/   BinaryRecord.__init__   sQ    , ?{!++-w(>(>y"(MN,T\\->->?	r1   c                L    U R                   R                  R                  S5      $ r3   r5   r8   s    r.   r4   BinaryRecord.handle  r:   r1   c                    U $ r<   r=   r8   s    r.   r>   BinaryRecord.__enter__  r@   r1   c                $    U R                  5         g r<   rB   rD   s       r.   rH   BinaryRecord.__exit__  rJ   r1   c                ,    [        U R                  5      $ rL   )r   r,   r8   s    r.   rM   BinaryRecord.__str__  s    tyy))r1   c                    [        U R                  [        [        [        45      (       d   S5       e[        U R                  SSSS9U R                  l        U R                  $ )zStore binary :attr:`data` in the underlying :class:`~ezdxf.entities.XRecord`
instance. This call is not required if using the class by the ``with``
statement.

zexpected binary data   6     )length_group_codevalue_group_code
value_size)r   r,   bytes	bytearray
memoryviewr   r)   rQ   r8   s    r.   rC   BinaryRecord.commit  sb     IIy*5
 
 	"!	" 
 4II! 	
 ||r1   )r,   r)   r<   )r)   rS   r#   rT   rU   )rV   r*   rW   )rX   rY   rZ   r[   r/   r]   r4   r>   rH   rM   rC   r^   r=   r1   r.   r   r      sT     &*@ "&	@"@ 	@> . .*r1   c                h    U (       a+  U S   R                   S:X  a  SR                  S U  5       5      $ g)Nr   r   r1   c              3  \   #    U  H"  oR                   S :X  d  M  UR                  v   M$     g7f)r   N)ri   rj   )ra   ts     r.   rc   $parse_binary_data.<locals>.<genexpr>,  s     ?A3s   ,,)ri   join)rQ   s    r.   r   r   *  s,    Q#xx????r1   N)r)   r   r"   r*   rV   list)rQ   r   rV   r   )r"   r*   r,   r   rV   r   )r   r   rV   r   )r,   r   rV   r   )rQ   r   rV   r   )1__doc__
__future__r   typingr   r   r   r   r   r	   r
   ezdxf.lldxfr   ezdxf.entitiesr   ezdxf.lldxf.tagsr   r   ezdxf.lldxf.typesr   
ezdxf.mathr   r   ezdxf.toolsr   ezdxf.tools.binarydatar   ezdxf.documentr   re   rm   ro   rq   rs   rt   ru   rw   rv   rx   r\   __all__r   r+   rh   rP   r   r   r   r   r=   r1   r.   <module>r      s   0 #    " : $ !  2&  


(= =@
*ZD? ?Dr1   