
    )ix                         S SK r S SKr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  SSKJr  SSKJrJr  SSKJrJrJr   " S	 S
\5      rg)    N)StringIO)chain)AnyDictListOptionalSetTextIO   )utils)T_obj
T_obj_list)CSV_COLS_REQUIREDCSV_COLS_TO_PREPEND
Serializerc                      \ rS rSr/ SQr\S\\\      4S j5       r	\S\
\\4   4S j5       rS!S\\\      S\
\\4   4S jjrS!S	\\\      SS4S
 jjr\S\4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r      S"S\\   S\\\      S\\\      S\\\      S\\   S\\   S\\   4S jjr      S#S\\   S\\\      S\\   S\\\      S\\\      S\\   4S jjr!S r"g)$	Container   )_rect_edges_curve_edges_edges_objectsreturnc                     g N selfs    T/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/pdfplumber/container.pypagesContainer.pages           c                     g r   r   r   s    r   objectsContainer.objects   r"   r#   Nobject_typesc                     g r   r   )r   r'   s     r   to_dictContainer.to_dict   s    r#   
propertiesc                 r    Uc  U R                   OUnU H   n[        X5      (       d  M  [        X5        M"     g r   )cached_propertieshasattrdelattr)r   r+   propsps       r   flush_cacheContainer.flush_cache   s1    *4*<&&*At  r#   c                 :    U R                   R                  S/ 5      $ )Nrectr%   getr   s    r   rectsContainer.rects        ||++r#   c                 :    U R                   R                  S/ 5      $ )Nliner6   r   s    r   linesContainer.lines$   r:   r#   c                 :    U R                   R                  S/ 5      $ )Ncurver6   r   s    r   curvesContainer.curves(       ||,,r#   c                 :    U R                   R                  S/ 5      $ )Nimager6   r   s    r   imagesContainer.images,   rC   r#   c                 :    U R                   R                  S/ 5      $ )Ncharr6   r   s    r   charsContainer.chars0   r:   r#   c                 :    U R                   R                  S/ 5      $ )Ntextboxverticalr6   r   s    r   textboxverticalsContainer.textboxverticals4   s    || 1266r#   c                 :    U R                   R                  S/ 5      $ )Ntextboxhorizontalr6   r   s    r   textboxhorizontalsContainer.textboxhorizontals8   s    || 3R88r#   c                 :    U R                   R                  S/ 5      $ )Ntextlineverticalr6   r   s    r   textlineverticalsContainer.textlineverticals<   s    || 2B77r#   c                 :    U R                   R                  S/ 5      $ )Ntextlinehorizontalr6   r   s    r   textlinehorizontalsContainer.textlinehorizontals@   s    || 4b99r#   c                     [        U S5      (       a  U R                  $ S U R                   5       n[        [	        U6 5      U l        U R                  $ )Nr   c              3   N   #    U  H  n[         R                  " U5      v   M     g 7fr   )r   rect_to_edges.0rs     r   	<genexpr>'Container.rect_edges.<locals>.<genexpr>H   s     E*Q%--a00*   #%)r.   r   r8   listr   )r   rect_edges_gens     r   
rect_edgesContainer.rect_edgesD   sG    4''###E$**E'+E>,B'Cr#   c                     [        U S5      (       a  U R                  $ S U R                   5       n[        [	        U6 5      U l        U R                  $ )Nr   c              3   N   #    U  H  n[         R                  " U5      v   M     g 7fr   )r   curve_to_edgesr_   s     r   rb   (Container.curve_edges.<locals>.<genexpr>P   s     HKq5//22Krd   )r.   r   rA   re   r   )r   curve_edges_gens     r   curve_edgesContainer.curve_edgesL   sG    4(($$$HDKKH(,UO-D(E   r#   c                     [        U S5      (       a  U R                  $ [        [        [        R
                  U R                  5      5      nXR                  -   U R                  -   U l        U R                  $ )Nr   )	r.   r   re   mapr   line_to_edger=   rg   rn   )r   
line_edgess     r   edgesContainer.edgesT   sW    4"";;#e00$**=>
",">AQAQ"Q{{r#   c                 `    S[         S[        4S jn[        [        XR                  5      5      $ )Nxr   c                 $    [        U S   S:H  5      $ )Norientationhboolrw   s    r   test(Container.horizontal_edges.<locals>.test^       -(C/00r#   r   r|   re   filterrt   r   r~   s     r   horizontal_edgesContainer.horizontal_edges\   +    	1E 	1d 	1 F4,--r#   c                 `    S[         S[        4S jn[        [        XR                  5      5      $ )Nrw   r   c                 $    [        U S   S:H  5      $ )Nry   vr{   r}   s    r   r~   &Container.vertical_edges.<locals>.teste   r   r#   r   r   s     r   vertical_edgesContainer.vertical_edgesc   r   r#   streaminclude_attrsexclude_attrs	precisionindentc                     U R                  U5      n[        UUUS9R                  U5      nUc  [        R                  " XS9$ [        R
                  " XUS9  g )Nr   r   r   )r   )r)   r   	serializejsondumpsdump)	r   r   r'   r   r   r   r   data
serializeds	            r   to_jsonContainer.to_jsonj   sZ     ||L)''
 )D/	 	 >::j88IIj8r#   c           
         Uc  [        5       nSnOSnUc'  [        U R                  R                  5       5      S/-   n/ n[	        5       nU R
                  c  U /OU R
                  n	[        UUUS9n
U	 H  nU H  n[        XS-   5      n[        U5      (       d  M#  XzR                  U5      -  nUS   R                  5        VVs/ s H  u  p[        U5      [        Ld  M  UPM     nnnUR                  [	        U5      5      nM     M     [        [        [        [	        U5      [	        [         [        -   5      -
  5      5      -   n[         [        [#        U
R$                  U5      5      -   n[&        R(                  " UUSS9nUR+                  5         UR-                  U5        U(       a!  UR/                  S5        UR1                  5       $ g s  snnf )	NTFannotr   sr   ignore)
fieldnamesextrasaction)r   re   r%   keyssetr    r   getattrlenr   itemstypedictunionr   sortedr   r   attr_filtercsv
DictWriterwriteheader	writerowsseekread)r   r   r'   r   r   r   	to_stringr   fieldsr    
serializerpagetobjskr   new_keysnon_req_colscolsws                       r   to_csvContainer.to_csv   s    >ZFII 1 1 34y@L
5**,$**''


 D!tW-t99"6"6t"<<J.21gmmoUodaaPTAToHU#\\#h-8F "  +T3v;%69L%L!MMN.
 
 !4z/E/E|(T#UUNN6dJ		JKKN;;= #  Vs   G
G
)r   r   r   r   )NNNNNN)NNNNN)#__name__
__module____qualname____firstlineno__r-   propertyr   r   r   r    r   strr   r%   r)   r2   r8   r=   rA   rF   rJ   rN   rR   rV   rZ   rg   rn   rt   r   r   r
   intr   r   __static_attributes__r   r#   r   r   r      s   MxS	*   c:o.  HT#Y$7 4S> !htCy&9 !T ! ,z , , ,z , , -
 - - -
 - - ,z , , 7* 7 7 9J 9 9 8: 8 8 :Z : :  J     !Z ! ! z   .* . . .
 . . $(,0-1-1#' $  tCy)  S	*	
  S	* C=  
#4 $(,0#'-1-11 1 tCy)1 C=	1
  S	*1  S	*1 
#1 1r#   r   )r   r   ior   	itertoolsr   typingr   r   r   r   r	   r
    r   _typingr   r   convertr   r   r   objectr   r   r#   r   <module>r      s1    
    9 9  & G Gg gr#   