
    h3h                       % S SK Jr  S SKJrJrJrJrJrJr  S SK	r	S SK
Jr  S SKJrJr  S SKJrJr  S SKJrJr  S SKJr  S S	KJr  S S
KJrJr  \(       a(  S SKJr  S SKJr  S SKJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(  S SK)J*r*  \	RV                  " S5      r, " S S5      r-/ SQr.0 SS_SS_SS_SS_SS_SS_SS _S!S"_S#S$_S%S&_S'S(_S)S*_S+S,_S-S._S/S0_S1S2_S3S4_S5S60Er/S7\0S8'    " S9 S:5      r1g);    )annotations)IterableIteratorOptionalTYPE_CHECKINGUnioncastN)
Dictionary)factoryis_dxf_object)const	validator)EntitySpaceEntityDB)EntityQuery)UnderlayKeyGenerator)Auditor
AuditError)Drawing)AbstractTagWriter)	GeoDataDictionaryVarDXFTagStorage	DXFObjectImageDefUnderlayDefinitionDictionaryWithDefaultXRecordPlaceholder)ImageDefReactorezdxfc                     \ rS rSrS(S)S jjr\S*S j5       rS+S jrS 4S,S jjrS-S jr	S.S	 jr
S/S
 jrS0S jrS1S jrS2S jrS3S jrS0S jrS4S jrS r\S2S j5       rS5S jrS6S jrS7S jrS rS8S9S jjrS:S jrS;S<S jjr S=   S>S jjrS?S@S jjrSASBS jjrSASCS jjr SD       SES jjrSFS jr SGSHS  jjr!S5S! jr" S(       SIS" jjr#SJS# jr$ SK       SLS$ jjr%SMSNS% jjr&S(SOS& jjr'S'r(g)PObjectsSection)   Nc                    Xl         [        5       U l        [        5       U l        Ub  U R                  [        U5      5        g g N)docr   underlay_key_generatorr   _entity_space_builditer)selfr'   entitiess      H/var/www/html/env/lib/python3.13/site-packages/ezdxf/sections/objects.py__init__ObjectsSection.__init__*   s7    &:&<#(]KKX'      c                .    U R                   R                  $ )z/Returns drawing entity database. (internal API))r'   entitydbr,   s    r.   r3   ObjectsSection.entitydb1   s     xx   r1   c                    U R                   $ )z$Returns entity space. (internal API)r)   r4   s    r.   get_entity_spaceObjectsSection.get_entity_space6   s    !!!r1   c                    gNT )ks    r.   <lambda>ObjectsSection.<lambda>:   s    Dr1   c                Z     U R                   R                  5       nU" U5      (       a  U$ M+  r&   )r(   next)r,   	checkfunckeys      r.   next_underlay_key ObjectsSection.next_underlay_key:   s,    --224C~~
 r1   c                    [        S[        U5      5      nUR                  5       S:w  d  UR                  S   S:w  a  [        R
                  " S5      eU H  nU R                  R                  U5        M      g )Nr   SECTION   )   OBJECTSz0Critical structure error in the OBJECTS section.)r	   rA   dxftype
base_classr   DXFStructureErrorr)   add)r,   r-   section_headentitys       r.   r*   ObjectsSection._build@   su    OT(^<!Y.,2I2I!2L Q
 3
 ))B  F ""6* r1   c                    UR                  S5        U R                  R                  U5        UR                  SS5        g)z0Export DXF entity by `tagwriter`. (internal API)z  0
SECTION
  2
OBJECTS
r   ENDSECN)	write_strr)   
export_dxf
write_tag2)r,   	tagwriters     r.   rU   ObjectsSection.export_dxfP   s5    :;%%i0Q)r1   c                ~    [         R                  " XU R                  5      nU R                  R	                  U5        U$ )zCreate new DXF object, add it to the entity database and to the
entity space.

Args:
     _type: DXF type like `DICTIONARY`
     dxfattribs: DXF attributes as dict

(internal API)
)r   create_db_entryr'   r)   rN   )r,   _type
dxfattribs
dxf_entitys       r.   
new_entityObjectsSection.new_entityV   s4     ,,UI
z*r1   c                p    U R                   R                  U5        U R                  R                  U5        g)zDRemove `entity` from entity space and destroy object. (internal API)N)r)   remover3   delete_entityr,   rP   s     r.   rb   ObjectsSection.delete_entityd   s(    !!&)##F+r1   c                    U R                   nU R                   H  nUR                  U5        M     U R                  R                  5         g)z&Delete all DXF objects. (internal API)N)r3   r)   rb   clear)r,   dbrP   s      r.   delete_all_entities"ObjectsSection.delete_all_entitiesi   s;    ]]((FV$ )  "r1   c                    [        U 5      (       a  [        R                  " S5      e[        R	                  S5        U R                  SSS9$ )z[Create a root dictionary. Has to be the first object in the objects
section. (internal API)z=Can not create root dictionary in none empty objects section.zCreating ROOT dictionary.0Fowner
hard_owned)lenr   rM   loggerdebugadd_dictionaryr4   s    r.   setup_rootdictObjectsSection.setup_rootdictp   sH     t99))O  	01"""??r1   c                t  ^ ^ UU 4S jnS
UU 4S jjn[          H  nTR                  U5      n[        U[        5      (       a  M+  [        R                  SU S35        US:X  a  U" 5         OTR                  USS9  [        U[        5      (       d  My  [        R                  " U5      (       d  M  U" XES9  M     g	)z0Setup required management tables. (internal API)c                    > TR                  TR                  R                  SS9n TR                  U R                  R                  S9nU R	                  U5        XS'   U TS'   g )NFrl   )rm   NormalACAD_PLOTSTYLENAME)add_dictionary_with_defaultdxfhandleadd_placeholderset_default)plot_style_name_dictplaceholderrootdictr,   s     r.   setup_plot_style_name_tableRObjectsSection.setup_object_management_tables.<locals>.setup_plot_style_name_table~   sm    #'#C#Cll))  $D $  ..5I5M5M5T5T.UK ,,[9-8*-AH)*r1   c                   > TR                  U 5      n[        U[        5      (       aG  TR                  R                  R                  X!5      (       a  [        R                  SU  SU 35        g g g )Nzreset handle of table z to #)get
isinstancer
   r'   r3   reset_handlerp   rq   )
table_namer{   	new_tabler   r,   s      r.   restore_table_handleKObjectsSection.setup_object_management_tables.<locals>.restore_table_handle   sc     !Z0I)Z00TXX5F5F5S5S6 6 5j\vhOP60r1   z	creating z dictionaryrx   F)rn   )r{   N)r   strr{   r   returnNone)
_OBJECT_TABLE_NAMESr   r   r
   rp   infoadd_new_dictr   r   	is_handle)r,   r   r   r   nametables   ``    r.   setup_object_management_tables-ObjectsSection.setup_object_management_tables{   s    	B	Q 	Q (D2:,,t2DE %,,KK)D656+++-%%du%=%%%)*=*=e*D*D$T8 (r1   c                    [        U5      (       a  U R                  R                  U5        g[        R                  " SUR                  5        S35      e)z/Add `entity` to OBJECTS section. (internal API)zinvalid DXF type z for OBJECTS sectionN)r   r)   rN   r   DXFTypeErrorrK   rc   s     r.   
add_objectObjectsSection.add_object   sI      ""6*$$#FNN$4#55IJ r1   c                R    U R                  X5      nUR                  US   /5        U$ )z+Add DXF object with reactor. (internal API)rm   )r^   set_reactors)r,   rK   r\   	dxfobjects       r.   add_dxf_object_with_reactor*ObjectsSection.add_dxf_object_with_reactor   s,    OOG8	
7 345r1   c                8    U R                   R                  5         g r&   )r)   purger4   s    r.   r   ObjectsSection.purge   s      "r1   c                `    [        U 5      (       a  U R                  S   $ U R                  5       $ )zKReturns the root DICTIONARY, or as AutoCAD calls it:
the named DICTIONARY.
r   )ro   r)   rs   r4   s    r.   r   ObjectsSection.rootdict   s-    
 t99%%a((&&((r1   c                ,    [        U R                  5      $ )z<Returns the count of all DXF objects in the OBJECTS section.)ro   r)   r4   s    r.   __len__ObjectsSection.__len__   s    4%%&&r1   c                ,    [        U R                  5      $ )z>Returns an iterator of all DXF objects in the OBJECTS section.)r+   r)   r4   s    r.   __iter__ObjectsSection.__iter__   s    D&&''r1   c                     U R                   U   $ )aW  Get entity at `index`.

The underlying data structure for storing DXF objects is organized like
a standard Python list, therefore `index` can be any valid list indexing
or slicing term, like a single index ``objects[-1]`` to get the last
entity, or an index slice ``objects[:10]`` to get the first 10 or fewer
objects as ``list[DXFObject]``.

r7   )r,   indexs     r.   __getitem__ObjectsSection.__getitem__   s     !!%((r1   c                    [        U[        5      (       a   U R                  U   nXR                  ;   $ ! [         a     gf = f)zxReturns ``True`` if `entity` stored in OBJECTS section.

Args:
     entity: :class:`DXFObject` or handle as hex string

F)r   r   r3   KeyErrorr)   rc   s     r.   __contains__ObjectsSection.__contains__   sI     fc""v. ++++  s   4 
A Ac                ,    [        [        U 5      U5      $ )z<Get all DXF objects matching the :ref:`entity query string`.)r   r+   )r,   querys     r.   r   ObjectsSection.query   s    4:u--r1   c                ^   U R                   UR                   L d   S5       eU R                   HQ  n[        U5      (       a  M  UR                  [        R
                  S[        U5       S3S9  UR                  U5        MS     U R                  U5        U R                  R                  U5        g)a  Audit and repair OBJECTS section.

.. important::

    Do not delete entities while auditing process, because this
    would alter the entity database while iterating, instead use::

        auditor.trash(entity)

    to delete invalid entities after auditing automatically.

z#Auditor for different DXF document.zRemoved invalid DXF entity z from OBJECTS section.codemessageN)
r'   r)   r   fixed_errorr   REMOVED_INVALID_DXF_OBJECTr   trashreorgaudit)r,   auditorrP   s      r.   r   ObjectsSection.audit   s     xx7;;&M(MM&((F ((###>>9#f+ G, - $ 
 f% ) 	

7  )r1   c                H    U R                  SUUS.S9n[        [        U5      $ )zAdd new :class:`~ezdxf.entities.Dictionary` object.

Args:
    owner: handle to owner as hex string.
    hard_owned: ``True`` to treat entries as hard owned.


DICTIONARYrl   r\   )r^   r	   r
   )r,   rm   rn   rP   s       r.   rr   ObjectsSection.add_dictionary  s4     ( ! 
 J''r1   c                B    U R                  SUUUS.S9n[        SU5      $ )zAdd new :class:`~ezdxf.entities.DictionaryWithDefault` object.

Args:
    owner: handle to owner as hex string.
    default: handle to default entry.
    hard_owned: ``True`` to treat entries as hard owned.

ACDBDICTIONARYWDFLT)rm   defaultrn   r   r   r^   r	   )r,   rm   r   rn   rP   s        r.   ry   *ObjectsSection.add_dictionary_with_default  s8     !"( ! 
 +V44r1   c                &    U R                  SXS.S9$ )zAdd a new :class:`~ezdxf.entities.DictionaryVar` object.

Args:
    owner: handle to owner as hex string.
    value: value as string

DICTIONARYVAR)rm   valuer   r^   )r,   rm   r   s      r.   add_dictionary_var!ObjectsSection.add_dictionary_var'  s"     %(H  
 	
r1   c                &    U R                  SSU0S9$ )zeAdd a new :class:`~ezdxf.entities.XRecord` object.

Args:
    owner: handle to owner as hex string.

XRECORDrm   r   r   r,   rm   s     r.   add_xrecordObjectsSection.add_xrecord3  s     ygu5EFFr1   c                &    U R                  SSU0S9$ )ziAdd a new :class:`~ezdxf.entities.Placeholder` object.

Args:
    owner: handle to owner as hex string.

ACDBPLACEHOLDERrm   r   r   r   s     r.   r|   ObjectsSection.add_placeholder<  s$     7E*:  
 	
r1   c           	     z   [         R                  R                  US5      n U R                  S   nXR                  l        X%R                  l        XER                  l        g! [         R                   aD    U R                  SU R                  R                  R                  UUUS.S9nXPR                  S'    gf = f)a  Set raster variables.

Args:
    frame: ``0`` = do not show image frame; ``1`` = show image frame
    quality: ``0`` = draft; ``1`` = high
    units: units for inserting images. This defines the real world unit for one
        drawing unit for the purpose of inserting and scaling images with an
        associated resolution.

           ===== ===========================
           mm    Millimeter
           cm    Centimeter
           m     Meter (ezdxf default)
           km    Kilometer
           in    Inch
           ft    Foot
           yd    Yard
           mi    Mile
           none  None
           ===== ===========================

(internal API), public interface :meth:`~ezdxf.drawing.Drawing.set_raster_variables`

r   ACAD_IMAGE_VARSRASTERVARIABLES)rm   framequalityunitsr   N)r   RASTER_UNITSr   r   rz   r   r   r   DXFKeyErrorr   r{   )r,   r   r   r   units_raster_varss         r.   set_raster_variables#ObjectsSection.set_raster_variablesI  s    6 ((,,UA6	+--(9:K %*OO!&-OO#$*OO!    
	;::!!]]..55"&#	 ; K 0;MM+,
	;s   A" "AB:9B:c                    U R                   S   nUR                  R                  UR                  R
                  [        R                  R                  UR                  R                  S5      4$ ! [        R                   a     gf = f)Nr   )r   rH   noner   )	r   r   r   rz   r   r   REVERSE_RASTER_UNITSr   r   )r,   r   s     r.   get_raster_variables#ObjectsSection.get_raster_variablesw  sv    	 --(9:K OO!!OO##&&**;??+@+@&I
 	
    	 	 s   A0 0BBc                    U R                   S   n[        U5      UR                  l        g! [        R
                   aK    U R                  SU R                   R                  R                  [        U5      S.S9nX R                   S'    gf = f)zsSet wipeout variables.

Args:
    frame: ``0`` = do not show image frame; ``1`` = show image frame

(internal API)
ACAD_WIPEOUT_VARSWIPEOUTVARIABLES)rm   r   r   N)r   intrz   r   r   r   r   r{   )r,   r   wipeout_varss      r.   set_wipeout_variables$ObjectsSection.set_wipeout_variables  s    	0==)<=L &)ZL"    	>;;"!]]..55 Z < L 2>MM-.	>s   , AB
Bc                     U R                   S   nUR                  R                  $ ! [        R                   a     gf = f)Nr   r   )r   r   r   rz   r   )r,   r   s     r.   get_wipeout_frame_setting(ObjectsSection.get_wipeout_frame_setting  sD    	==)<=L %%%    		s   ' >>c                    Uc  UnU R                   R                  S5      nU R                  SUR                  R                  UUS.S9nXTU'   [        SU5      $ )a  Add an image definition to the objects section.

Add an :class:`~ezdxf.entities.image.ImageDef` entity to the drawing
(objects section). `filename` is the image file name as relative or
absolute path and `size_in_pixel` is the image size in pixel as (x, y)
tuple. To avoid dependencies to external packages, `ezdxf` can not
determine the image size by itself. Returns a :class:`~ezdxf.entities.image.ImageDef`
entity which is needed to create an image reference. `name` is the
internal image name, if set to ``None``, name is auto-generated.

Absolute image paths works best for AutoCAD but not really good, you
have to update external references manually in AutoCAD, which is not
possible in TrueView. If the drawing units differ from 1 meter, you also
have to use: :meth:`set_raster_variables`.

Args:
    filename: image file name (absolute path works best for AutoCAD)
    size_in_pixel: image size in pixel as (x, y) tuple
    name: image name for internal use, None for using filename as name
        (best for AutoCAD)

ACAD_IMAGE_DICTIMAGEDEF)rm   filename
image_sizer   r   )r   get_required_dictr   rz   r{   r	   )r,   r   size_in_pixelr   
image_dict	image_defs         r.   add_image_defObjectsSection.add_image_def  sj    8 <D]]445FG
44#..$+ 5 
	 %4J	**r1   c                @    U R                  SUUS.S9n[        SU5      $ )zJAdd required IMAGEDEF_REACTOR object for IMAGEDEF object.

(internal API)
IMAGEDEF_REACTOR)rm   image_handler   r    r   )r,   r   image_def_reactors      r.   add_image_def_reactor$ObjectsSection.add_image_def_reactor  s7    
 !OO% , , 
 %'899r1   c                |  ^ UR                  5       nUS;   a  SU S3nU S3nO[        R                  " SU S35      eUc  US:X  a  SnOUS	:X  a  S
nOSnU R                  R	                  U5      mU R                  UTR                  R                  UUS.S9nU R                  U4S j5      nUTU'   [        SU5      $ )a  Add an :class:`~ezdxf.entities.underlay.UnderlayDefinition` entity
to the drawing (OBJECTS section). `filename` is the underlay file name
as relative or absolute path and `fmt` as string (pdf, dwf, dgn).
The underlay definition is required to create an underlay reference.

Args:
    filename: underlay file name
    fmt: file format as string ``'pdf'|'dwf'|'dgn'``
    name: pdf format = page number to display; dgn format = ``'default'``; dwf: ????

)PDFDWFDGNACAD_DEFINITIONS
DEFINITIONzUnsupported file format: ''r  1r  r   Model)rm   r   r   r   c                   > U T;  $ r&   r<   )r=   underlay_dicts    r.   r>   1ObjectsSection.add_underlay_def.<locals>.<lambda>  s
    q/Er1   r   )
upperr   DXFValueErrorr   r   r^   rz   r{   rD   r	   )	r,   r   fmtr   underlay_dict_nameunderlay_def_entityunderlay_defrC   r  s	           @r.   add_underlay_defObjectsSection.add_underlay_def  s     iik''#([!9%(E"4%%(B3%q&IJJ<e| 778JK&**11$ ' 
 $$%EF)c(,77r1   c                L    Uc  0 nXS'   [        SU R                  SU5      5      $ )a  Creates a new :class:`GeoData` entity and replaces existing ones.
The GEODATA entity resides in the OBJECTS section and NOT in the layout
entity space, and it is linked to the layout by an extension dictionary
located in BLOCK_RECORD of the layout.

The GEODATA entity requires DXF version R2010+. The DXF Reference does
not document if other layouts than model space supports geo referencing,
so getting/setting geo data may only make sense for the model space
layout, but it is also available in paper space layouts.

Args:
    owner: handle to owner as hex string
    dxfattribs: DXF attributes for :class:`~ezdxf.entities.GeoData` entity

rm   r   GEODATA)r	   r   )r,   rm   r\   s      r.   add_geodataObjectsSection.add_geodata  s1      J#7It??	:VWWr1   c                    Uc)  U R                   c   S5       e[        U R                   5      n[        X5      nUR                  5         U$ )z;Validate and recreate the integrity of the OBJECTS section.zvalid document required)r'   r   
_Sanitizerexecute)r,   r   	sanitizers      r.   r   ObjectsSection.reorg  sF    ?88'B)BB'dhh'Gw-	r1   )r)   r'   r(   r&   )r'   r   r-   zOptional[Iterable[DXFObject]])r   r   )r   r   )r   r   )r-   Iterator[DXFObject]r   r   )rW   r   r   r   )r[   r   r\   dictr   r   )rP   r   r   r   r   r   )r   r
   )r   r
   r   r   )rK   r   r   r   )r   r   )r   r!  )r   r   )*)r   r   r   r   )r   r   r   r   )rk   T)rm   r   rn   boolr   r
   )rk   rk   T)rn   r%  r   r   )rk    )rm   r   r   r   r   r   )rk   )rm   r   r   r   )rm   r   r   r   )r   rH   m)r   r   r   r   r   r   r   r   )r   ztuple[int, int, str])r   )r   r   r   r   )r   r   r   ztuple[int, int]r   Optional[str]r   r   )r   r   r   r    )pdfN)r   r   r  r   r   r(  r   r   )rk   N)rm   r   r   r   )r   zOptional[Auditor]r   r   ))__name__
__module____qualname____firstlineno__r/   propertyr3   r8   rD   r*   rU   r^   rb   rh   rs   r   r   r   r   r   r   r   r   r   r   r   rr   ry   r   r   r|   r   r   r   r   r   r  r  r  r   __static_attributes__r<   r1   r.   r#   r#   )   sm   ( ! !" +9 + *,
#	@'9R#
 ) )'(
),.*2($ :>5265	5*

G	
 >A,+,+'*,+7:,+	,+\	
0,& #	(+(+ '(+ 	(+
 
(+T: FJ*8*8"%*85B*8	*8XX* r1   r#   )
ACAD_COLOR
ACAD_GROUPACAD_LAYOUTACAD_MATERIALACAD_MLEADERSTYLEACAD_MLINESTYLEACAD_PLOTSETTINGSrx   ACAD_SCALELISTACAD_TABLESTYLEACAD_VISUALSTYLEr0  DBCOLORr1  GROUPr   r   ACAD_DETAILVIEWSTYLEACDBDETAILVIEWSTYLEr2  LAYOUTr3  MATERIALr4  MLEADERSTYLEr5  
MLINESTYLEr6  PLOTSETTINGSACAD_RENDER_ACTIVE_SETTINGSMENTALRAYRENDERSETTINGSr7  SCALEACAD_SECTIONVIEWSTYLEACDBSECTIONVIEWSTYLEr8  
TABLESTYLEACAD_PDFDEFINITIONSPDFDEFINITIONACAD_DWFDEFINITIONSDWFDEFINITIONACAD_DGNDEFINITIONSDGNDEFINITIONr9  VISUALSTYLEAcDbVariableDictionaryr   zdict[str, str]KNOWN_DICT_CONTENTc                  f    \ rS rSrSS jrSS jrSSS jjrSS jrSS jrSS jr	S r
S	 rS
 rSrg)r  iF  c                L    X l         Xl        UR                  U l        SU l        g r;   )objectsr   r   removed_entity)r,   r   rT  s      r.   r/   _Sanitizer.__init__G  s!    (("r1   c              #  h   #    U R                    H  n[        U[        5      (       d  M  Uv   M      g 7fr&   )rT  r   r
   )r,   ds     r.   dictionaries_Sanitizer.dictionariesM  s%     A!Z(( s   #2	2c                *   U R                  5         U R                  5         SnSU l        U R                  (       aI  X!:  aD  US-  nSU l        U R                  5         U R	                  5         U R                  (       a  X!:  a  MD  U R                  5         g )Nr   TrH   F)+restore_owner_handles_of_dictionary_entriesvalidate_known_dictionariesrU  remove_orphaned_dictionariesaudit_objectscreate_required_structures)r,   	max_loopsloopss      r.   r  _Sanitizer.executeR  s~    88:((*"!!e&7QJE"'D--/   !!e&7 	'')r1   c                B  ^ ^^^^	^
 SUUU 4S jjnUU	U
U 4S jnT R                   R                  nT R                  5        H  m/ m
TR                  R                  mTR                  5        H  u  m	m[        T[        5      (       a	  U" 5         M$  TR                  R                  S5      nUT:X  a  MG  UR                  U5      n[        U[        5      (       a  UR                  T5      (       a	  U" 5         M  U" 5         M     T
 H  m	TR                  T	5        M     M     g )Nc                    > T TR                   l        TR                  R                  [        R
                  ST S35        g )NzFixed invalid owner handle of .)rz   rm   r   r   r   INVALID_OWNER_HANDLE)dict_handlerP   r,   s   r.   reclaim_entityN_Sanitizer.restore_owner_handles_of_dictionary_entries.<locals>.reclaim_entitya  s6    *FJJLL$$//0:r1   c            	        > TR                  T5        TR                  R                  [        R                  ST S[        T 5       S35        g )NzRemoved invalid key z in rf  )appendr   r   r   rg  r   )
dictionaryrC   r   r,   s   r.   	purge_keyI_Sanitizer.restore_owner_handles_of_dictionary_entries.<locals>.purge_keyh  sA    LLLL$$//&se4J/@Br1   rm   r#  )r   r3   rY  rz   r{   itemsr   r   r   r
   find_keydiscard)r,   ri  rn  r3   owner_handleparent_dictrh  rm  rP   rC   r   s   `     @@@@@r.   r\  6_Sanitizer.restore_owner_handles_of_dictionary_entries`  s    	 		 	 <<((++-J!E$..//K)//1Vfc**K%zz~~g6;.&ll<8k:66;;O;OPV;W;WK"$  2 ""3' # .r1   c                r  ^^ UU4S jnU R                   R                  mU R                  nU R                  5        Hx  mTUL a  M
  TR	                  TR
                  R	                  S5      5      nUc	  U" 5         M@  [        U[        5      (       d  MW  UR                  T5      nU(       a  Mq  U" 5         Mz     g )Nc                 H   > TR                  T 5        T R                  5         g r&   )rr  _silent_kill)rm  r3   s   r.   kill_dictionary@_Sanitizer.remove_orphaned_dictionaries.<locals>.kill_dictionary  s    Z(##%r1   rm   )	r   r3   r   rY  r   rz   r   r
   rq  )r,   ry  r   rm   rC   rm  r3   s        @@r.   r^  '_Sanitizer.remove_orphaned_dictionaries  s    	& <<((==++-JX%LL!3!3G!<=E}  !eZ00..,C3!! .r1   c                   SSK Jn  U R                  n[        R	                  5        H  u  p4U R
                  R                  U5      n[        U[        5      (       d  M7  / nUR	                  5        H{  u  px[        X5      (       d  M  UR                  5       U:w  d  M-  UR                  [        R                  SU SU SU SU 35        UR                  U5        UR                  U5        M}     U H  nUR                  U5        M     M     g )Nr   )	DXFEntityzRemoved invalid type z from <z>, expected type )ezdxf.entitiesr}  r   rQ  rp  r   r   r   r
   rK   r   r   r   rl  r   rr  )	r,   r}  r   	dict_nameexpected_typeobject_dict
purge_keysrC   entrys	            r.   r]  &_Sanitizer.validate_known_dictionaries  s    ,,,(:(@(@(B$I--++I6Kk:66$&J)//1
e//EMMO}4T''"==/wf[M9+ V))69
 %%c*MM%( 2 "##C( " )Cr1   c                   U R                   R                  U R                  5        U R                   R                  nUR                  R                  5         UR                  R                  5         UR                  R                  5         UR                  R                  5         UR                  R                  5         UR                  R                  5         UR                  R                  5         g r&   )
rT  r   r   r'   	materialsupdate_object_dictcreate_required_entriesmline_stylesmleader_stylesgroups)r,   r'   s     r.   r`  %_Sanitizer.create_required_structures  s    33DMMBll((*--/++-002--/224

%%'r1   c                    U R                   R                  5         U R                   R                  R                  5         g r&   )r   empty_trashcanr3   r   r4   s    r.   cleanup_entitydb_Sanitizer.cleanup_entitydb  s(    ##%##%r1   c                   U R                  5         U R                  n[        UR                  5      nU R                   H  nUR
                  R                  S5      (       d>  UR                  [        R                  S[        U5       S3S9  UR                  U5        Ma  UR                  U5        UR                  U5        M     UR                  5         U[        UR                  5      :w  a  SU l        g g )Nrm   zDeleted z entity without owner handle.r   T)r  r   ro   r3   rT  rz   hasattrr   r   rg  r   r   check_owner_existr   r  rU  )r,   r   current_db_sizerP   s       r.   r_  _Sanitizer.audit_objects  s    ,,g../llF::%%g..###88&s6{m3PQ $  f%%%f-LL! # 	 c'"2"233"&D 4r1   )r   rT  rU  r   N)r   r   rT  r#   r   r   )r   zIterator[Dictionary])d   r#  )r*  r+  r,  r-  r/   rY  r  r\  r^  r]  r`  r  r_  r/  r<   r1   r.   r  r  F  s0    #
*"(H"2)*
(&'r1   r  )2
__future__r   typingr   r   r   r   r   r	   loggingezdxf.entities.dictionaryr
   r  r   r   ezdxf.lldxfr   r   ezdxf.entitydbr   r   ezdxf.queryr   ezdxf.tools.handler   ezdxf.auditr   r   ezdxf.documentr   ezdxf.lldxf.tagwriterr   r   r   r   r   r   r   r   r   r   ezdxf.entities.imager    	getLoggerrp   r#   r   rQ  __annotations__r  r<   r1   r.   <module>r     sb   #   0 1 ( 0 # 3 +&7
 
 
 5			7	#v vr &)&'& z& 1	&
 8& Z& & |& & "#<& g& 3& |& ?& ?&  ?!&" #&$ o%& N ,O' O'r1   