Server IP : 209.38.156.173 / Your IP : 216.73.216.122 [ Web Server : Apache/2.4.52 (Ubuntu) System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.1.2-1ubuntu2.22 Disable Function : NONE Domains : 2 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/lib/python3/dist-packages/requests_toolbelt/multipart/__pycache__/ |
Upload File : |
o �B�[� � @ s� d Z ddlZddlZddlmZ ddlmZ dd� ZG dd � d e �Z G d d� de �Zdd � ZG dd� de �ZG dd� de �ZdS )z� requests_toolbelt.multipart.decoder =================================== This holds all the implementation details of the MultipartDecoder � N� ��encode_with)�CaseInsensitiveDictc C s* | � |�}| d |� | |t|� d � fS �N)�find�len)�content�bound�point� r �E/usr/lib/python3/dist-packages/requests_toolbelt/multipart/decoder.py�_split_on_find s r c @ � e Zd ZdS )� ImproperBodyPartContentExceptionN��__name__� __module__�__qualname__r r r r r � r c @ r )� NonMultipartContentTypeExceptionNr r r r r r r r c sB t jd }|dkr| �� �} tj�� �| ��� }� fdd�|D �S )Nr � c 3 s( � | ]\}}t |� �t |� �fV qd S r r )�.0�k�v��encodingr r � <genexpr># s � � �z!_header_parser.<locals>.<genexpr>)�sys�version_info�decode�email�parser�HeaderParser�parsestr�items)�stringr �major�headersr r r �_header_parser s �r) c @ s$ e Zd ZdZdd� Zedd� �ZdS )�BodyParta� 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 C sP || _ i }d|v rt|d�\}| _|dkrt|�� |�}ntd��t|�| _d S )Ns � z$content does not contain CR-LF-CR-LF)r r r r) �lstripr r r( )�selfr r r( �firstr r r �__init__6 s ��zBodyPart.__init__c C s | j �| j�S )z'Content of the ``BodyPart`` in unicode.)r r r )r- r r r �textD s z BodyPart.textN)r r r �__doc__r/ �propertyr0 r r r r r* ) s r* c @ sD e Zd ZdZddd�Zdd� Zedd� �Zd d � Ze ddd��Z d S )�MultipartDecoderai 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.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'``). �utf-8c C s* || _ || _t� | _| �� | �|� d S r )�content_typer �tuple�parts�_find_boundary�_parse_body)r- r r5 r r r r r/ g s zMultipartDecoder.__init__c C s� t dd� | j�d�D ��}|d }|�d�d �� dkr#td�|���|dd � D ]}t|d �\}}|�� d krBt|�d�| j �| _ q)d S )Nc s s � | ]}|� � V qd S r )�strip�r �xr r r r r s � z2MultipartDecoder._find_boundary.<locals>.<genexpr>�;r �/� multipartz*Unexpected mimetype in content-type: '{0}'r �=�boundary�")r6 r5 �split�lowerr �formatr r r: r rA )r- �ct_info�mimetype�item�attr�valuer r r r8 q s ����zMultipartDecoder._find_boundaryc C s( t |�}|| d |� kr| |d � S | S r )r )�part�boundary_marker�bm_lenr r r �_fix_first_part� s z MultipartDecoder._fix_first_partc sX d� d�jf����fdd�� dd� �|�d� d�f��}t� �fdd �|D ���_d S ) Nr+ � --c s t �| � �}t|�j�S r )r3 rN r* r )rK �fixed)rA r- r r � body_part� s z/MultipartDecoder._parse_body.<locals>.body_partc S s( | dko| dko| d d� dko| dkS )Nr+ � � s -- rO r )rK r r r � test_part� s ���z/MultipartDecoder._parse_body.<locals>.test_partrR c 3 s � | ]}�|�r� |�V qd S r r r; )rQ rT r r r � s � z/MultipartDecoder._parse_body.<locals>.<genexpr>)�joinrA rC r6 r7 )r- r r7 r )rQ rA r- rT r r9 � s zMultipartDecoder._parse_bodyc C s |j }|j�dd �}| |||�S )Nzcontent-type)r r( �get)�cls�responser r r5 r r r � from_response� s zMultipartDecoder.from_responseN)r4 )r r r r1 r/ r8 �staticmethodrN r9 �classmethodrY r r r r r3 J s r3 )r1 r �email.parserr! �encoderr �requests.structuresr r � Exceptionr r r) �objectr* r3 r r r r �<module> s !