Spade

Mini Shell

Directory:~$ /lib/python2.7/site-packages/kitchen/text/
Upload File

[Home] [System Details] [Kill Me]
Current File:~$ //lib/python2.7/site-packages/kitchen/text/converters.pyo

�
i�:Oc@s�dZyddlmZmZWn'ek
rIddlmZmZnXddlZddlZddlZ	ddl
Zddlm
Z
e
j�ddlmZmZddlmZmZmZedF�ZedG�Zdd
ddd!�Zdd ddd"�Zd#�Zd
d$d%�Zd&�Zd'�d(�fZd)�efZ
ed*�Z!ed+�Z"de#d d,�Z$dd d-�Z%dd de#d
d.�Z&dd dd/�Z'd0�Z(d1�Z)de#d
d2�Z*de#d3d4�Z+dHZ,dS(Is!
Functions to handle conversion of byte :class:`str` and :class:`unicode`
strings.

.. versionchanged:: kitchen 0.2a2 ; API kitchen.text 2.0.0
    Added :func:`~kitchen.text.converters.getwriter`

.. versionchanged:: kitchen 0.2.2  ; API kitchen.text 2.1.0
    Added :func:`~kitchen.text.converters.exception_to_unicode`,
    :func:`~kitchen.text.converters.exception_to_bytes`,
    :data:`~kitchen.text.converters.EXCEPTION_CONVERTERS`,
    and :data:`~kitchen.text.converters.BYTE_EXCEPTION_CONVERTERS`

.. versionchanged:: kitchen 1.0.1 ; API kitchen.text 2.1.1
    Deprecated :data:`~kitchen.text.converters.BYTE_EXCEPTION_CONVERTERS`
as
    we've simplified
:func:`~kitchen.text.converters.exception_to_unicode` and
    :func:`~kitchen.text.converters.exception_to_bytes` to make it
unnecessary

i����(t	b64encodet	b64decodeN(tsets(tControlCharErrortXmlEncodeError(tguess_encodingthtml_entities_unescapetprocess_control_charssutf-8sUTF-8tutf8tUTF8tutf_8tUTF_8tutftUTFtu8tU8slatin-1sLATIN-1tlatin1tLATIN1tlatintLATINtl1tL1tcp819tCP819t8859s	iso8859-1s	ISO8859-1s
iso-8859-1s
ISO-8859-1treplacecCs+t|t�rjt|t�r"|S|tkr>t|d|�S|tkrZt|d|�S|j||�S|r�tjtj	d�t
dd�|s�|}q�n|s�d}n|dkr�dS|d	kr�|S|dkr�y|j�}Wntt
fk
rd}nX|siyt|�}Wqit
k
rey|j�}Wqft
tfk
rad}qfXqiXnt|t�s�t|||�S|S|dkrt|�}t|t�s�t|||�}n|d
kr�|Sttj	d�i|j|d
�d6��nttj	d�i|d6��dS(s}Convert
an object into a :class:`unicode` string

    :arg obj: Object to convert to a :class:`unicode` string.  This should
        normally be a byte :class:`str`
    :kwarg encoding: What encoding to try converting the byte :class:`str`
as.
        Defaults to :term:`utf-8`
    :kwarg errors: If errors are found while decoding, perform this action.
        Defaults to ``replace`` which replaces the invalid bytes with
        a character that means the bytes were unable to be decoded.  Other
        values are the same as the error handling schemes in the `codec
base
        classes
       
<http://docs.python.org/library/codecs.html#codec-base-classes>`_.
        For instance ``strict`` which raises an exception and ``ignore``
which
        simply omits the non-decodable characters.
    :kwarg nonstring: How to treat nonstring values.  Possible values are:

        :simplerepr: Attempt to call the object's "simple
representation"
            method and return that value.  Python-2.3+ has two methods that
            try to return a simple representation:
:meth:`object.__unicode__`
            and :meth:`object.__str__`.  We first try to get a usable value
            from :meth:`object.__unicode__`.  If that fails we try the same
            with :meth:`object.__str__`.
        :empty: Return an empty :class:`unicode` string
        :strict: Raise a :exc:`TypeError`
        :passthru: Return the object unchanged
        :repr: Attempt to return a :class:`unicode` string of the repr of
the
            object

        Default is ``simplerepr``

    :kwarg non_string: *Deprecated* Use :attr:`nonstring` instead
    :raises TypeError: if :attr:`nonstring` is ``strict`` and
        a non-:class:`basestring` object is passed in or if
:attr:`nonstring`
        is set to an unknown value
    :raises UnicodeDecodeError: if :attr:`errors` is ``strict`` and
        :attr:`obj` is not decodable using the given encoding
    :returns: :class:`unicode` string or the original object depending on
the
        value of :attr:`nonstring`.

    Usually this should be used on a byte :class:`str` but it can take both
    byte :class:`str` and :class:`unicode` strings intelligently. 
Nonstring
    objects are handled in different ways depending on the setting of the
    :attr:`nonstring` parameter.

    The default values of this function are set so as to always return
    a :class:`unicode` string and never raise an error when converting from
    a byte :class:`str` to a :class:`unicode` string.  However, when you do
    not pass validly encoded text (or a nonstring object), you may end up
with
    output that you don't expect.  Be sure you understand the
requirements of
    your data, not just ignore errors by passing it through this function.

    .. versionchanged:: 0.2.1a2
        Deprecated :attr:`non_string` in favor of :attr:`nonstring`
parameter and changed
        default value to ``simplerepr``
    sutf-8slatin-1sLnon_string is a deprecated parameter of to_unicode().
 Use nonstring insteadt
stacklevelit
simplereprtemptyutpassthrutreprtstrictsWto_unicode was given
"%(obj)s" which is neither a byte string (str) or a unicode
stringRtobjs8nonstring value, %(param)s, is not set to a valid
actiontparamN(sreprsstrict(t
isinstancet
basestringtunicodet
_UTF8_ALIASESt_LATIN1_ALIASEStdecodetwarningstwarntktb_tDeprecationWarningt__unicode__tAttributeErrortUnicodeErrortNonetstrt__str__Rt	TypeErrortencode(R
tencodingterrorst	nonstringt
non_stringtsimpletobj_repr((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pyt
to_unicodeIs\9	


cCst|t�r2t|t�r"|S|j||�S|ritjtjd�tdd�|si|}qin|sxd}n|dkr�dS|dkr�|S|dkrYyt|�}WnAt	k
r�y|j
�}Wq�tt	fk
r�d}q�XnX|s1y|j
�}Wq1tt	fk
r-d}q1Xnt|t�rU|j|d�}n|S|dkr�y|j�}Wntt	fk
r�d}nXt|t�r�|j||�}nt|�}|d	kr�|Sttjd�i|d6��nttjd
�i|d6��dS(s�
Convert
an object into a byte :class:`str`

    :arg obj: Object to convert to a byte :class:`str`.  This should
normally
        be a :class:`unicode` string.
    :kwarg encoding: Encoding to use to convert the :class:`unicode` string
        into a byte :class:`str`.  Defaults to :term:`utf-8`.
    :kwarg errors: If errors are found while encoding, perform this action.
        Defaults to ``replace`` which replaces the invalid bytes with
        a character that means the bytes were unable to be encoded.  Other
        values are the same as the error handling schemes in the `codec
base
        classes
       
<http://docs.python.org/library/codecs.html#codec-base-classes>`_.
        For instance ``strict`` which raises an exception and ``ignore``
which
        simply omits the non-encodable characters.
    :kwarg nonstring: How to treat nonstring values.  Possible values are:

        :simplerepr: Attempt to call the object's "simple
representation"
            method and return that value.  Python-2.3+ has two methods that
            try to return a simple representation:
:meth:`object.__unicode__`
            and :meth:`object.__str__`.  We first try to get a usable value
            from :meth:`object.__str__`.  If that fails we try the same
            with :meth:`object.__unicode__`.
        :empty: Return an empty byte :class:`str`
        :strict: Raise a :exc:`TypeError`
        :passthru: Return the object unchanged
        :repr: Attempt to return a byte :class:`str` of the :func:`repr` of
the
            object

        Default is ``simplerepr``.

    :kwarg non_string: *Deprecated* Use :attr:`nonstring` instead.
    :raises TypeError: if :attr:`nonstring` is ``strict`` and
        a non-:class:`basestring` object is passed in or if
:attr:`nonstring`
        is set to an unknown value.
    :raises UnicodeEncodeError: if :attr:`errors` is ``strict`` and all of
the
        bytes of :attr:`obj` are unable to be encoded using
:attr:`encoding`.
    :returns: byte :class:`str` or the original object depending on the
value
        of :attr:`nonstring`.

    .. warning::

        If you pass a byte :class:`str` into this function the byte
        :class:`str` is returned unmodified.  It is **not** re-encoded with
        the specified :attr:`encoding`.  The easiest way to achieve that
is::

            to_bytes(to_unicode(text), encoding='utf-8')

        The initial :func:`to_unicode` call will ensure text is
        a :class:`unicode` string.  Then, :func:`to_bytes` will turn that
into
        a byte :class:`str` with the specified encoding.

    Usually, this should be used on a :class:`unicode` string but it can
take
    either a byte :class:`str` or a :class:`unicode` string intelligently.
    Nonstring objects are handled in different ways depending on the
setting
    of the :attr:`nonstring` parameter.

    The default values of this function are set so as to always return a
byte
    :class:`str` and never raise an error when converting from unicode to
    bytes.  However, when you do not pass an encoding that can validly
encode
    the object (or a non-string object), you may end up with output that
you
    don't expect.  Be sure you understand the requirements of your
data, not
    just ignore errors by passing it through this function.

    .. versionchanged:: 0.2.1a2
        Deprecated :attr:`non_string` in favor of :attr:`nonstring`
parameter
        and changed default value to ``simplerepr``
    sJnon_string is a deprecated parameter of to_bytes().  Use nonstring
insteadRiRRtRRRRsUto_bytes was given "%(obj)s" which is
neither a unicode string or a byte string (str)R s8nonstring value,
%(param)s, is not set to a valid
actionR!N(sreprsstrict(R"R#R1R4R(R)R*R+R,R/R2R.R0R-R$t__repr__R3(R
R5R6R7R8R9R:((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pytto_bytes�s\E	


cCs&dtjfd��Y}||_|S(s�Return a
:class:`codecs.StreamWriter` that resists tracing back.

    :arg encoding: Encoding to use for transforming :class:`unicode`
strings
        into byte :class:`str`.
    :rtype: :class:`codecs.StreamWriter`
    :returns: :class:`~codecs.StreamWriter` that you can instantiate to
wrap output
        streams to automatically translate :class:`unicode` strings into
:attr:`encoding`.

    This is a reimplemetation of :func:`codecs.getwriter` that returns
    a :class:`~codecs.StreamWriter` that resists issuing tracebacks.  The
    :class:`~codecs.StreamWriter` that is returned uses
    :func:`kitchen.text.converters.to_bytes` to convert :class:`unicode`
    strings into byte :class:`str`.  The departures from
    :func:`codecs.getwriter` are:

    1) The :class:`~codecs.StreamWriter` that is returned will take byte
       :class:`str` as well as :class:`unicode` strings.  Any byte
       :class:`str` will be passed through unmodified.
    2) The default error handler for unknown bytes is to ``replace`` the
bytes
       with the unknown character (``?`` in most ascii-based encodings,
``�``
       in the utf encodings) whereas :func:`codecs.getwriter` defaults to
       ``strict``.  Like :class:`codecs.StreamWriter`, the returned
       :class:`~codecs.StreamWriter` can have its error handler changed in
       code by setting ``stream.errors = 'new_handler_name'``

    Example usage::

        $ LC_ALL=C python
        >>> import sys
        >>> from kitchen.text.converters import getwriter
        >>> UTF8Writer = getwriter('utf-8')
        >>> unwrapped_stdout = sys.stdout
        >>> sys.stdout = UTF8Writer(unwrapped_stdout)
        >>> print 'caf\xc3\xa9'
        café
        >>> print u'caf\xe9'
        café
        >>> ASCIIWriter = getwriter('ascii')
        >>> sys.stdout = ASCIIWriter(unwrapped_stdout)
        >>> print 'caf\xc3\xa9'
        café
        >>> print u'caf\xe9'
        caf?

    .. seealso::

        API docs for :class:`codecs.StreamWriter` and
:func:`codecs.getwriter`
        and `Print Fails <http://wiki.python.org/moin/PrintFails>`_
on the
        python wiki.

    .. versionadded:: kitchen 0.2a2, API: kitchen.text 1.1.0
    t
_StreamWritercBs
eZdd�Zdd�ZRS(RcSstjj|||�dS(N(tcodecstStreamWritert__init__(tselftstreamR6((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pyRBhscSs%t|d|jd|�t|�fS(NR5R6(R>R5tlen(RCtmsgR6((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pyR4ks(t__name__t
__module__RBR4(((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pyR?as(R@RAR5(R5R?((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pyt	getwriter,s5	RcCs;tjtjd�tdd�t|ddd|d|�S(s�*Deprecated*

    Convert :class:`unicode` to an encoded :term:`utf-8` byte :class:`str`.
    You should be using :func:`to_bytes` instead::

        to_bytes(obj, encoding='utf-8',
non_string='passthru')
    s�kitchen.text.converters.to_utf8 is deprecated.  Use
kitchen.text.converters.to_bytes(obj, encoding="utf-8",
nonstring="passthru"
instead.RiR5sutf-8R6R7(R(R)R*R+R,R>(R
R6R8((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pytto_utf8rs
cCs/tjtjd�tdd�t|dd�S(s*Deprecated*

    This function converts something to a byte :class:`str` if it
isn't one.
    It's used to call :func:`str` or :func:`unicode` on the object to
get its
    simple representation without danger of getting a :exc:`UnicodeError`.
    You should be using :func:`to_unicode` or :func:`to_bytes` explicitly
    instead.

    If you need :class:`unicode` strings::

        to_unicode(obj, nonstring='simplerepr')

    If you need byte :class:`str`::

        to_bytes(obj, nonstring='simplerepr')
    smto_str is deprecated.  Use to_unicode or to_bytes instead.  See the
to_str docstring for porting information.RiR7R(R(R)R*R+R,R>(R
((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pytto_str�s
cCs|jdS(Ni(targs(te((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pyt<lambda>�scCs|S(N((RM((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pyRN�scCst|jd�S(Ni(R>RL(RM((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pyRN�scCs<d}x)|D]!}y||�}Wnq
XPq
Wt|�S(s�Convert
an exception object into a unicode representation

    :arg exc: Exception object to convert
    :kwarg converters: List of functions to use to convert the exception
into
        a string.  See :data:`EXCEPTION_CONVERTERS` for the default value
and
        an example of adding other converters to the defaults.  The
functions
        in the list are tried one at a time to see if they can extract
        a string from the exception.  The first one to do so without
raising
        an exception is used.
    :returns: :class:`unicode` string representation of the exception.  The
        value extracted by the :attr:`converters` will be converted into
        :class:`unicode` before being returned using the :term:`utf-8`
        encoding.  If you know you need to use an alternate encoding add
        a function that does that to the list of functions in
        :attr:`converters`)

    .. versionadded:: 0.2.2
    u%<exception failed to convert to text>(R;(texct
convertersRFtfunc((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pytexception_to_unicode�s
cCs<d}x)|D]!}y||�}Wnq
XPq
Wt|�S(s;Convert
an exception object into a str representation

    :arg exc: Exception object to convert
    :kwarg converters: List of functions to use to convert the exception
into
        a string.  See :data:`EXCEPTION_CONVERTERS` for the default value
and
        an example of adding other converters to the defaults.  The
functions
        in the list are tried one at a time to see if they can extract
        a string from the exception.  The first one to do so without
raising
        an exception is used.
    :returns: byte :class:`str` representation of the exception.  The value
        extracted by the :attr:`converters` will be converted into
        :class:`str` before being returned using the :term:`utf-8`
encoding.
        If you know you need to use an alternate encoding add a function
that
        does that to the list of functions in :attr:`converters`)

    .. versionadded:: 0.2.2
    .. versionchanged:: 1.0.1
        Code simplification allowed us to switch to using
        :data:`EXCEPTION_CONVERTERS` as the default value of
        :attr:`converters`.
    s%<exception failed to convert to
text>(R>(RORPRFRQ((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pytexception_to_bytes�s
cCs�|s
dSyt|d|�Wnptk
rFttjd���nKtk
rkttjd���n&tk
r�}t|jd��nX|j|d�}|r�t	j
jj|didd	6�}nt	j
jj|�}|S(
sdTake a :class:`unicode` string and turn it into a byte :class:`str`
    suitable for xml

    :arg string: :class:`unicode` string to encode into an XML compatible
byte
        :class:`str`
    :kwarg encoding: encoding to use for the returned byte :class:`str`.
        Default is to encode to :term:`UTF-8`.  If some of the characters
in
        :attr:`string` are not encodable in this encoding, the unknown
        characters will be entered into the output string using xml
character
        references.
    :kwarg attrib: If :data:`True`, quote the string for use in an xml
        attribute.  If :data:`False` (default), quote for use in an xml
text
        field.
    :kwarg control_chars: :term:`control characters` are not allowed in XML
        documents.  When we encounter those we need to know what to do. 
Valid
        options are:

        :replace: (default) Replace the control characters with ``?``
        :ignore: Remove the characters altogether from the output
        :strict: Raise an :exc:`~kitchen.text.exceptions.XmlEncodeError` 
when
            we encounter a :term:`control character`

    :raises kitchen.text.exceptions.XmlEncodeError: If
:attr:`control_chars`
        is set to ``strict`` and the string to be made suitable for output
to
        xml contains :term:`control characters` or if :attr:`string` is not
        a :class:`unicode` string then we raise this exception.
    :raises ValueError: If :attr:`control_chars` is set to something other
than
        ``replace``, ``ignore``, or ``strict``.
    :rtype: byte :class:`str`
    :returns: representation of the :class:`unicode` string as a valid XML
        byte :class:`str`

    XML files consist mainly of text encoded using a particular charset. 
XML
    also denies the use of certain bytes in the encoded text (example:
``ASCII
    Null``).  There are also special characters that must be escaped if
they
    are present in the input (example: ``<``).  This function takes care
of
    all of those issues for you.

    There are a few different ways to use this function depending on your
    needs.  The simplest invocation is like this::

       unicode_to_xml(u'String with non-ASCII characters: <"á
と">')

    This will return the following to you, encoded in :term:`utf-8`::

      'String with non-ASCII characters: &lt;"á
と"&gt;'

    Pretty straightforward.  Now, what if you need to encode your document
in
    something other than :term:`utf-8`?  For instance, ``latin-1``? 
Let's
    see::

       unicode_to_xml(u'String with non-ASCII characters: <"á
と">', encoding='latin-1')
       'String with non-ASCII characters: &lt;"á
&#12392;"&gt;'

    Because the ``と`` character is not available in the ``latin-1``
charset,
    it is replaced with ``&#12392;`` in our output.  This is an xml
character
    reference which represents the character at unicode codepoint
``12392``, the
    ``と`` character.

    When you want to reverse this, use :func:`xml_to_unicode` which will
turn
    a byte :class:`str` into a :class:`unicode` string and replace the xml
    character references with the unicode characters.

    XML also has the quirk of not allowing :term:`control characters` in
its
    output.  The :attr:`control_chars` parameter allows us to specify what
to
    do with those.  For use cases that don't need absolute character
by
    character fidelity (example: holding strings that will just be used for
    display in a GUI app later), the default value of ``replace`` works
well::

        unicode_to_xml(u'String with disallowed control chars:
\u0000\u0007')
        'String with disallowed control chars: ??'

    If you do need to be able to reproduce all of the characters at a later
    date (examples: if the string is a key value in a database or a path on
a
    filesystem) you have many choices.  Here are a few that rely on
``utf-7``,
    a verbose encoding that encodes :term:`control characters` (as well as
    non-:term:`ASCII` unicode values) to characters from within the
    :term:`ASCII` printable characters.  The good thing about doing this is
    that the code is pretty simple.  You just need to use ``utf-7`` both
when
    encoding the field for xml and when decoding it for use in your python
    program::

        unicode_to_xml(u'String with unicode: と and control char:
\u0007', encoding='utf7')
        'String with unicode: +MGg and control char: +AAc-'
        # [...]
        xml_to_unicode('String with unicode: +MGg and control char:
+AAc-', encoding='utf7')
        u'String with unicode: と and control char: \u0007'

    As you can see, the ``utf-7`` encoding will transform even characters
that
    would be representable in :term:`utf-8`.  This can be a drawback if you
    want unicode characters in the file to be readable without being
decoded
    first.  You can work around this with increased complexity in your
    application code::

        encoding = 'utf-8'
        u_string = u'String with unicode: と and control char:
\u0007'
        try:
            # First attempt to encode to utf8
            data = unicode_to_xml(u_string, encoding=encoding,
errors='strict')
        except XmlEncodeError:
            # Fallback to utf-7
            encoding = 'utf-7'
            data = unicode_to_xml(u_string, encoding=encoding,
errors='strict')
        write_tag('<mytag encoding=%s>%s</mytag>' %
(encoding, data))
        # [...]
        encoding = tag.attributes.encoding
        u_string = xml_to_unicode(u_string, encoding=encoding)

    Using code similar to that, you can have some fields encoded using your
    default encoding and fallback to ``utf-7`` if there are :term:`control
    characters` present.

    .. note::

        If your goal is to preserve the :term:`control characters` you
cannot
        save the entire file as ``utf-7`` and set the xml encoding
parameter
        to ``utf-7`` if your goal is to preserve the :term:`control
        characters`.  Because XML doesn't allow :term:`control
characters`,
        you have to encode those separate from any encoding work that the
XML
        parser itself knows about.

    .. seealso::

        :func:`bytes_to_xml`
            if you're dealing with bytes that are non-text or of an
unknown
            encoding that you must preserve on a byte for byte level.
        :func:`guess_encoding_to_xml`
            if you're dealing with strings in unknown encodings that
you don't
            need to save with char-for-char fidelity.
    R<tstrategysiunicode_to_xml must have a unicode type as the first
argument.  Use bytes_string_to_xml for byte strings.sVThe control_chars
argument to unicode_to_xml must be one of ignore, replace, or
strictitxmlcharrefreplacetentitiess&quot;t"(
RR3RR*R+t
ValueErrorRRLR4txmltsaxtsaxutilstescape(tstringR5tattribt
control_charsRO((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pytunicode_to_xml#s�

%cCs(t|d|d|�}t|�}|S(s
Transform a byte :class:`str` from an xml file into a :class:`unicode`
    string

    :arg byte_string: byte :class:`str` to decode
    :kwarg encoding: encoding that the byte :class:`str` is in
    :kwarg errors: What to do if not every character is  valid in
        :attr:`encoding`.  See the :func:`to_unicode` documentation for
legal
        values.
    :rtype: :class:`unicode` string
    :returns: string decoded from :attr:`byte_string`

    This function attempts to reverse what :func:`unicode_to_xml` does.  It
    takes a byte :class:`str` (presumably read in from an xml file) and
    expands all the html entities into unicode characters and decodes the
byte
    :class:`str` into a :class:`unicode` string.  One thing it cannot do is
    restore any :term:`control characters` that were removed prior to
    inserting into the file.  If you need to keep such characters you need
to
    use :func:`xml_to_bytes` and :func:`bytes_to_xml` or use on of the
    strategies documented in :func:`unicode_to_xml` instead.
   
R5R6(R;R(tbyte_stringR5R6R]((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pytxml_to_unicode�scCsUt|t�s'ttjd���nt|||�}t|d|d|d|�S(s�
Make sure a byte :class:`str` is validly encoded for xml output

    :arg byte_string: Byte :class:`str` to turn into valid xml output
    :kwarg input_encoding: Encoding of :attr:`byte_string`.  Default
``utf-8``
    :kwarg errors: How to handle errors encountered while decoding the
        :attr:`byte_string` into :class:`unicode` at the beginning of the
        process.  Values are:

        :replace: (default) Replace the invalid bytes with a ``?``
        :ignore: Remove the characters altogether from the output
        :strict: Raise an :exc:`UnicodeDecodeError` when we encounter
            a non-decodable character

    :kwarg output_encoding: Encoding for the xml file that this string will
go
        into.  Default is ``utf-8``.  If all the characters in
        :attr:`byte_string` are not encodable in this encoding, the unknown
        characters will be entered into the output string using xml
character
        references.
    :kwarg attrib: If :data:`True`, quote the string for use in an xml
        attribute.  If :data:`False` (default), quote for use in an xml
text
        field.
    :kwarg control_chars: XML does not allow :term:`control characters`. 
When
        we encounter those we need to know what to do.  Valid options are:

        :replace: (default) Replace the :term:`control characters` with
``?``
        :ignore: Remove the characters altogether from the output
        :strict: Raise an error when we encounter a :term:`control
character`

    :raises XmlEncodeError: If :attr:`control_chars` is set to ``strict``
and
        the string to be made suitable for output to xml contains
        :term:`control characters` then we raise this exception.
    :raises UnicodeDecodeError: If errors is set to ``strict`` and the
        :attr:`byte_string` contains bytes that are not decodable using
        :attr:`input_encoding`, this error is raised
    :rtype: byte :class:`str`
    :returns: representation of the byte :class:`str` in the output
encoding with
        any bytes that aren't available in xml taken care of.

    Use this when you have a byte :class:`str` representing text that you
need
    to make suitable for output to xml.  There are several cases where this
    is the case.  For instance, if you need to transform some strings
encoded
    in ``latin-1`` to :term:`utf-8` for output::

        utf8_string = byte_string_to_xml(latin1_string,
input_encoding='latin-1')

    If you already have strings in the proper encoding you may still want
to
    use this function to remove :term:`control characters`::

        cleaned_string = byte_string_to_xml(string,
input_encoding='utf-8', output_encoding='utf-8')

    .. seealso::

        :func:`unicode_to_xml`
            for other ideas on using this function
    smbyte_string_to_xml can only take a byte string as its first argument.
 Use unicode_to_xml for unicode
stringsR5R^R_(R"R1RR*R+R$R`(Ratinput_encodingR6toutput_encodingR^R_tu_string((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pytbyte_string_to_xml�s
9cCs"t|||�}t|||�S(s=Transform a byte
:class:`str` from an xml file into :class:`unicode`
    string

    :arg byte_string: byte :class:`str` to decode
    :kwarg input_encoding: encoding that the byte :class:`str` is in
    :kwarg errors: What to do if not every character is valid in
        :attr:`encoding`.  See the :func:`to_unicode` docstring for legal
        values.
    :kwarg output_encoding: Encoding for the output byte :class:`str`
    :returns: :class:`unicode` string decoded from :attr:`byte_string`

    This function attempts to reverse what :func:`unicode_to_xml` does.  It
    takes a byte :class:`str` (presumably read in from an xml file) and
    expands all the html entities into unicode characters and decodes the
    byte :class:`str` into a :class:`unicode` string.  One thing it cannot
do
    is restore any :term:`control characters` that were removed prior to
    inserting into the file.  If you need to keep such characters you need
to
    use :func:`xml_to_bytes` and :func:`bytes_to_xml` or use one of the
    strategies documented in :func:`unicode_to_xml` instead.
   
(RbR>(RaRcR6RdR]((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pytxml_to_byte_stringscOst|||�S(s3Return
a byte :class:`str` encoded so it is valid inside of any xml
    file

    :arg byte_string: byte :class:`str` to transform
    :arg \*args, \*\*kwargs: extra arguments to this function are passed on
to
        the function actually implementing the encoding.  You can use this
to
        tweak the output in some cases but, as a general rule, you
shouldn't
        because the underlying encoding function is not guaranteed to
remain
        the same.
    :rtype: byte :class:`str` consisting of all :term:`ASCII` characters
    :returns: byte :class:`str` representation of the input.  This will be
encoded
        using base64.

    This function is made especially to put binary information into xml
    documents.

    This function is intended for encoding things that must be preserved
    byte-for-byte.  If you want to encode a byte string that's text
and don't
    mind losing the actual bytes you probably want to try
:func:`byte_string_to_xml`
    or :func:`guess_encoding_to_xml` instead.

    .. note::

        Although the current implementation uses :func:`base64.b64encode`
and
        there's no plans to change it, that isn't guaranteed.  If
you want to
        make sure that you can encode and decode these messages it's
best to
        use :func:`xml_to_bytes` if you use this function to encode.
   
(R(RaRLtkwargs((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pytbytes_to_xml4scOst|||�S(s�Decode
a string encoded using :func:`bytes_to_xml`

    :arg byte_string: byte :class:`str` to transform.  This should be a
base64
        encoded sequence of bytes originally generated by
:func:`bytes_to_xml`.
    :arg \*args, \*\*kwargs: extra arguments to this function are passed on
to
        the function actually implementing the encoding.  You can use this
to
        tweak the output in some cases but, as a general rule, you
shouldn't
        because the underlying encoding function is not guaranteed to
remain
        the same.
    :rtype: byte :class:`str`
    :returns: byte :class:`str` that's the decoded input

    If you've got fields in an xml document that were encoded with
    :func:`bytes_to_xml` then you want to use this function to undecode
them.
    It converts a base64 encoded string into a byte :class:`str`.

    .. note::

        Although the current implementation uses :func:`base64.b64decode`
and
        there's no plans to change it, that isn't guaranteed.  If
you want to
        make sure that you can encode and decode these messages it's
best to
        use :func:`bytes_to_xml` if you use this function to decode.
   
(R(RaRLRh((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pytxml_to_bytesTscCs_t|t�r+t|d|d|d|�St|�}t|d|ddd|d|d|�S(s�Return
a byte :class:`str` suitable for inclusion in xml

    :arg string: :class:`unicode` or byte :class:`str` to be transformed
into
        a byte :class:`str` suitable for inclusion in xml.  If string is
        a byte :class:`str` we attempt to guess the encoding.  If we cannot
guess,
        we fallback to ``latin-1``.
    :kwarg output_encoding: Output encoding for the byte :class:`str`. 
This
        should match the encoding of your xml file.
    :kwarg attrib: If :data:`True`, escape the item for use in an xml
        attribute.  If :data:`False` (default) escape the item for use in
        a text node.
    :returns: :term:`utf-8` encoded byte :class:`str`

   
R5R^R_RcR6RRd(R"R$R`RRf(R]RdR^R_Rc((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pytguess_encoding_to_xmlns
tignorecCs;tjtjd�tdd�t|d|d|d|�S(s<*Deprecated*:
Use :func:`guess_encoding_to_xml` instead
    sikitchen.text.converters.to_xml is deprecated.  Use
kitchen.text.converters.guess_encoding_to_xml
instead.RiRdR^R_(R(R)R*R+R,Rk(R]R5R^R_((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pytto_xml�s
tBYTE_EXCEPTION_CONVERTERStEXCEPTION_CONVERTERSRfRiRSRRRIRkR>RKR;RJRmR`RgRjRb(
sutf-8sUTF-8sutf8R	sutf_8RsutfR
su8R(slatin-1sLATIN-1slatin1RslatinRsl1Rscp819Rs8859s	iso8859-1s	ISO8859-1s
iso-8859-1s
ISO-8859-1(sBYTE_EXCEPTION_CONVERTERSsEXCEPTION_CONVERTERSsbyte_string_to_xmlsbytes_to_xmlsexception_to_bytessexception_to_unicodes	getwritersguess_encoding_to_xmlsto_bytessto_strs
to_unicodesto_utf8sto_xmlsunicode_to_xmlsxml_to_byte_stringsxml_to_bytessxml_to_unicode(-t__doc__tbase64RRtImportErrortkitchen.pycompat24.base64R@R(txml.sax.saxutilsRYtkitchenR*tkitchen.pycompat24Rtadd_builtin_settkitchen.text.exceptionsRRtkitchen.text.miscRRRt	frozensetR%R&R0R;R>RIRJRKRoRnRRRStFalseR`RbRfRgRiRjRkRmt__all__(((s;/usr/lib/python2.7/site-packages/kitchen/text/converters.pyt<module>+s\

			k	v	F	8$�B