Mini Shell
a
X�ZgYH � @ s� d Z g d�ZddlZddlZddlZddlZddlZddlZddlZ ddl
mZ ddl
mZ
ddl
mZ ddl
mZmZmZ ddlmZ d Zd
Zd
ZdZdZe�d
�Ze�d�ZdZdadd� Zdd� Zdd� Z dd� Z!dFdd�Z"dd� Z#dd� Z$dZ%dd �d!d"�Z&d#d$� Z'd%d&� Z(d'd(� Z)d)d*� Z*dGd,d-�Z+dHd.d/�Z,dId0d1�Z-d2d3� Z.dd �d4d5�Z/d6d7� Z0d8d9� Z1dJd:d;�Z2e�d<ej3�Z4d=d>� Z5dKdAdB�Z6dLdDdE�Z7dS )MzMiscellaneous utilities.)�collapse_rfc2231_value�
decode_params�decode_rfc2231�encode_rfc2231�
formataddr�
formatdate�format_datetime�getaddresses�
make_msgid� mktime_tz� parseaddr� parsedate�parsedate_tz�parsedate_to_datetime�unquote� N)�quote)�AddressList)r
)r r
�
_parsedate_tz)�Charsetz, � z
�'z[][\\()<>@,:;".]z[\\"]z/etc/python/email.cfgc C s t du rt� a t S )z5"Cache implementation for _cached_strict_addr_parsingN)�_cached_strict_addr_parsing�_use_strict_email_parsing_impl� r r �#/usr/lib64/python3.9/email/utils.py�_use_strict_email_parsing7 s r c C s� t tj�d��} | rdS ztt�}W n ty6 Y nV0 |�@ ddl}|jddd�}|� |� |j
dddd�} W d � n1 s�0 Y | r�dS d S )
z]Returns True if strict email parsing is not disabled by
config file or env variable.
Z(PYTHON_EMAIL_DISABLE_STRICT_ADDR_PARSINGFr N)�#)Z
interpolationZcomment_prefixesZemail_addr_parsing)�fallbackT)�bool�os�environ�get�open�_EMAIL_CONFIG_FILE�FileNotFoundError�configparser�ConfigParserZ read_fileZ
getboolean)�disabled�filer% Zconfigr r r r ? s$ �
.r c C s( z| � � W dS ty" Y dS 0 dS )z8Return True if s contains surrogate-escaped binary data.FTN)�encode�UnicodeEncodeError)�sr r r �_has_surrogates\ s
r, c C s | � dd�}|�dd�S )N�utf-8�surrogateescape�replace)r) �decode)�stringZoriginal_bytesr r r � _sanitizei s r2 r- c C s� | \}}|� d� |r�z|� d� W n: ty^ t|t�rDt|�}|�|�}d||f Y S 0 d}t�|�rrd}t� d|�}d||||f S |S )a� The inverse of parseaddr(), this takes a 2-tuple of the form
(realname, email_address) and returns the string value suitable
for an RFC 2822 From, To or Cc header.
If the first element of pair is false, then the second element is
returned unmodified.
The optional charset is the character set that is used to encode
realname in case realname is not ASCII safe. Can be an instance of str or
a Charset-like object which has a header_encode method. Default is
'utf-8'.
�asciiz%s <%s>r �"z\\\g<0>z%s%s%s <%s>)
r) r* �
isinstance�strr Z
header_encode�
specialsre�search� escapesre�sub)Zpair�charset�name�addressZencoded_nameZquotesr r r r u s
r c c s\ d}d}t | �D ]8\}}|r0|d| fV d}q|dkr>d}q||fV q|rX|dfV d S )Nr F�\T)� enumerate)�addr�pos�escape�chr r r �_iter_escaped_chars� s rD c C s� d| vr| S d}d}g }t | �D ]D\}}|dkr |du r>|}q ||krX|�| ||� � |d }d}q |t| �k r�|�| |d� � d�|�S )z Strip real names between quotes.r4 r N� r )rD �append�len�join)r@ �startZopen_pos�resultrA rC r r r �_strip_quoted_realnames� s rK T)�strictc C s� |dkrt � }|s4t�dd� | D ��}t|�}|jS dd� | D �} t| �} t�| �}t|�}t|j�}d}| D ]}t|�}|d|�d� 7 }qnt |�|kr�d gS |S )
z�Return a list of (REALNAME, EMAIL) or ('','') for each fieldvalue.
When parsing fails for a fieldvalue, a 2-tuple of ('', '') is returned in
its place.
If strict is true, use a strict parser which rejects malformed inputs.
Nc s s | ]}t |�V qd S )N�r6 ��.0�vr r r � <genexpr>� � zgetaddresses.<locals>.<genexpr>c S s g | ]}t |��qS r rM rN r r r �
<listcomp>� rR z getaddresses.<locals>.<listcomp>r rE �,�r r )
r �
COMMASPACErH �_AddressList�addresslist�_pre_parse_validation�_post_parse_validationrK �countrG )ZfieldvaluesrL �all�ar@ rJ �nrP r r r r � s$
r c C sV t | �} d}t| �D ]8\}}|dkr.|d7 }q|dkr|d8 }|dk r dS q|dkS )Nr �(rE �)F)rK rD )r@ ZopensrA rC r r r �_check_parenthesis� s
ra c C s( g }| D ]}t |�sd}|�|� q|S )Nz('', ''))ra rF )Zemail_header_fields�accepted_valuesrP r r r rY s rY c C s, g }| D ]}d|d v rd}|� |� q|S )N�[rE rU )rF )Zparsed_email_header_tuplesrb rP r r r rZ
s rZ c C sH dg d�| d | d g d�| d d | d | d | d | d
|f S )Nz"%s, %02d %s %04d %02d:%02d:%02d %s)ZMonZTueZWedZThuZFriZSatZSun� � )ZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecrE r � � � r )� timetuple�zoner r r �_format_timetuple_and_zone s
��rk Fc C sR | du rt � � } |s|r,tj�| tjj�}ntj�| �}|rH|�� }d}t||�S )a� Returns a date string as specified by RFC 2822, e.g.:
Fri, 09 Nov 2001 01:08:47 -0000
Optional timeval if given is a floating point time value as accepted by
gmtime() and localtime(), otherwise the current time is used.
Optional localtime is a flag that when True, interprets timeval, and
returns a date relative to the local timezone instead of UTC, properly
taking daylight savings time into account.
Optional argument usegmt means that the timezone is written out as
an ascii string, not numeric one (so "GMT" instead of "+0000"). This
is needed for HTTP, and is only used when localtime==False.
NF)�time�datetimeZ
fromtimestamp�timezone�utcZutcfromtimestamp�
astimezoner )�timeval� localtime�usegmt�dtr r r r s r c C sV | � � }|r2| jdu s$| jtjjkr,td��d}n| jdu rBd}n
| �d�}t||�S )a$ Turn a datetime into a date string as specified in RFC 2822.
If usegmt is True, dt must be an aware datetime with an offset of zero. In
this case 'GMT' will be rendered instead of the normal +0000 required by
RFC2822. This is to support HTTP headers involving date stamps.
Nz%usegmt option requires a UTC datetimeZGMTz-0000z%z)ri �tzinform rn ro �
ValueError�strftimerk )rt rs �nowrj r r r r < s
r c C s^ t t�� d �}t�� }t�d�}| du r0d} nd| } |du rHt�� }d|||| |f }|S )a{ Returns a string suitable for RFC 2822 compliant Message-ID, e.g:
<142480216486.20800.16526388040877946887@nightshade.la.mastaler.com>
Optional idstring if given is a string used to strengthen the
uniqueness of the message id. Optional domain if given provides the
portion of the message id after the '@'. It defaults to the locally
defined hostname.
�d �@ Nr �.z<%d.%d.%d%s@%s>)�intrl r �getpid�random�getrandbits�socket�getfqdn)Zidstring�domainrq �pid�randintZmsgidr r r r O s
r c C sN t | ��^ }}|d u r(tj|d d� � S tj|d d� dt�tj|d��i�S )Nrd ru ��seconds)r rm rn � timedelta)�dataZdtuple�tzr r r r f s �r c C s� |dkrt � }|s,t| �j}|s$dS |d S t| t�r>| d } t| t�sLdS t| g�d } tt| �j�}|rxt|�dkr|dS |d S )a
Parse addr into its constituent realname and email address parts.
Return a tuple of realname and email address, unless the parse fails, in
which case return a 2-tuple of ('', '').
If strict is True, use a strict parser which rejects malformed inputs.
NrU r rE ) r rW rX r5 �listr6 rY rZ rG )r@ rL �addrsr r r r n s
r c C s` t | �dkr\| �d�r<| �d�r<| dd� �dd��dd�S | �d�r\| �d�r\| dd� S | S ) zRemove quotes from a string.rE r4 ���z\\r>