
    9i@L                        S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  / SQr	SS	K
r
SS	KrSS	KrSS	KrSS	KrSS
KJrJr  SSKJr  SSKJr  SSKJr  SS	KJs  Js  Jr  SrSr\
R>                  " S\
R@                  5      r! " S S\"5      r# " S S\#5      r$Sr% " S S\#5      r&\'" \(" \RR                  S-
  5      5      r*S\*-  r+\#RX                  r,g	)z:Classes to generate plain text from a message object tree.    )print_function)unicode_literals)division)absolute_import)super)str)	GeneratorDecodedGeneratorBytesGeneratorN)StringIOBytesIO)compat32)Header)_has_surrogates_
z^From c                       \ rS rSrSrSS jrS rSS jrS rSr	S	 r
S
 rS rS rS rS rS r\rS rS rS rS r\SS j5       r\S 5       rSrg)r	   !   z~Generates output from a Message object tree.

This basic generator writes the message to the given file object as plain
text.
Nc                 V    SU;   a  US   oTS	 OS n Xl         X l        X0l        XPl        g )Npolicy)_fp_mangle_from_maxheaderlenr   )selfoutfpmangle_from_r   _3to2kwargsr   s         `/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/future/backports/email/generator.py__init__Generator.__init__+   s;    {"[-BFT\H]f	* )(    c                 :    U R                   R                  U5        g N)r   writer   ss     r   r$   Generator.writeH   s    qr!   c                    U R                   c  UR                   OU R                   nUb  UR                  US9nU R                  b  UR                  U R                  S9nUR                  U l        U R                  U R                  5      U l        SU l        U R                  S5      U l        U R                   nUR                   n X@l         XAl         U(       a`  UR                  5       nU(       d,  S[        R                  " [        R                  " 5       5      -   nU R                  XpR                  -   5        U R                  U5        XPl         Xal         g! XPl         Xal         f = f)a2  Print the message object tree rooted at msg to the output file
specified when the Generator instance was created.

unixfrom is a flag that forces the printing of a Unix From_ delimiter
before the first object in the message tree.  If the original message
has no From_ delimiter, a `standard' one is crafted.  By default, this
is False to inhibit the printing of any From_ delimiter.

Note that for subobjects, no From_ line is printed.

linesep specifies the characters used to indicate a new line in
the output.  The default value is determined by the policy.

N)linesepmax_line_length zFrom nobody )r   cloner   r)   _NL_encode_encoded_NL_EMPTY_encoded_EMTPYget_unixfromtimectimer$   _write)r   msgunixfromr)   r   old_gen_policyold_msg_policyufroms           r   flattenGenerator.flattenL   s   &  ${{2\\'\2F(\\$2C2C\DF>><<1"ll2.
 	( KJ((**TZZ		-DDE

588+,KK(K'J )K'Js   BE E$c                 N    U R                  UU R                  SU R                  S9$ )z1Clone this generator with the exact same options.N)r   )	__class__r   r   )r   fps     r   r-   Generator.clone{   s-    ~~b"00"%)[[  2 	2r!   r,   c                     [        5       $ r#   )r   r   s    r   _new_bufferGenerator._new_buffer   s
    zr!   c                     U$ r#    r%   s     r   r/   Generator._encode   s    r!   c                 |   U(       d  g UR                  S5      nUS S  H>  nU R                  UR                  S5      5        U R                  U R                  5        M@     US   R                  S5      nU R                  U5        [	        US   5      [	        U5      :w  a  U R                  U R                  5        g g )NTz
)
splitlinesr$   rstripr.   len)r   lineslinelaststrippeds       r   _write_linesGenerator._write_lines   s      &#2JDJJt{{6*+JJtxx   Ry''/

< uRy>S..JJtxx  /r!   c                 6   U R                   n U R                  5       =U l         nU R                  U5        X l         [        USS 5      nUc  U R	                  U5        OU" U 5        U R                   R                  UR                  5       5        g ! X l         f = f)N_write_headers)r   rD   	_dispatchgetattrrT   r$   getvalue)r   r7   oldfpsfpmeths        r   r6   Generator._write   s     	!--//DHsNN3H s,d3<$Js||~& Hs   (B Bc                 (   UR                  5       nUR                  5       n[        R                  X#45      R	                  SS5      n[        U SU-   S 5      nUc1  UR	                  SS5      n[        U SU-   S 5      nUc  U R                  nU" U5        g )N-r   _handle_)get_content_maintypeget_content_subtype
UNDERSCOREjoinreplacerV   
_writeBody)r   r7   mainsubspecificrZ   generics          r   rU   Generator._dispatch   s    
 '')%%'??D;/77SAtZ(2D9<ll3,G4g!5t<D|S	r!   c                     UR                  5        H/  u  p#U R                  U R                  R                  X#5      5        M1     U R                  U R                  5        g r#   )	raw_itemsr$   r   foldr.   r   r7   hvs       r   rT   Generator._write_headers   sA    MMODAJJt{{''-. $ 	

488r!   c                    UR                  5       nUc  g [        U[        5      (       d  [        S[	        U5      -  5      e[        UR                  5      (       a8  UR                  S5      nUb$  US	 UR                  X#5        UR                  5       nU R                  (       a  [        R                  SU5      nU R                  U5        g )Nzstring payload expected: %scharsetzcontent-transfer-encoding>From )get_payload
isinstancer   	TypeErrortyper   _payload	get_paramset_payloadr   fcrerf   rQ   )r   r7   payloadrr   s       r   _handle_textGenerator._handle_text   s    //#?'3''9DMIJJ3<<((mmI.G"341//+hhx1G'"r!   c                    / nUR                  5       nUc  / nO?[        U[        5      (       a  U R                  U5        g [        U[        5      (       d  U/nU H^  nU R                  5       nU R                  U5      nUR                  USU R                  S9  UR                  UR                  5       5        M`     UR                  5       nU(       d=  U R                  R                  U5      nU R                  U5      nUR                  U5        UR                   bj  U R"                  (       a!  [$        R'                  SUR                   5      n	OUR                   n	U R)                  U	5        U R                  U R                  5        U R                  SU-   U R                  -   5        U(       a*  U R*                  R                  UR-                  S5      5        U HL  n
U R                  U R                  S-   U-   U R                  -   5        U R*                  R                  U
5        MN     U R                  U R                  S-   U-   S-   5        UR.                  bk  U R                  U R                  5        U R"                  (       a!  [$        R'                  SUR.                  5      nOUR.                  nU R)                  U5        g g )NFr8   r)   rs   z--r   )rt   ru   r   r$   listrD   r-   r<   r.   appendrW   get_boundaryr0   rb   _make_boundaryset_boundarypreambler   r{   rf   rQ   r   popepilogue)r   r7   msgtextssubpartspartr&   gboundaryalltextr   	body_partr   s               r   _handle_multipartGenerator._handle_multipart   s    ??$H#&&JJx Hd++ zHD  "A

1AIIdUDHHI=OOAJJL)	  ##% &&++H5G**73HX&<<#!!88Hcll;<<h'JJtxx 

4(?TXX-.HHNN8<<?+ "IJJtxx$1DHH<=HHNN9%	 " 	

488d?X-45<<#JJtxx !!88Hcll;<<h' $r!   c                     U R                   nUR                  SS9U l          U R                  U5        X l         g ! X l         f = f)Nr   r*   )r   r-   r   )r   r7   ps      r   _handle_multipart_signed"Generator._handle_multipart_signed/  s=     KKggag0	""3'K!Ks	   : Ac                     / nUR                  5        H  nU R                  5       nU R                  U5      nUR                  USU R                  S9  UR                  5       nUR                  U R                  5      nU(       aB  US   U R                  :X  a/  UR                  U R                  R                  US S 5      5        M  UR                  U5        M     U R                  R                  U R                  R                  U5      5        g )NFr   rJ   )rt   rD   r-   r<   r.   rW   splitr0   _encoded_EMPTYr   rb   r   r$   )r   r7   blocksr   r&   r   textrN   s           r   _handle_message_delivery_status)Generator._handle_message_delivery_status:  s     OO%D  "A

1AIIdUDHHI=::<DJJt//0Erd&9&99d..33E#2J?@d# & 	t'',,V45r!   c                 V   U R                  5       nU R                  U5      nUR                  n[        U[        5      (       a;  UR                  UR                  S5      SU R                  S9  UR                  5       nOU R                  U5      nU R                  R                  U5        g )Nr   Fr   )rD   r-   rx   ru   r   r<   rt   r.   rW   r/   r   r$   )r   r7   r&   r   r|   s        r   _handle_messageGenerator._handle_messageO  s}    JJqM ,,gt$$IIcooa(5$((IKjjlGll7+Gwr!   c                 R   [         R                  " [        R                  5      nS[        U-  -   S-   nUc  U$ UnSn U R                  S[        R                  " U5      -   S-   [        R                  5      nUR                  U5      (       d   U$ US-   [        U5      -   nUS-  nMk  )Nz===============z==r   z^--z(--)?$.   )random	randrangesysmaxsize_fmt_compile_rereescape	MULTILINEsearchr   )clsr   tokenr   bcountercres          r   r   Generator._make_boundaryh  s       -.5<O//%"))A,"6"A2<<PC::d##  3W-AqLG r!   c                 .    [         R                  " X5      $ r#   )r   compiler   r&   flagss      r   r   Generator._compile_rez  s    zz!##r!   )r1   r.   r2   r0   r   r   r   r   )TN)FNr#   )__name__
__module____qualname____firstlineno____doc__r   r$   r<   r-   r   rD   r/   rQ   r6   rU   rT   r}   rd   r   r   r   r   classmethodr   r   __static_attributes__rG   r!   r   r	   r	   !   s    :-(^2, N!'6(#" J9(v	6* 2  " $ $r!   r	   c                   \   ^  \ rS rSrSrSrS rS rS rS r	U 4S jr
\
r\S	 5       rS
rU =r$ )r   i~  a  Generates a bytes version of a Message object tree.

Functionally identical to the base Generator except that the output is
bytes and not string.  When surrogates were used in the input to encode
bytes, these are decoded back to bytes for output.  If the policy has
cte_type set to 7bit, then the message is transformed such that the
non-ASCII bytes are properly content transfer encoded, using the charset
unknown-8bit.

The outfp object must accept bytes in its write method.
r!   c                 l    U R                   R                  [        U5      R                  SS5      5        g )Nasciisurrogateescape)r   r$   r   encoder%   s     r   r$   BytesGenerator.write  s"    s1v}}W.?@Ar!   c                     [        5       $ r#   )r   rC   s    r   rD   BytesGenerator._new_buffer  s
    yr!   c                 $    UR                  S5      $ Nr   )r   r%   s     r   r/   BytesGenerator._encode  s    xx  r!   c                     UR                  5        H9  u  p#U R                  R                  U R                  R	                  X#5      5        M;     U R                  U R
                  5        g r#   )rk   r   r$   r   fold_binaryr.   rm   s       r   rT   BytesGenerator._write_headers  sG     MMODAHHNN4;;22189 $ 	

488r!   c                 l  > UR                   c  g [        UR                   5      (       al  U R                  R                  S:X  dR  U R                  (       a%  [
        R                  SUR                   5      Ul         U R                  UR                   5        g [        [        U 5      R                  U5        g )N7bitrs   )rx   r   r   cte_typer   r{   rf   rQ   r   r   r}   )r   r7   r?   s     r   r}   BytesGenerator._handle_text  sx     <<3<<((1E1Ev1M!!#xx#,,?cll+.&33C8r!   c                 N    [         R                  " UR                  S5      U5      $ r   )r   r   r   r   s      r   r   BytesGenerator._compile_re  s    zz!((7+U33r!   rG   )r   r   r   r   r   r   r$   rD   r/   rT   r}   rd   r   r   r   __classcell__)r?   s   @r   r   r   ~  sB    
 NB!
9 J4 4r!   r   zD[Non-text (%(type)s) part of message omitted, filename %(filename)s]c                   (    \ rS rSrSrSS jrS rSrg)r
   i  zGenerates a text representation of a message.

Like the Generator base class, except that non-text parts are substituted
with a format string representing the part.
Nc                 Z    [         R                  XX#5        Uc  [        U l        gX@l        g)a  Like Generator.__init__() except that an additional optional
argument is allowed.

Walks through all subparts of a message.  If the subpart is of main
type `text', then it prints the decoded payload of the subpart.

Otherwise, fmt is a format string that is used instead of the message
payload.  fmt is expanded with the following keywords (in
%(keyword)s format):

type       : Full MIME type of the non-text part
maintype   : Main MIME type of the non-text part
subtype    : Sub-MIME type of the non-text part
filename   : Filename of the non-text part
description: Description associated with the non-text part
encoding   : Content transfer encoding of the non-text part

The default value for fmt is None, meaning

[Non-text (%(type)s) part of message omitted, filename %(filename)s]
N)r	   r   _FMTr   )r   r   r   r   fmts        r   r   DecodedGenerator.__init__  s%    , 	4C;DIIr!   c                    UR                  5        H  nUR                  5       nUS:X  a  [        UR                  SS9U S9  M2  US:X  a  M:  [        U R                  UR                  5       UR                  5       UR                  5       UR                  S5      UR                  SS5      UR                  S	S
5      S.-  U S9  M     g )Nr   F)decode)file	multipartz[no filename]zContent-Descriptionz[no description]zContent-Transfer-Encodingz[no encoding])rw   maintypesubtypefilenamedescriptionencoding)	walkr_   printrt   r   get_content_typer`   get_filenameget)r   r7   r   r   s       r   rU   DecodedGenerator._dispatch  s    HHJD002H6!d&&e&44@[(dii#'#8#8#:#'#<#<#>#'#;#;#=#'#4#4_#E#'88,A,>$@#'88,G,;$=	# 	 !	" r!   )r   )TN   N)r   r   r   r   r   r   rU   r   rG   r!   r   r
   r
     s    
8"r!   r
   r   z%%0%dd)-r   
__future__r   r   r   r   future.builtinsr   r   __all__r   r   r4   r   warningsior   r   "future.backports.email._policybaser   future.backports.email.headerr   future.backports.email.utilsr   future.backports.email.charset	backportsemailrr   _charsetra   NLr   r   r{   objectr	   r   r   r
   rM   reprr   _widthr   r   rG   r!   r   <module>r      s   
 A % '  & ! 
= 	 
      7 0 8 1 1
		zz)R\\*[$ [$z
34Y 34l N4"y 4"p 
T#++a- 	!& ))r!   