Spade

Mini Shell

Directory:~$ /lib/python2.7/site-packages/future/backports/email/
Upload File

[Home] [System Details] [Kill Me]
Current File:~$ //lib/python2.7/site-packages/future/backports/email/_encoded_words.pyc

�
,�]c@`s�dZddlmZddlmZddlmZddlmZddlmZddlmZddlm	Z	dd	l
Z
dd	lZdd	lZdd	l
Z
dd
lmZmZddlmZdd
ddddddgZe
je
jd�jd��Zd�Zdefd��YZe�Zdeed�<d�Zd�Zd�Zd�Z
d�Z!ied 6ed!6Z"d"�Z#ied 6e d!6Z$ied
6e!d!6Z%d#d	d$d%�Z'd	S(&u� Routines for manipulating RFC2047
encoded words.

This is currently a package-private API, but will be considered for
promotion
to a public API if there is demand.

i(tunicode_literals(tdivision(tabsolute_import(tbytes(tchr(tint(tstrN(t
ascii_letterstdigits(terrorsudecode_quencode_qudecode_buencode_bulen_qulen_budecodeuencodes=([a-fA-F0-9]{2})cC`stt|jd�d�g�S(Nii(RRtgroup(tm((sI/usr/lib/python2.7/site-packages/future/backports/email/_encoded_words.pyt<lambda>HscC`s(t|jdd��}t|�gfS(Nt_t
(Rtreplacet_q_byte_subber(tencoded((sI/usr/lib/python2.7/site-packages/future/backports/email/_encoded_words.pytdecode_qJst	_QByteMapcB`s7eZedejd�ejd��Zd�ZRS(s-!*+/uasciicC`s=||jkr"t|�||<ndj|�||<||S(Nu={:02X}(tsafeRtformat(tselftkey((sI/usr/lib/python2.7/site-packages/future/backports/email/_encoded_words.pyt__missing__Ts(t__name__t
__module__RRtencodeRRR(((sI/usr/lib/python2.7/site-packages/future/backports/email/_encoded_words.pyRPs&u_u
cC`s#tdjd�t|�D���S(Nucs`s|]}t|VqdS(N(t_q_byte_map(t.0tx((sI/usr/lib/python2.7/site-packages/future/backports/email/_encoded_words.pys	<genexpr>as(RtjoinR(tbstring((sI/usr/lib/python2.7/site-packages/future/backports/email/_encoded_words.pytencode_q`scC`std�t|�D��S(Ncs`s|]}tt|�VqdS(N(tlenR(RR((sI/usr/lib/python2.7/site-packages/future/backports/email/_encoded_words.pys	<genexpr>ds(tsumR(R
((sI/usr/lib/python2.7/site-packages/future/backports/email/_encoded_words.pytlen_qcscC`s*g}t|�d}|rD|jtj��|dd|
}n|}y;tjd|�sqtjd��ntj	|�|fSWn�tjk
r%tj
�g}x|dD]d}ytj	|d	|�|fSWq�tjtfk
r|dkr|jtj��qq�Xq�Wtd
��nXdS(Nis===s^[A-Za-z0-9+/]*={0,2}$uNon-base64 digit
foundiiiit=uunexpected
binascii.Error(iiii(
R"tappendR	tInvalidBase64PaddingDefecttretmatchtbinasciitErrortbase64t	b64decodetInvalidBase64CharactersDefectt	TypeErrortAssertionError(Rtdefectstpad_errtpadded_encodedti((sI/usr/lib/python2.7/site-packages/future/backports/email/_encoded_words.pytdecode_bks&
cC`stj|�jd�S(Nuascii(R,t	b64encodetdecode(R
((sI/usr/lib/python2.7/site-packages/future/backports/email/_encoded_words.pytencode_b�scC`s3tt|�d�\}}|d|r.dndS(Niii(tdivmodR"(R
tgroups_of_3tleftover((sI/usr/lib/python2.7/site-packages/future/backports/email/_encoded_words.pytlen_b�suqubc	C`s.t|�jd�\}}}}}|jd�\}}}|j�}|jdd�}t||�\}}y|j|�}Wn�tk
r�|jt	j
dj|���|j|d�}nWtk
r|jdd�}|j�dkr|jt	j
dj|���qnX||||fS(u�Decode
encoded word and return (string, charset, lang, defects) tuple.

    An RFC 2047/2243 encoded word has the form:

        =?charset*lang?cte?encoded_string?=

    where '*lang' may be omitted but the other parts may not be.

    This function expects exactly such a string (that is, it does not check
the
    syntax and may raise errors if the string is not well formed), and
returns
    the encoded_string decoded first from its Content Transfer Encoding and
    then from the resulting bytes into unicode using the specified charset.
 If
    the cte-decoded string does not successfully decode using the specified
    character set, a defect is added to the defects list and the unknown
octets
    are replaced by the unicode 'unknown' character ﷿.

    The specified charset and language are returned.  The default for
language,
    which is rarely if ever encountered, is the empty string.

    u?u*uasciiusurrogateescapeu:Encoded word contains bytes not
decodable using {} charsetuunknown-8bitu<Unknown charset {} in encoded
word; decoded as unknown
bytes(Rtsplitt	partitiontlowerRt
_cte_decodersR7tUnicodeErrorR&R	tUndecodableBytesDefectRtLookupErrortCharsetError(	tewR
tcharsettctet
cte_stringtlangR
R1tstring((sI/usr/lib/python2.7/site-packages/future/backports/email/_encoded_words.pyR7�s"$


uutf-8ucC`s�t|�}|dkr-|jdd�}n|j|�}|d	kr�td|�}td|�}||dkr~dnd}nt||�}|r�d|}ndj||||�S(
uEncode string using the CTE encoding that produces the shorter result.

    Produces an RFC 2047/2243 encoded word of the form:

        =?charset*lang?cte?encoded_string?=

    where '*lang' is omitted unless the 'lang'
parameter is given a value.
    Optional argument charset (defaults to utf-8) specifies the charset to
use
    to encode the string to binary before CTE encoding it.  Optional
argument
    'encoding' is the cte specifier for the encoding that should
be used ('q'
    or 'b'); if it is None (the default) the encoding which
produces the
    shortest encoded sequence is used, except that 'q' is
preferred if it is up
    to five characters longer.  Optional argument 'lang' (default
'') gives the
    RFC 2243 language string to specify in the encoded word.

   
uunknown-8bituasciiusurrogateescapeuqubiu*u=?{0}{1}?{2}?{3}?=N(RRtNonet_cte_encode_lengtht
_cte_encodersR(RJRFtencodingRIR
tqlentblenR((sI/usr/lib/python2.7/site-packages/future/backports/email/_encoded_words.pyR�s
((t__doc__t
__future__RRRtfuture.builtinsRRRRR(R,R*t	functoolsRJRRtfuture.backports.emailR	t__all__tpartialtcompiletsubRRtdictRRtordR!R$R5R8R<R@R7RMRLRKR(((sI/usr/lib/python2.7/site-packages/future/backports/email/_encoded_words.pyt<module>sV$								
	*