Spade
Mini Shell
| Directory:~$ /lib/python2.7/site-packages/requests_toolbelt/multipart/ |
| [Home] [System Details] [Kill Me] |
�
ӵ Yc@s�dZddlZddlZddlmZddlmZd�Zde fd��YZ
d e fd
��YZd�Zde
fd
��YZde
fd��YZdS(s�
requests_toolbelt.multipart.decoder
===================================
This holds all the implementation details of the MultipartDecoder
i����Ni(tencode_with(tCaseInsensitiveDictcCs+|j|�}||
||t|�fS(N(tfindtlen(tcontenttboundtpoint((sG/usr/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyt_split_on_findst
ImproperBodyPartContentExceptioncBseZRS((t__name__t
__module__(((sG/usr/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyRst
NonMultipartContentTypeExceptioncBseZRS((R R
(((sG/usr/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyRscs]tjd}|dkr+|j��}ntjj�j|�j�}�fd�|D�S(Niic3s3|])\}}t|��t|��fVqdS(N(R(t.0tktv(tencoding(sG/usr/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pys <genexpr>$s(tsystversion_infotdecodetemailtparsertHeaderParsertparsestrtitems(tstringRtmajortheaders((RsG/usr/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyt_header_parsers
tBodyPartcBs&eZdZd�Zed��ZRS(s�
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
header,
``content`` to access bytes, ``text`` to access unicode, and
``encoding``
to access the unicode codec.
cCsy||_i}d|krZt|d�\}|_|dkrft|j�|�}qfntd��t|�|_dS(Ns
ts$content does not contain
CR-LF-CR-LF(RRRRtlstripRRR(tselfRRRtfirst((sG/usr/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyt__init__6s cCs|jj|j�S(s'Content
of the ``BodyPart`` in
unicode.(RRR(R((sG/usr/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyttextDs(R R
t__doc__R!tpropertyR"(((sG/usr/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyR)s tMultipartDecodercBsMeZdZdd�Zd�Zed��Zd�Zedd��Z RS(sg
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 = request.get(url)
decoder = MultipartDecoder.from_response(response)
for part in decoder.parts:
print(part.header['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.header['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'``).
sutf-8cCs?||_||_||_t�|_|j�|j�dS(N(Rtcontent_typeRttupletpartst_find_boundaryt_parse_body(RRR&R((sG/usr/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyR!gs
cCs�td�|jjd�D��}|d}|jd�ddkr]tdj|���nxZ|dD]N}t|d�\}}|j�d krht|jd
�|j �|_
qhqhWdS(Ncss|]}|j�VqdS(N(tstrip(Rtx((sG/usr/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pys <genexpr>tst;it/t multiparts*Unexpected
mimetype in content-type:
'{0}'it=tboundaryt"(R'R&tsplitRtformatRtlowerRR+RR1(Rtct_infotmimetypetitemtattrtvalue((sG/usr/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyR)ss"
cCs,t|�}|||
kr$||S|SdS(N(R(tparttboundary_markertbm_len((sG/usr/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyt_fix_first_part�scszdjd�jf����fd��d���jjdjd�f��}t��fd�|D���_dS(NRs--cs"tj|��}t|�j�S(N(R%R>RR(R;tfixed(R1R(sG/usr/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyt body_part�scSs2|dko1|dko1|d
dko1|dkS(NRs
is--
s--((R;((sG/usr/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyt test_part�ss
c3s'|]}�|�r�|�VqdS(N((RR,(R@RA(sG/usr/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pys <genexpr>�s(tjoinR1RR3R'R((RR(((R@R1RRAsG/usr/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyR*�s
!cCs.|j}|jjdd�}||||�S(Nscontent-type(RRtgettNone(tclstresponseRRR&((sG/usr/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyt
from_response�s (
R R
R#R!R)tstaticmethodR>R*tclassmethodRG(((sG/usr/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyR%Js (R#Rtemail.parserRtencoderRtrequests.structuresRRt ExceptionRRRtobjectRR%(((sG/usr/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyt<module> s !