Plan 9 from Bell Labs’s /usr/web/sources/contrib/stallion/root/sys/lib/python2.7/email/charset.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�`^c@s�ddddgZddlZddlZddlZddlmZddlmZdZd	Z	d
Z
dZdZieedfd
6eedfd6eedfd6eedfd6eedfd6eedfd6eedfd6eedfd6eedfd6eedfd6eedfd6eedfd6dAd6e	e	dfd6e	e	dfd6e	ddfd6e	ddfd6e	ddfd6e	e	dfd6e
e	dfd6de	dfd 6Zid
d!6d
d"6dd#6dd$6dd%6dd&6dd'6dd(6dd)6dd*6dd+6dd,6dd-6dd.6dd/6dd06dd16dd26dd36dd46d5d66dd76d8d96dd:6Zid;d6d<d6dd6Zdddd=�Zd>�Zd?�ZddBd@��YZdS(CtCharsett	add_aliastadd_charsett	add_codeci�N(terrors(tencode_7or8bitiiiisus-asciis
iso-8859-1s
iso-8859-2s
iso-8859-3s
iso-8859-4s
iso-8859-9siso-8859-10siso-8859-13siso-8859-14siso-8859-15siso-8859-16swindows-1252tvisciitbig5tgb2312siso-2022-jpseuc-jpt	shift_jisskoi8-rsutf-8t8bittlatin_1slatin-1tlatin_2slatin-2tlatin_3slatin-3tlatin_4slatin-4tlatin_5slatin-5tlatin_6slatin-6tlatin_7slatin-7tlatin_8slatin-8tlatin_9slatin-9tlatin_10slatin-10sks_c_5601-1987tcp949teuc_jpseuc-krteuc_krtasciiteucgb2312_cntbig5_twcCs2|tkrtd��n|||ft|<dS(s>Add character set properties to the global registry.

    charset is the input character set, and must be the canonical name of a
    character set.

    Optional header_enc and body_enc is either Charset.QP for
    quoted-printable, Charset.BASE64 for base64 encoding, Charset.SHORTEST for
    the shortest of qp or base64 encoding, or None for no encoding.  SHORTEST
    is only valid for header_enc.  It describes how message headers and
    message bodies in the input charset are to be encoded.  Default is no
    encoding.

    Optional output_charset is the character set that the output should be
    in.  Conversions will proceed from input charset, to Unicode, to the
    output charset when the method Charset.convert() is called.  The default
    is to output in the same character set as the input.

    Both input_charset and output_charset must have Unicode codec entries in
    the module's charset-to-codec mapping; use add_codec(charset, codecname)
    to add codecs the module does not know about.  See the codecs module's
    documentation for more information.
    s!SHORTEST not allowed for body_encN(tSHORTESTt
ValueErrortCHARSETS(tcharsett
header_enctbody_enctoutput_charset((s#/sys/lib/python2.7/email/charset.pyRlscCs|t|<dS(s�Add a character set alias.

    alias is the alias name, e.g. latin-1
    canonical is the character set's canonical name, e.g. iso-8859-1
    N(tALIASES(taliast	canonical((s#/sys/lib/python2.7/email/charset.pyR�scCs|t|<dS(s$Add a codec that map characters in the given charset to/from Unicode.

    charset is the canonical name of a character set.  codecname is the name
    of a Python codec, as appropriate for the second argument to the unicode()
    built-in, or to the encode() method of a Unicode string.
    N(t	CODEC_MAP(Rt	codecname((s#/sys/lib/python2.7/email/charset.pyR�scBs�eZdZed�Zd�ZeZd�Zd�Zd�Z	d�Z
d�Zed�Z
d	�Zd
�Zed�Zed�ZRS(
s@	Map character sets to their email properties.

    This class provides information about the requirements imposed on email
    for a specific character set.  It also provides convenience routines for
    converting between character sets, given the availability of the
    applicable codecs.  Given a character set, it will do its best to provide
    information on how to use that character set in an email in an
    RFC-compliant way.

    Certain character sets must be encoded with quoted-printable or base64
    when used in email headers or bodies.  Certain character sets must be
    converted outright, and are not allowed in email.  Instances of this
    module expose the following information about a character set:

    input_charset: The initial character set specified.  Common aliases
                   are converted to their `official' email names (e.g. latin_1
                   is converted to iso-8859-1).  Defaults to 7-bit us-ascii.

    header_encoding: If the character set must be encoded before it can be
                     used in an email header, this attribute will be set to
                     Charset.QP (for quoted-printable), Charset.BASE64 (for
                     base64 encoding), or Charset.SHORTEST for the shortest of
                     QP or BASE64 encoding.  Otherwise, it will be None.

    body_encoding: Same as header_encoding, but describes the encoding for the
                   mail message's body, which indeed may be different than the
                   header encoding.  Charset.SHORTEST is not allowed for
                   body_encoding.

    output_charset: Some character sets must be converted before they can be
                    used in email headers or bodies.  If the input_charset is
                    one of them, this attribute will contain the name of the
                    charset output will be converted to.  Otherwise, it will
                    be None.

    input_codec: The name of the Python codec used to convert the
                 input_charset to Unicode.  If no conversion codec is
                 necessary, this attribute will be None.

    output_codec: The name of the Python codec used to convert Unicode
                  to the output_charset.  If no conversion codec is necessary,
                  this attribute will have the same value as the input_codec.
    cCs^y2t|t�r"|jd�nt|d�}Wn tk
rTtj|��nX|j�jd�}|tkp|tks�yt	j
|�j}Wq�tk
r�q�Xntj
||�|_tj
|jttdf�\}}}|s�j}n||_||_tj
||�|_tj
|j|j�|_tj
|j|j�|_dS(NR(t
isinstancetunicodetencodetUnicodeErrorRtCharsetErrortlowerR"RtcodecstlookuptnametLookupErrortgett
input_charsetRtBASE64tNonetheader_encodingt
body_encodingR!R%tinput_codectoutput_codec(tselfR2thenctbenctconv((s#/sys/lib/python2.7/email/charset.pyt__init__�s0

		cCs
|jj�S(N(R2R,(R9((s#/sys/lib/python2.7/email/charset.pyt__str__�scCst|�t|�j�kS(N(tstrR,(R9tother((s#/sys/lib/python2.7/email/charset.pyt__eq__�scCs|j|�S(N(RA(R9R@((s#/sys/lib/python2.7/email/charset.pyt__ne__�scCsC|jtkst�|jtkr(dS|jtkr;dStSdS(sCReturn the content-transfer-encoding used for body encoding.

        This is either the string `quoted-printable' or `base64' depending on
        the encoding used, or it is a function in which case you should call
        the function with a single argument, the Message object being
        encoded.  The function should then set the Content-Transfer-Encoding
        header itself to whatever is appropriate.

        Returns "quoted-printable" if self.body_encoding is QP.
        Returns "base64" if self.body_encoding is BASE64.
        Returns "7bit" otherwise.
        squoted-printabletbase64N(R6RtAssertionErrortQPR3R(R9((s#/sys/lib/python2.7/email/charset.pytget_body_encoding�s
cCs6|j|jkr.t||j�j|j�S|SdS(s:Convert a string from the input_codec to the output_codec.N(R7R8R(R)(R9ts((s#/sys/lib/python2.7/email/charset.pytconvertscCsRt|t�s|jdkr"|Syt||jd�SWntk
rM|SXdS(s�Convert a possibly multibyte string to a safely splittable format.

        Uses the input_codec to try and convert the string to Unicode, so it
        can be safely split on character boundaries (even for multibyte
        characters).

        Returns the string as-is if it isn't known how to convert it to
        Unicode with the input_charset.

        Characters that could not be converted to Unicode will be replaced
        with the Unicode replacement character U+FFFD.
        treplaceN(R'R(R7R4R0(R9RG((s#/sys/lib/python2.7/email/charset.pyt
to_splittables

cCsh|r|j}n	|j}t|t�s7|dkr;|Sy|j|d�SWntk
rc|SXdS(s*Convert a splittable string back into an encoded string.

        Uses the proper codec to try and convert the string from Unicode back
        into an encoded format.  Return the string as-is if it is not Unicode,
        or if it could not be converted from Unicode.

        Characters that could not be converted from Unicode will be replaced
        with an appropriate character (usually '?').

        If to_output is True (the default), uses output_codec to convert to an
        encoded format.  If to_output is False, uses input_codec.
        RIN(R8R7R'R(R4R)R0(R9tustrt	to_outputtcodec((s#/sys/lib/python2.7/email/charset.pytfrom_splittable+s
	
cCs|jp|jS(s�Return the output character set.

        This is self.output_charset if that is not None, otherwise it is
        self.input_charset.
        (R!R2(R9((s#/sys/lib/python2.7/email/charset.pytget_output_charsetDscCs�|j�}|jtkr9tjj|�t|�tS|jtkrftj	j
|�t|�tS|jtkr�tjj|�}tj	j
|�}t||�t|�tSt|�SdS(s/Return the length of the encoded header string.N(
ROR5R3temailt
base64mimet
base64_lentlentMISC_LENREt
quoprimimetheader_quopri_lenRtmin(R9RGtcsettlenb64tlenqp((s#/sys/lib/python2.7/email/charset.pytencoded_header_lenLscCs�|j�}|r$|j|�}n|jtkrFtjj||�S|jtkrntjj||dd�S|jt
kr�tjj|�}tjj|�}||kr�tjj||�Stjj||dd�Sn|SdS(sEHeader-encode a string, optionally converting it to output_charset.

        If convert is True, the string will be converted from the input
        charset to the output charset automatically.  This is not useful for
        multibyte character sets, which have line length issues (multibyte
        characters must be split on a character, not a byte boundary); use the
        high-level Header class to deal with these issues.  convert defaults
        to False.

        The type of encoding (base64 or quoted-printable) will be based on
        self.header_encoding.
        t
maxlinelenN(
RORHR5R3RPRQt
header_encodeRERUR4RRRRV(R9RGRHRXRYRZ((s#/sys/lib/python2.7/email/charset.pyR][s
cCs^|r|j|�}n|jtkr7tjj|�S|jtkrVtjj|�S|SdS(s�Body-encode a string and convert it to output_charset.

        If convert is True (the default), the string will be converted from
        the input charset to output charset automatically.  Unlike
        header_encode(), there are no issues with byte boundaries and
        multibyte charsets in email bodies, so this is usually pretty safe.

        The type of encoding (base64 or quoted-printable) will be based on
        self.body_encoding.
        N(RHR6R3RPRQtbody_encodeRERU(R9RGRH((s#/sys/lib/python2.7/email/charset.pyR^zs(t__name__t
__module__t__doc__tDEFAULT_CHARSETR=R>t__repr__RARBRFRHRJtTrueRNROR[tFalseR]R^(((s#/sys/lib/python2.7/email/charset.pyR�s+&								(NNN((t__all__R-temail.base64mimeRPtemail.quoprimimeRtemail.encodersRRER3RRTRbR4RR"R%RRRR(((s#/sys/lib/python2.7/email/charset.pyt<module>s�	

			

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].