
    $h                         S r SSKrSSKrSSKJr  SSKJr  S r " S S\	5      r
 " S	 S
\	5      rS r " S S\5      r " S S\5      rg)z

requests_toolbelt.multipart.decoder
===================================

This holds all the implementation details of the MultipartDecoder

    N   encode_with)CaseInsensitiveDictc                 N    U R                  U5      nU S U X[        U5      -   S  4$ N)findlen)contentboundpoints      [/var/www/html/shao/venv/lib/python3.13/site-packages/requests_toolbelt/multipart/decoder.py_split_on_findr      s0    LLE6E?GCJ$6$7888    c                       \ rS rSrSrg) ImproperBodyPartContentException    N__name__
__module____qualname____firstlineno____static_attributes__r   r   r   r   r          r   r   c                       \ rS rSrSrg) NonMultipartContentTypeException   r   Nr   r   r   r   r   r      r   r   r   c                    ^ [         R                  S   nUS:X  a  U R                  T5      n [        R                  R                  5       R                  U 5      R                  5       nU4S jU 5       $ )Nr      c              3   V   >#    U H  u  p[        UT5      [        UT5      4v   M!     g 7fr   r   ).0kvencodings      r   	<genexpr>!_header_parser.<locals>.<genexpr>#   s-      DA 
Q	!;q(#;<s   &))sysversion_infodecodeemailparserHeaderParserparsestritems)stringr%   majorheaderss    `  r   _header_parserr3      s`    QEzx(ll'')226:@@BG r   c                   .    \ rS rSrSrS r\S 5       rSrg)BodyPart)   a  

The ``BodyPart`` object is a ``Response``-like interface to an individual
subpart of a multipart response. It is expected that these will
generally be created by objects of the ``MultipartDecoder`` class.

Like ``Response``, there is a ``CaseInsensitiveDict`` object named headers,
``content`` to access bytes, ``text`` to access unicode, and ``encoding``
to access the unicode codec.

c                     X l         0 nSU;   a4  [        US5      u  o@l        US:w  a  [        UR	                  5       U5      nO[        S5      e[        U5      U l        g )Ns   

r   z$content does not contain CR-LF-CR-LF)r%   r   r   r3   lstripr   r   r2   )selfr   r%   r2   firsts        r   __init__BodyPart.__init__6   s]     '!"0+"FE<|(B26  +73r   c                 L    U R                   R                  U R                  5      $ )z'Content of the ``BodyPart`` in unicode.)r   r*   r%   )r9   s    r   textBodyPart.textD   s     ||""4==11r   )r   r%   r2   N)	r   r   r   r   __doc__r;   propertyr>   r   r   r   r   r5   r5   )   s     
4 2 2r   r5   c                   R    \ rS rSrSrS
S jrS r\S 5       rS r	\
S
S j5       rSrg	)MultipartDecoderJ   a"  

The ``MultipartDecoder`` object parses the multipart payload of
a bytestring into a tuple of ``Response``-like ``BodyPart`` objects.

The basic usage is::

    import requests
    from requests_toolbelt import MultipartDecoder

    response = requests.get(url)
    decoder = MultipartDecoder.from_response(response)
    for part in decoder.parts:
        print(part.headers['content-type'])

If the multipart content is not from a response, basic usage is::

    from requests_toolbelt import MultipartDecoder

    decoder = MultipartDecoder(content, content_type)
    for part in decoder.parts:
        print(part.headers['content-type'])

For both these usages, there is an optional ``encoding`` parameter. This is
a string, which is the name of the unicode codec to use (default is
``'utf-8'``).

c                 |    X l         X0l        [        5       U l        U R	                  5         U R                  U5        g r   )content_typer%   tupleparts_find_boundary_parse_body)r9   r   rF   r%   s       r   r;   MultipartDecoder.__init__g   s0    ( W
!r   c                    [        S U R                  R                  S5       5       5      nUS   nUR                  S5      S   R                  5       S:w  a  [	        SR                  U5      5      eUSS   HQ  n[        US5      u  pEUR                  5       S	:X  d  M'  [        UR                  S
5      U R                  5      U l
        MS     g )Nc              3   >   #    U H  oR                  5       v   M     g 7fr   )strip)r"   xs     r   r&   2MultipartDecoder._find_boundary.<locals>.<genexpr>r   s     H+Ga		+Gs   ;r   /	multipartz)Unexpected mimetype in content-type: '{}'r   =boundary")rG   rF   splitlowerr   formatr   r   rN   r%   rU   )r9   ct_infomimetypeitemattrvalues         r   rI   MultipartDecoder._find_boundaryq   s    H4+<+<+B+B3+GHH1:>>#q!'')[82;BB8L  ABKD(KD zz|z) +EKK,<dmm L  r   c                 4    [        U5      nXS U :X  a  XS  $ U $ r   )r
   )partboundary_markerbm_lens      r   _fix_first_part MultipartDecoder._fix_first_part   s'    _%7Fm+= Kr   c                    ^ ^^^ SR                  ST R                  45      mUU 4S jmS mUR                  SR                  ST45      5      n[        UU4S jU 5       5      T l        g )Nr      --c                 \   > [         R                  U T5      n[        UTR                  5      $ r   )rC   rd   r5   r%   )ra   fixedrU   r9   s     r   	body_part/MultipartDecoder._parse_body.<locals>.body_part   s&    $44T8DEE4==11r   c                 Z    U S:g  =(       a     U S:g  =(       a    U S S S:g  =(       a    U S:g  $ )Nr      
   s   --
rg   r   )ra   s    r   	test_part/MultipartDecoder._parse_body.<locals>.test_part   s;    CK "GO"!H	)" EM#r   rm   c              3   P   >#    U H  nT" U5      (       d  M  T" U5      v   M     g 7fr   r   )r"   rO   rj   ro   s     r   r&   /MultipartDecoder._parse_body.<locals>.<genexpr>   s     GA)A,<9Q<<s   &&)joinrU   rW   rG   rH   )r9   r   rH   rj   rU   ro   s   `  @@@r   rJ   MultipartDecoder._parse_body   sT    88UDMM23	2	# chh':;<GGG
r   c                 d    UR                   nUR                  R                  SS 5      nU " X4U5      $ )Nzcontent-type)r   r2   get)clsresponser%   r   rF   s        r   from_responseMultipartDecoder.from_response   s2    ""''++NDA7(33r   )rU   rF   r%   rH   N)zutf-8)r   r   r   r   r@   r;   rI   staticmethodrd   rJ   classmethodry   r   r   r   r   rC   rC   J   s@    8"M  H  4 4r   rC   )r@   r(   email.parserr+   encoderr   requests.structuresr   r   	Exceptionr   r   r3   objectr5   rC   r   r   r   <module>r      sU        39
	y 		y 	2v 2BR4v R4r   