File: //lib/python3.10/email/__pycache__/header.cpython-310.pyc
o
    E�h&^  �                   @   s�   d Z g d�ZddlZddlZddlZddlZddlmZ ddlm	Z
 e
jZdZdZ
dZd	Zd
ZdZdZed
�Zed�Ze�dejejB �Ze�d�Ze�d�ZejjZdd� Z		ddd�ZG dd� d�ZG dd� d�Z G dd� de!�Z"dS )z+Header encoding and decoding functionality.)�Header�
decode_header�make_header�    N)�HeaderParseError)�charset�
� �    z        � �N   z 	�us-asciizutf-8ai  
  =\?                   # literal =?
  (?P<charset>[^?]*?)   # non-greedy up to the next ? is the charset
  \?                    # literal ?
  (?P<encoding>[qQbB])  # either a "q" or a "b", case insensitive
  \?                    # literal ?
  (?P<encoded>.*?)      # non-greedy up to the next ?= is the encoded string
  \?=                   # literal ?=
  z[\041-\176]+:$z
\n[^ \t]+:c              	   C   s�  t | d�r
dd� | jD �S t�| �s| dfgS g }| �� D ]A}t�|�}d}|r^|�d�}|r5|�� }d}|r?|�|ddf� |r\|�d��	� }|�d��	� }|�d�}|�|||f� |s(qg }	t
|�D ]%\}
}|
dkr�|d r�||
d	  d r�||
d  d �� r�|	�|
d � qet|	�D ]}||= q�g }
|D ][\}}}|du r�|
�||f� q�|d
kr�t
j�|�}|
�||f� q�|dkr�t|�d }|r�|d
dd| � 7 }zt
j�|�}W n tjy�   td��w |
�||f� q�td| ��g }d }}|
D ]:\}}t|t��rt|d�}|du �r|}|}q�||k�r'|�||f� |}|}q�|du �r3|t| 7 }q�||7 }q�|�||f� |S )a;  Decode a message header value without converting charset.
    Returns a list of (string, charset) pairs containing each of the decoded
    parts of the header.  Charset is None for non-encoded parts of the header,
    otherwise a lower-case string containing the name of the character set
    specified in the encoded string.
    header may be a string that may or may not contain RFC2047 encoded words,
    or it may be a Header object.
    An email.errors.HeaderParseError may be raised when certain decoding error
    occurs (e.g. a base64 decoding exception).
    �_chunksc                 S   s(   g | ]\}}t �|t|��t|�f�qS � )�_charset�_encode�str)�.0�stringr   r   r   �#/usr/lib/python3.10/email/header.py�
<listcomp>M   s    �z!decode_header.<locals>.<listcomp>NTr   F�   �   �q�b�   z===zBase64 decoding errorzUnexpected encoding: zraw-unicode-escape)�hasattrr
   �ecre�search�
splitlines�split�pop�lstrip�append�lower�	enumerate�isspace�reversed�email�
quoprimime�
header_decode�len�
base64mime�decode�binascii�Errorr   �AssertionError�
isinstancer   �bytes�BSPACE)�header�words�line�parts�first�	unencodedr   �encoding�encoded�droplist�n�w�d�
decoded_words�encoded_string�word�paderr�	collapsed�	last_word�last_charsetr   r   r   r   =   s�   
�
��4��
r   c                 C   sF   t |||d�}| D ]\}}|durt|t�st|�}|�||� q	|S )a�  Create a Header from a sequence of pairs as returned by decode_header()
    decode_header() takes a header value string and returns a sequence of
    pairs of the format (decoded_string, charset) where charset is the string
    name of the character set.
    This function takes one of those sequence of pairs and returns a Header
    instance.  Optional maxlinelen, header_name, and continuation_ws are as in
    the Header constructor.
    )�
maxlinelen�header_name�continuation_wsN)r   r0   �Charsetr"