~dkuhlman/python-training-materials/Materials

« back to all changes in this revision

Viewing changes to python-2.7.11-docs-html/c-api/unicode.html

  • Committer: Dave Kuhlman
  • Date: 2017-04-15 16:24:56 UTC
  • Revision ID: dkuhlman@davekuhlman.org-20170415162456-iav9vozzg4iwqwv3
Updated docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
 
 
4
 
 
5
 
<html xmlns="http://www.w3.org/1999/xhtml">
6
 
  <head>
7
 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8
 
    
9
 
    <title>Unicode Objects and Codecs &mdash; Python 2.7.11 documentation</title>
10
 
    
11
 
    <link rel="stylesheet" href="../_static/classic.css" type="text/css" />
12
 
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
13
 
    
14
 
    <script type="text/javascript">
15
 
      var DOCUMENTATION_OPTIONS = {
16
 
        URL_ROOT:    '../',
17
 
        VERSION:     '2.7.11',
18
 
        COLLAPSE_INDEX: false,
19
 
        FILE_SUFFIX: '.html',
20
 
        HAS_SOURCE:  true
21
 
      };
22
 
    </script>
23
 
    <script type="text/javascript" src="../_static/jquery.js"></script>
24
 
    <script type="text/javascript" src="../_static/underscore.js"></script>
25
 
    <script type="text/javascript" src="../_static/doctools.js"></script>
26
 
    <script type="text/javascript" src="../_static/sidebar.js"></script>
27
 
    <link rel="search" type="application/opensearchdescription+xml"
28
 
          title="Search within Python 2.7.11 documentation"
29
 
          href="../_static/opensearch.xml"/>
30
 
    <link rel="author" title="About these documents" href="../about.html" />
31
 
    <link rel="copyright" title="Copyright" href="../copyright.html" />
32
 
    <link rel="top" title="Python 2.7.11 documentation" href="../contents.html" />
33
 
    <link rel="up" title="Concrete Objects Layer" href="concrete.html" />
34
 
    <link rel="next" title="Buffers and Memoryview Objects" href="buffer.html" />
35
 
    <link rel="prev" title="String/Bytes Objects" href="string.html" />
36
 
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
37
 
    <script type="text/javascript" src="../_static/copybutton.js"></script>
38
 
    <script type="text/javascript" src="../_static/version_switch.js"></script>
39
 
 
40
 
    
41
 
 
42
 
  </head>
43
 
  <body role="document">  
44
 
    <div class="related" role="navigation" aria-label="related navigation">
45
 
      <h3>Navigation</h3>
46
 
      <ul>
47
 
        <li class="right" style="margin-right: 10px">
48
 
          <a href="../genindex.html" title="General Index"
49
 
             accesskey="I">index</a></li>
50
 
        <li class="right" >
51
 
          <a href="../py-modindex.html" title="Python Module Index"
52
 
             >modules</a> |</li>
53
 
        <li class="right" >
54
 
          <a href="buffer.html" title="Buffers and Memoryview Objects"
55
 
             accesskey="N">next</a> |</li>
56
 
        <li class="right" >
57
 
          <a href="string.html" title="String/Bytes Objects"
58
 
             accesskey="P">previous</a> |</li>
59
 
        <li><img src="../_static/py.png" alt=""
60
 
                 style="vertical-align: middle; margin-top: -1px"/></li>
61
 
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
62
 
        <li>
63
 
          <span class="version_switcher_placeholder">2.7.11</span>
64
 
          <a href="../index.html">Documentation</a> &raquo;
65
 
        </li>
66
 
 
67
 
          <li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> &raquo;</li>
68
 
          <li class="nav-item nav-item-2"><a href="concrete.html" accesskey="U">Concrete Objects Layer</a> &raquo;</li> 
69
 
      </ul>
70
 
    </div>    
71
 
 
72
 
    <div class="document">
73
 
      <div class="documentwrapper">
74
 
        <div class="bodywrapper">
75
 
          <div class="body" role="main">
76
 
            
77
 
  <div class="section" id="unicode-objects-and-codecs">
78
 
<span id="unicodeobjects"></span><h1>Unicode Objects and Codecs<a class="headerlink" href="#unicode-objects-and-codecs" title="Permalink to this headline">¶</a></h1>
79
 
<div class="section" id="unicode-objects">
80
 
<h2>Unicode Objects<a class="headerlink" href="#unicode-objects" title="Permalink to this headline">¶</a></h2>
81
 
<div class="section" id="unicode-type">
82
 
<h3>Unicode Type<a class="headerlink" href="#unicode-type" title="Permalink to this headline">¶</a></h3>
83
 
<p>These are the basic Unicode object types used for the Unicode implementation in
84
 
Python:</p>
85
 
<dl class="type">
86
 
<dt id="c.Py_UNICODE">
87
 
<code class="descname">Py_UNICODE</code><a class="headerlink" href="#c.Py_UNICODE" title="Permalink to this definition">¶</a></dt>
88
 
<dd><p>This type represents the storage type which is used by Python internally as
89
 
basis for holding Unicode ordinals.  Python&#8217;s default builds use a 16-bit type
90
 
for <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></code></a> and store Unicode values internally as UCS2. It is also
91
 
possible to build a UCS4 version of Python (most recent Linux distributions come
92
 
with UCS4 builds of Python). These builds then use a 32-bit type for
93
 
<a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></code></a> and store Unicode data internally as UCS4. On platforms
94
 
where <code class="xref c c-type docutils literal"><span class="pre">wchar_t</span></code> is available and compatible with the chosen Python
95
 
Unicode build variant, <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></code></a> is a typedef alias for
96
 
<code class="xref c c-type docutils literal"><span class="pre">wchar_t</span></code> to enhance native platform compatibility. On all other
97
 
platforms, <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></code></a> is a typedef alias for either <code class="xref c c-type docutils literal"><span class="pre">unsigned</span>
98
 
<span class="pre">short</span></code> (UCS2) or <code class="xref c c-type docutils literal"><span class="pre">unsigned</span> <span class="pre">long</span></code> (UCS4).</p>
99
 
</dd></dl>
100
 
 
101
 
<p>Note that UCS2 and UCS4 Python builds are not binary compatible. Please keep
102
 
this in mind when writing extensions or interfaces.</p>
103
 
<dl class="type">
104
 
<dt id="c.PyUnicodeObject">
105
 
<code class="descname">PyUnicodeObject</code><a class="headerlink" href="#c.PyUnicodeObject" title="Permalink to this definition">¶</a></dt>
106
 
<dd><p>This subtype of <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><code class="xref c c-type docutils literal"><span class="pre">PyObject</span></code></a> represents a Python Unicode object.</p>
107
 
</dd></dl>
108
 
 
109
 
<dl class="var">
110
 
<dt id="c.PyUnicode_Type">
111
 
<a class="reference internal" href="type.html#c.PyTypeObject" title="PyTypeObject">PyTypeObject</a> <code class="descname">PyUnicode_Type</code><a class="headerlink" href="#c.PyUnicode_Type" title="Permalink to this definition">¶</a></dt>
112
 
<dd><p>This instance of <a class="reference internal" href="type.html#c.PyTypeObject" title="PyTypeObject"><code class="xref c c-type docutils literal"><span class="pre">PyTypeObject</span></code></a> represents the Python Unicode type.  It
113
 
is exposed to Python code as <code class="docutils literal"><span class="pre">unicode</span></code> and <code class="docutils literal"><span class="pre">types.UnicodeType</span></code>.</p>
114
 
</dd></dl>
115
 
 
116
 
<p>The following APIs are really C macros and can be used to do fast checks and to
117
 
access internal read-only data of Unicode objects:</p>
118
 
<dl class="function">
119
 
<dt id="c.PyUnicode_Check">
120
 
int <code class="descname">PyUnicode_Check</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_Check" title="Permalink to this definition">¶</a></dt>
121
 
<dd><p>Return true if the object <em>o</em> is a Unicode object or an instance of a Unicode
122
 
subtype.</p>
123
 
<div class="versionchanged">
124
 
<p><span class="versionmodified">Changed in version 2.2: </span>Allowed subtypes to be accepted.</p>
125
 
</div>
126
 
</dd></dl>
127
 
 
128
 
<dl class="function">
129
 
<dt id="c.PyUnicode_CheckExact">
130
 
int <code class="descname">PyUnicode_CheckExact</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_CheckExact" title="Permalink to this definition">¶</a></dt>
131
 
<dd><p>Return true if the object <em>o</em> is a Unicode object, but not an instance of a
132
 
subtype.</p>
133
 
<div class="versionadded">
134
 
<p><span class="versionmodified">New in version 2.2.</span></p>
135
 
</div>
136
 
</dd></dl>
137
 
 
138
 
<dl class="function">
139
 
<dt id="c.PyUnicode_GET_SIZE">
140
 
Py_ssize_t <code class="descname">PyUnicode_GET_SIZE</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_GET_SIZE" title="Permalink to this definition">¶</a></dt>
141
 
<dd><p>Return the size of the object.  <em>o</em> has to be a <a class="reference internal" href="#c.PyUnicodeObject" title="PyUnicodeObject"><code class="xref c c-type docutils literal"><span class="pre">PyUnicodeObject</span></code></a> (not
142
 
checked).</p>
143
 
<div class="versionchanged">
144
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function returned an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type. This might require changes
145
 
in your code for properly supporting 64-bit systems.</p>
146
 
</div>
147
 
</dd></dl>
148
 
 
149
 
<dl class="function">
150
 
<dt id="c.PyUnicode_GET_DATA_SIZE">
151
 
Py_ssize_t <code class="descname">PyUnicode_GET_DATA_SIZE</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_GET_DATA_SIZE" title="Permalink to this definition">¶</a></dt>
152
 
<dd><p>Return the size of the object&#8217;s internal buffer in bytes.  <em>o</em> has to be a
153
 
<a class="reference internal" href="#c.PyUnicodeObject" title="PyUnicodeObject"><code class="xref c c-type docutils literal"><span class="pre">PyUnicodeObject</span></code></a> (not checked).</p>
154
 
<div class="versionchanged">
155
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function returned an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type. This might require changes
156
 
in your code for properly supporting 64-bit systems.</p>
157
 
</div>
158
 
</dd></dl>
159
 
 
160
 
<dl class="function">
161
 
<dt id="c.PyUnicode_AS_UNICODE">
162
 
<a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a>* <code class="descname">PyUnicode_AS_UNICODE</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_AS_UNICODE" title="Permalink to this definition">¶</a></dt>
163
 
<dd><p>Return a pointer to the internal <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></code></a> buffer of the object.  <em>o</em>
164
 
has to be a <a class="reference internal" href="#c.PyUnicodeObject" title="PyUnicodeObject"><code class="xref c c-type docutils literal"><span class="pre">PyUnicodeObject</span></code></a> (not checked).</p>
165
 
</dd></dl>
166
 
 
167
 
<dl class="function">
168
 
<dt id="c.PyUnicode_AS_DATA">
169
 
const char* <code class="descname">PyUnicode_AS_DATA</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_AS_DATA" title="Permalink to this definition">¶</a></dt>
170
 
<dd><p>Return a pointer to the internal buffer of the object. <em>o</em> has to be a
171
 
<a class="reference internal" href="#c.PyUnicodeObject" title="PyUnicodeObject"><code class="xref c c-type docutils literal"><span class="pre">PyUnicodeObject</span></code></a> (not checked).</p>
172
 
</dd></dl>
173
 
 
174
 
<dl class="function">
175
 
<dt id="c.PyUnicode_ClearFreeList">
176
 
int <code class="descname">PyUnicode_ClearFreeList</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_ClearFreeList" title="Permalink to this definition">¶</a></dt>
177
 
<dd><p>Clear the free list. Return the total number of freed items.</p>
178
 
<div class="versionadded">
179
 
<p><span class="versionmodified">New in version 2.6.</span></p>
180
 
</div>
181
 
</dd></dl>
182
 
 
183
 
</div>
184
 
<div class="section" id="unicode-character-properties">
185
 
<h3>Unicode Character Properties<a class="headerlink" href="#unicode-character-properties" title="Permalink to this headline">¶</a></h3>
186
 
<p>Unicode provides many different character properties. The most often needed ones
187
 
are available through these macros which are mapped to C functions depending on
188
 
the Python configuration.</p>
189
 
<dl class="function">
190
 
<dt id="c.Py_UNICODE_ISSPACE">
191
 
int <code class="descname">Py_UNICODE_ISSPACE</code><span class="sig-paren">(</span><a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;ch</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_UNICODE_ISSPACE" title="Permalink to this definition">¶</a></dt>
192
 
<dd><p>Return 1 or 0 depending on whether <em>ch</em> is a whitespace character.</p>
193
 
</dd></dl>
194
 
 
195
 
<dl class="function">
196
 
<dt id="c.Py_UNICODE_ISLOWER">
197
 
int <code class="descname">Py_UNICODE_ISLOWER</code><span class="sig-paren">(</span><a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;ch</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_UNICODE_ISLOWER" title="Permalink to this definition">¶</a></dt>
198
 
<dd><p>Return 1 or 0 depending on whether <em>ch</em> is a lowercase character.</p>
199
 
</dd></dl>
200
 
 
201
 
<dl class="function">
202
 
<dt id="c.Py_UNICODE_ISUPPER">
203
 
int <code class="descname">Py_UNICODE_ISUPPER</code><span class="sig-paren">(</span><a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;ch</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_UNICODE_ISUPPER" title="Permalink to this definition">¶</a></dt>
204
 
<dd><p>Return 1 or 0 depending on whether <em>ch</em> is an uppercase character.</p>
205
 
</dd></dl>
206
 
 
207
 
<dl class="function">
208
 
<dt id="c.Py_UNICODE_ISTITLE">
209
 
int <code class="descname">Py_UNICODE_ISTITLE</code><span class="sig-paren">(</span><a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;ch</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_UNICODE_ISTITLE" title="Permalink to this definition">¶</a></dt>
210
 
<dd><p>Return 1 or 0 depending on whether <em>ch</em> is a titlecase character.</p>
211
 
</dd></dl>
212
 
 
213
 
<dl class="function">
214
 
<dt id="c.Py_UNICODE_ISLINEBREAK">
215
 
int <code class="descname">Py_UNICODE_ISLINEBREAK</code><span class="sig-paren">(</span><a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;ch</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_UNICODE_ISLINEBREAK" title="Permalink to this definition">¶</a></dt>
216
 
<dd><p>Return 1 or 0 depending on whether <em>ch</em> is a linebreak character.</p>
217
 
</dd></dl>
218
 
 
219
 
<dl class="function">
220
 
<dt id="c.Py_UNICODE_ISDECIMAL">
221
 
int <code class="descname">Py_UNICODE_ISDECIMAL</code><span class="sig-paren">(</span><a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;ch</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_UNICODE_ISDECIMAL" title="Permalink to this definition">¶</a></dt>
222
 
<dd><p>Return 1 or 0 depending on whether <em>ch</em> is a decimal character.</p>
223
 
</dd></dl>
224
 
 
225
 
<dl class="function">
226
 
<dt id="c.Py_UNICODE_ISDIGIT">
227
 
int <code class="descname">Py_UNICODE_ISDIGIT</code><span class="sig-paren">(</span><a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;ch</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_UNICODE_ISDIGIT" title="Permalink to this definition">¶</a></dt>
228
 
<dd><p>Return 1 or 0 depending on whether <em>ch</em> is a digit character.</p>
229
 
</dd></dl>
230
 
 
231
 
<dl class="function">
232
 
<dt id="c.Py_UNICODE_ISNUMERIC">
233
 
int <code class="descname">Py_UNICODE_ISNUMERIC</code><span class="sig-paren">(</span><a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;ch</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_UNICODE_ISNUMERIC" title="Permalink to this definition">¶</a></dt>
234
 
<dd><p>Return 1 or 0 depending on whether <em>ch</em> is a numeric character.</p>
235
 
</dd></dl>
236
 
 
237
 
<dl class="function">
238
 
<dt id="c.Py_UNICODE_ISALPHA">
239
 
int <code class="descname">Py_UNICODE_ISALPHA</code><span class="sig-paren">(</span><a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;ch</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_UNICODE_ISALPHA" title="Permalink to this definition">¶</a></dt>
240
 
<dd><p>Return 1 or 0 depending on whether <em>ch</em> is an alphabetic character.</p>
241
 
</dd></dl>
242
 
 
243
 
<dl class="function">
244
 
<dt id="c.Py_UNICODE_ISALNUM">
245
 
int <code class="descname">Py_UNICODE_ISALNUM</code><span class="sig-paren">(</span><a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;ch</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_UNICODE_ISALNUM" title="Permalink to this definition">¶</a></dt>
246
 
<dd><p>Return 1 or 0 depending on whether <em>ch</em> is an alphanumeric character.</p>
247
 
</dd></dl>
248
 
 
249
 
<p>These APIs can be used for fast direct character conversions:</p>
250
 
<dl class="function">
251
 
<dt id="c.Py_UNICODE_TOLOWER">
252
 
<a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a> <code class="descname">Py_UNICODE_TOLOWER</code><span class="sig-paren">(</span><a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;ch</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_UNICODE_TOLOWER" title="Permalink to this definition">¶</a></dt>
253
 
<dd><p>Return the character <em>ch</em> converted to lower case.</p>
254
 
</dd></dl>
255
 
 
256
 
<dl class="function">
257
 
<dt id="c.Py_UNICODE_TOUPPER">
258
 
<a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a> <code class="descname">Py_UNICODE_TOUPPER</code><span class="sig-paren">(</span><a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;ch</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_UNICODE_TOUPPER" title="Permalink to this definition">¶</a></dt>
259
 
<dd><p>Return the character <em>ch</em> converted to upper case.</p>
260
 
</dd></dl>
261
 
 
262
 
<dl class="function">
263
 
<dt id="c.Py_UNICODE_TOTITLE">
264
 
<a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a> <code class="descname">Py_UNICODE_TOTITLE</code><span class="sig-paren">(</span><a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;ch</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_UNICODE_TOTITLE" title="Permalink to this definition">¶</a></dt>
265
 
<dd><p>Return the character <em>ch</em> converted to title case.</p>
266
 
</dd></dl>
267
 
 
268
 
<dl class="function">
269
 
<dt id="c.Py_UNICODE_TODECIMAL">
270
 
int <code class="descname">Py_UNICODE_TODECIMAL</code><span class="sig-paren">(</span><a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;ch</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_UNICODE_TODECIMAL" title="Permalink to this definition">¶</a></dt>
271
 
<dd><p>Return the character <em>ch</em> converted to a decimal positive integer.  Return
272
 
<code class="docutils literal"><span class="pre">-1</span></code> if this is not possible.  This macro does not raise exceptions.</p>
273
 
</dd></dl>
274
 
 
275
 
<dl class="function">
276
 
<dt id="c.Py_UNICODE_TODIGIT">
277
 
int <code class="descname">Py_UNICODE_TODIGIT</code><span class="sig-paren">(</span><a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;ch</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_UNICODE_TODIGIT" title="Permalink to this definition">¶</a></dt>
278
 
<dd><p>Return the character <em>ch</em> converted to a single digit integer. Return <code class="docutils literal"><span class="pre">-1</span></code> if
279
 
this is not possible.  This macro does not raise exceptions.</p>
280
 
</dd></dl>
281
 
 
282
 
<dl class="function">
283
 
<dt id="c.Py_UNICODE_TONUMERIC">
284
 
double <code class="descname">Py_UNICODE_TONUMERIC</code><span class="sig-paren">(</span><a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;ch</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_UNICODE_TONUMERIC" title="Permalink to this definition">¶</a></dt>
285
 
<dd><p>Return the character <em>ch</em> converted to a double. Return <code class="docutils literal"><span class="pre">-1.0</span></code> if this is not
286
 
possible.  This macro does not raise exceptions.</p>
287
 
</dd></dl>
288
 
 
289
 
</div>
290
 
<div class="section" id="plain-py-unicode">
291
 
<h3>Plain Py_UNICODE<a class="headerlink" href="#plain-py-unicode" title="Permalink to this headline">¶</a></h3>
292
 
<p>To create Unicode objects and access their basic sequence properties, use these
293
 
APIs:</p>
294
 
<dl class="function">
295
 
<dt id="c.PyUnicode_FromUnicode">
296
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_FromUnicode</code><span class="sig-paren">(</span>const <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;*u</em>, Py_ssize_t<em>&nbsp;size</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_FromUnicode" title="Permalink to this definition">¶</a></dt>
297
 
<dd><em class="refcount">Return value: New reference.</em><p>Create a Unicode object from the Py_UNICODE buffer <em>u</em> of the given size. <em>u</em>
298
 
may be <em>NULL</em> which causes the contents to be undefined. It is the user&#8217;s
299
 
responsibility to fill in the needed data.  The buffer is copied into the new
300
 
object. If the buffer is not <em>NULL</em>, the return value might be a shared object.
301
 
Therefore, modification of the resulting Unicode object is only allowed when <em>u</em>
302
 
is <em>NULL</em>.</p>
303
 
<div class="versionchanged">
304
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
305
 
changes in your code for properly supporting 64-bit systems.</p>
306
 
</div>
307
 
</dd></dl>
308
 
 
309
 
<dl class="function">
310
 
<dt id="c.PyUnicode_FromStringAndSize">
311
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_FromStringAndSize</code><span class="sig-paren">(</span>const char<em>&nbsp;*u</em>, Py_ssize_t<em>&nbsp;size</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_FromStringAndSize" title="Permalink to this definition">¶</a></dt>
312
 
<dd><em class="refcount">Return value: New reference.</em><p>Create a Unicode object from the char buffer <em>u</em>.  The bytes will be interpreted
313
 
as being UTF-8 encoded.  <em>u</em> may also be <em>NULL</em> which
314
 
causes the contents to be undefined. It is the user&#8217;s responsibility to fill in
315
 
the needed data.  The buffer is copied into the new object. If the buffer is not
316
 
<em>NULL</em>, the return value might be a shared object. Therefore, modification of
317
 
the resulting Unicode object is only allowed when <em>u</em> is <em>NULL</em>.</p>
318
 
<div class="versionadded">
319
 
<p><span class="versionmodified">New in version 2.6.</span></p>
320
 
</div>
321
 
</dd></dl>
322
 
 
323
 
<dl class="function">
324
 
<dt id="c.PyUnicode_FromString">
325
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a> *<code class="descname">PyUnicode_FromString</code><span class="sig-paren">(</span>const char<em>&nbsp;*u</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_FromString" title="Permalink to this definition">¶</a></dt>
326
 
<dd><em class="refcount">Return value: New reference.</em><p>Create a Unicode object from an UTF-8 encoded null-terminated char buffer
327
 
<em>u</em>.</p>
328
 
<div class="versionadded">
329
 
<p><span class="versionmodified">New in version 2.6.</span></p>
330
 
</div>
331
 
</dd></dl>
332
 
 
333
 
<dl class="function">
334
 
<dt id="c.PyUnicode_FromFormat">
335
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_FromFormat</code><span class="sig-paren">(</span>const char<em>&nbsp;*format</em>, ...<span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_FromFormat" title="Permalink to this definition">¶</a></dt>
336
 
<dd><em class="refcount">Return value: New reference.</em><p>Take a C <code class="xref c c-func docutils literal"><span class="pre">printf()</span></code>-style <em>format</em> string and a variable number of
337
 
arguments, calculate the size of the resulting Python unicode string and return
338
 
a string with the values formatted into it.  The variable arguments must be C
339
 
types and must correspond exactly to the format characters in the <em>format</em>
340
 
string.  The following format characters are allowed:</p>
341
 
<table border="1" class="docutils">
342
 
<colgroup>
343
 
<col width="26%" />
344
 
<col width="29%" />
345
 
<col width="44%" />
346
 
</colgroup>
347
 
<thead valign="bottom">
348
 
<tr class="row-odd"><th class="head">Format Characters</th>
349
 
<th class="head">Type</th>
350
 
<th class="head">Comment</th>
351
 
</tr>
352
 
</thead>
353
 
<tbody valign="top">
354
 
<tr class="row-even"><td><code class="xref py py-attr docutils literal"><span class="pre">%%</span></code></td>
355
 
<td><em>n/a</em></td>
356
 
<td>The literal % character.</td>
357
 
</tr>
358
 
<tr class="row-odd"><td><code class="xref py py-attr docutils literal"><span class="pre">%c</span></code></td>
359
 
<td>int</td>
360
 
<td>A single character,
361
 
represented as an C int.</td>
362
 
</tr>
363
 
<tr class="row-even"><td><code class="xref py py-attr docutils literal"><span class="pre">%d</span></code></td>
364
 
<td>int</td>
365
 
<td>Exactly equivalent to
366
 
<code class="docutils literal"><span class="pre">printf(&quot;%d&quot;)</span></code>.</td>
367
 
</tr>
368
 
<tr class="row-odd"><td><code class="xref py py-attr docutils literal"><span class="pre">%u</span></code></td>
369
 
<td>unsigned int</td>
370
 
<td>Exactly equivalent to
371
 
<code class="docutils literal"><span class="pre">printf(&quot;%u&quot;)</span></code>.</td>
372
 
</tr>
373
 
<tr class="row-even"><td><code class="xref py py-attr docutils literal"><span class="pre">%ld</span></code></td>
374
 
<td>long</td>
375
 
<td>Exactly equivalent to
376
 
<code class="docutils literal"><span class="pre">printf(&quot;%ld&quot;)</span></code>.</td>
377
 
</tr>
378
 
<tr class="row-odd"><td><code class="xref py py-attr docutils literal"><span class="pre">%lu</span></code></td>
379
 
<td>unsigned long</td>
380
 
<td>Exactly equivalent to
381
 
<code class="docutils literal"><span class="pre">printf(&quot;%lu&quot;)</span></code>.</td>
382
 
</tr>
383
 
<tr class="row-even"><td><code class="xref py py-attr docutils literal"><span class="pre">%zd</span></code></td>
384
 
<td>Py_ssize_t</td>
385
 
<td>Exactly equivalent to
386
 
<code class="docutils literal"><span class="pre">printf(&quot;%zd&quot;)</span></code>.</td>
387
 
</tr>
388
 
<tr class="row-odd"><td><code class="xref py py-attr docutils literal"><span class="pre">%zu</span></code></td>
389
 
<td>size_t</td>
390
 
<td>Exactly equivalent to
391
 
<code class="docutils literal"><span class="pre">printf(&quot;%zu&quot;)</span></code>.</td>
392
 
</tr>
393
 
<tr class="row-even"><td><code class="xref py py-attr docutils literal"><span class="pre">%i</span></code></td>
394
 
<td>int</td>
395
 
<td>Exactly equivalent to
396
 
<code class="docutils literal"><span class="pre">printf(&quot;%i&quot;)</span></code>.</td>
397
 
</tr>
398
 
<tr class="row-odd"><td><code class="xref py py-attr docutils literal"><span class="pre">%x</span></code></td>
399
 
<td>int</td>
400
 
<td>Exactly equivalent to
401
 
<code class="docutils literal"><span class="pre">printf(&quot;%x&quot;)</span></code>.</td>
402
 
</tr>
403
 
<tr class="row-even"><td><code class="xref py py-attr docutils literal"><span class="pre">%s</span></code></td>
404
 
<td>char*</td>
405
 
<td>A null-terminated C character
406
 
array.</td>
407
 
</tr>
408
 
<tr class="row-odd"><td><code class="xref py py-attr docutils literal"><span class="pre">%p</span></code></td>
409
 
<td>void*</td>
410
 
<td>The hex representation of a C
411
 
pointer. Mostly equivalent to
412
 
<code class="docutils literal"><span class="pre">printf(&quot;%p&quot;)</span></code> except that
413
 
it is guaranteed to start with
414
 
the literal <code class="docutils literal"><span class="pre">0x</span></code> regardless
415
 
of what the platform&#8217;s
416
 
<code class="docutils literal"><span class="pre">printf</span></code> yields.</td>
417
 
</tr>
418
 
<tr class="row-even"><td><code class="xref py py-attr docutils literal"><span class="pre">%U</span></code></td>
419
 
<td>PyObject*</td>
420
 
<td>A unicode object.</td>
421
 
</tr>
422
 
<tr class="row-odd"><td><code class="xref py py-attr docutils literal"><span class="pre">%V</span></code></td>
423
 
<td>PyObject*, char *</td>
424
 
<td>A unicode object (which may be
425
 
<em>NULL</em>) and a null-terminated
426
 
C character array as a second
427
 
parameter (which will be used,
428
 
if the first parameter is
429
 
<em>NULL</em>).</td>
430
 
</tr>
431
 
<tr class="row-even"><td><code class="xref py py-attr docutils literal"><span class="pre">%S</span></code></td>
432
 
<td>PyObject*</td>
433
 
<td>The result of calling
434
 
<code class="xref py py-func docutils literal"><span class="pre">PyObject_Unicode()</span></code>.</td>
435
 
</tr>
436
 
<tr class="row-odd"><td><code class="xref py py-attr docutils literal"><span class="pre">%R</span></code></td>
437
 
<td>PyObject*</td>
438
 
<td>The result of calling
439
 
<code class="xref py py-func docutils literal"><span class="pre">PyObject_Repr()</span></code>.</td>
440
 
</tr>
441
 
</tbody>
442
 
</table>
443
 
<p>An unrecognized format character causes all the rest of the format string to be
444
 
copied as-is to the result string, and any extra arguments discarded.</p>
445
 
<div class="versionadded">
446
 
<p><span class="versionmodified">New in version 2.6.</span></p>
447
 
</div>
448
 
</dd></dl>
449
 
 
450
 
<dl class="function">
451
 
<dt id="c.PyUnicode_FromFormatV">
452
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_FromFormatV</code><span class="sig-paren">(</span>const char<em>&nbsp;*format</em>, va_list<em>&nbsp;vargs</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_FromFormatV" title="Permalink to this definition">¶</a></dt>
453
 
<dd><em class="refcount">Return value: New reference.</em><p>Identical to <code class="xref py py-func docutils literal"><span class="pre">PyUnicode_FromFormat()</span></code> except that it takes exactly two
454
 
arguments.</p>
455
 
<div class="versionadded">
456
 
<p><span class="versionmodified">New in version 2.6.</span></p>
457
 
</div>
458
 
</dd></dl>
459
 
 
460
 
<dl class="function">
461
 
<dt id="c.PyUnicode_AsUnicode">
462
 
<a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a>* <code class="descname">PyUnicode_AsUnicode</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*unicode</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_AsUnicode" title="Permalink to this definition">¶</a></dt>
463
 
<dd><p>Return a read-only pointer to the Unicode object&#8217;s internal
464
 
<a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></code></a> buffer, <em>NULL</em> if <em>unicode</em> is not a Unicode object.
465
 
Note that the resulting <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE*</span></code></a> string may contain embedded
466
 
null characters, which would cause the string to be truncated when used in
467
 
most C functions.</p>
468
 
</dd></dl>
469
 
 
470
 
<dl class="function">
471
 
<dt id="c.PyUnicode_GetSize">
472
 
Py_ssize_t <code class="descname">PyUnicode_GetSize</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*unicode</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_GetSize" title="Permalink to this definition">¶</a></dt>
473
 
<dd><p>Return the length of the Unicode object.</p>
474
 
<div class="versionchanged">
475
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function returned an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type. This might require changes
476
 
in your code for properly supporting 64-bit systems.</p>
477
 
</div>
478
 
</dd></dl>
479
 
 
480
 
<dl class="function">
481
 
<dt id="c.PyUnicode_FromEncodedObject">
482
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_FromEncodedObject</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*obj</em>, const char<em>&nbsp;*encoding</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_FromEncodedObject" title="Permalink to this definition">¶</a></dt>
483
 
<dd><em class="refcount">Return value: New reference.</em><p>Coerce an encoded object <em>obj</em> to an Unicode object and return a reference with
484
 
incremented refcount.</p>
485
 
<p>String and other char buffer compatible objects are decoded according to the
486
 
given encoding and using the error handling defined by errors.  Both can be
487
 
<em>NULL</em> to have the interface use the default values (see the next section for
488
 
details).</p>
489
 
<p>All other objects, including Unicode objects, cause a <a class="reference internal" href="../library/exceptions.html#exceptions.TypeError" title="exceptions.TypeError"><code class="xref py py-exc docutils literal"><span class="pre">TypeError</span></code></a> to be
490
 
set.</p>
491
 
<p>The API returns <em>NULL</em> if there was an error.  The caller is responsible for
492
 
decref&#8217;ing the returned objects.</p>
493
 
</dd></dl>
494
 
 
495
 
<dl class="function">
496
 
<dt id="c.PyUnicode_FromObject">
497
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_FromObject</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_FromObject" title="Permalink to this definition">¶</a></dt>
498
 
<dd><em class="refcount">Return value: New reference.</em><p>Shortcut for <code class="docutils literal"><span class="pre">PyUnicode_FromEncodedObject(obj,</span> <span class="pre">NULL,</span> <span class="pre">&quot;strict&quot;)</span></code> which is used
499
 
throughout the interpreter whenever coercion to Unicode is needed.</p>
500
 
</dd></dl>
501
 
 
502
 
<p>If the platform supports <code class="xref c c-type docutils literal"><span class="pre">wchar_t</span></code> and provides a header file wchar.h,
503
 
Python can interface directly to this type using the following functions.
504
 
Support is optimized if Python&#8217;s own <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></code></a> type is identical to
505
 
the system&#8217;s <code class="xref c c-type docutils literal"><span class="pre">wchar_t</span></code>.</p>
506
 
</div>
507
 
<div class="section" id="wchar-t-support">
508
 
<h3>wchar_t Support<a class="headerlink" href="#wchar-t-support" title="Permalink to this headline">¶</a></h3>
509
 
<p><code class="xref c c-type docutils literal"><span class="pre">wchar_t</span></code> support for platforms which support it:</p>
510
 
<dl class="function">
511
 
<dt id="c.PyUnicode_FromWideChar">
512
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_FromWideChar</code><span class="sig-paren">(</span>const wchar_t<em>&nbsp;*w</em>, Py_ssize_t<em>&nbsp;size</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_FromWideChar" title="Permalink to this definition">¶</a></dt>
513
 
<dd><em class="refcount">Return value: New reference.</em><p>Create a Unicode object from the <code class="xref c c-type docutils literal"><span class="pre">wchar_t</span></code> buffer <em>w</em> of the given <em>size</em>.
514
 
Return <em>NULL</em> on failure.</p>
515
 
<div class="versionchanged">
516
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
517
 
changes in your code for properly supporting 64-bit systems.</p>
518
 
</div>
519
 
</dd></dl>
520
 
 
521
 
<dl class="function">
522
 
<dt id="c.PyUnicode_AsWideChar">
523
 
Py_ssize_t <code class="descname">PyUnicode_AsWideChar</code><span class="sig-paren">(</span><a class="reference internal" href="#c.PyUnicodeObject" title="PyUnicodeObject">PyUnicodeObject</a><em>&nbsp;*unicode</em>, wchar_t<em>&nbsp;*w</em>, Py_ssize_t<em>&nbsp;size</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_AsWideChar" title="Permalink to this definition">¶</a></dt>
524
 
<dd><p>Copy the Unicode object contents into the <code class="xref c c-type docutils literal"><span class="pre">wchar_t</span></code> buffer <em>w</em>.  At most
525
 
<em>size</em> <code class="xref c c-type docutils literal"><span class="pre">wchar_t</span></code> characters are copied (excluding a possibly trailing
526
 
0-termination character).  Return the number of <code class="xref c c-type docutils literal"><span class="pre">wchar_t</span></code> characters
527
 
copied or -1 in case of an error.  Note that the resulting <code class="xref c c-type docutils literal"><span class="pre">wchar_t</span></code>
528
 
string may or may not be 0-terminated.  It is the responsibility of the caller
529
 
to make sure that the <code class="xref c c-type docutils literal"><span class="pre">wchar_t</span></code> string is 0-terminated in case this is
530
 
required by the application. Also, note that the <code class="xref c c-type docutils literal"><span class="pre">wchar_t*</span></code> string
531
 
might contain null characters, which would cause the string to be truncated
532
 
when used with most C functions.</p>
533
 
<div class="versionchanged">
534
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function returned an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type and used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code>
535
 
type for <em>size</em>. This might require changes in your code for properly
536
 
supporting 64-bit systems.</p>
537
 
</div>
538
 
</dd></dl>
539
 
 
540
 
</div>
541
 
</div>
542
 
<div class="section" id="built-in-codecs">
543
 
<span id="builtincodecs"></span><h2>Built-in Codecs<a class="headerlink" href="#built-in-codecs" title="Permalink to this headline">¶</a></h2>
544
 
<p>Python provides a set of built-in codecs which are written in C for speed. All of
545
 
these codecs are directly usable via the following functions.</p>
546
 
<p>Many of the following APIs take two arguments encoding and errors, and they
547
 
have the same semantics as the ones of the built-in <a class="reference internal" href="../library/functions.html#unicode" title="unicode"><code class="xref py py-func docutils literal"><span class="pre">unicode()</span></code></a> Unicode
548
 
object constructor.</p>
549
 
<p>Setting encoding to <em>NULL</em> causes the default encoding to be used which is
550
 
ASCII.  The file system calls should use <code class="xref c c-data docutils literal"><span class="pre">Py_FileSystemDefaultEncoding</span></code>
551
 
as the encoding for file names. This variable should be treated as read-only: on
552
 
some systems, it will be a pointer to a static string, on others, it will change
553
 
at run-time (such as when the application invokes setlocale).</p>
554
 
<p>Error handling is set by errors which may also be set to <em>NULL</em> meaning to use
555
 
the default handling defined for the codec.  Default error handling for all
556
 
built-in codecs is &#8220;strict&#8221; (<a class="reference internal" href="../library/exceptions.html#exceptions.ValueError" title="exceptions.ValueError"><code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code></a> is raised).</p>
557
 
<p>The codecs all use a similar interface.  Only deviation from the following
558
 
generic ones are documented for simplicity.</p>
559
 
<div class="section" id="generic-codecs">
560
 
<h3>Generic Codecs<a class="headerlink" href="#generic-codecs" title="Permalink to this headline">¶</a></h3>
561
 
<p>These are the generic codec APIs:</p>
562
 
<dl class="function">
563
 
<dt id="c.PyUnicode_Decode">
564
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_Decode</code><span class="sig-paren">(</span>const char<em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*encoding</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_Decode" title="Permalink to this definition">¶</a></dt>
565
 
<dd><em class="refcount">Return value: New reference.</em><p>Create a Unicode object by decoding <em>size</em> bytes of the encoded string <em>s</em>.
566
 
<em>encoding</em> and <em>errors</em> have the same meaning as the parameters of the same name
567
 
in the <a class="reference internal" href="../library/functions.html#unicode" title="unicode"><code class="xref py py-func docutils literal"><span class="pre">unicode()</span></code></a> built-in function.  The codec to be used is looked up
568
 
using the Python codec registry.  Return <em>NULL</em> if an exception was raised by
569
 
the codec.</p>
570
 
<div class="versionchanged">
571
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
572
 
changes in your code for properly supporting 64-bit systems.</p>
573
 
</div>
574
 
</dd></dl>
575
 
 
576
 
<dl class="function">
577
 
<dt id="c.PyUnicode_Encode">
578
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_Encode</code><span class="sig-paren">(</span>const <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*encoding</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_Encode" title="Permalink to this definition">¶</a></dt>
579
 
<dd><em class="refcount">Return value: New reference.</em><p>Encode the <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></code></a> buffer <em>s</em> of the given <em>size</em> and return a Python
580
 
string object.  <em>encoding</em> and <em>errors</em> have the same meaning as the parameters
581
 
of the same name in the Unicode <code class="xref py py-meth docutils literal"><span class="pre">encode()</span></code> method.  The codec
582
 
to be used is looked up using the Python codec registry.  Return <em>NULL</em> if
583
 
an exception was raised by the codec.</p>
584
 
<div class="versionchanged">
585
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
586
 
changes in your code for properly supporting 64-bit systems.</p>
587
 
</div>
588
 
</dd></dl>
589
 
 
590
 
<dl class="function">
591
 
<dt id="c.PyUnicode_AsEncodedString">
592
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_AsEncodedString</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*unicode</em>, const char<em>&nbsp;*encoding</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_AsEncodedString" title="Permalink to this definition">¶</a></dt>
593
 
<dd><em class="refcount">Return value: New reference.</em><p>Encode a Unicode object and return the result as Python string object.
594
 
<em>encoding</em> and <em>errors</em> have the same meaning as the parameters of the same name
595
 
in the Unicode <code class="xref py py-meth docutils literal"><span class="pre">encode()</span></code> method. The codec to be used is looked up using
596
 
the Python codec registry. Return <em>NULL</em> if an exception was raised by the
597
 
codec.</p>
598
 
</dd></dl>
599
 
 
600
 
</div>
601
 
<div class="section" id="utf-8-codecs">
602
 
<h3>UTF-8 Codecs<a class="headerlink" href="#utf-8-codecs" title="Permalink to this headline">¶</a></h3>
603
 
<p>These are the UTF-8 codec APIs:</p>
604
 
<dl class="function">
605
 
<dt id="c.PyUnicode_DecodeUTF8">
606
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_DecodeUTF8</code><span class="sig-paren">(</span>const char<em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_DecodeUTF8" title="Permalink to this definition">¶</a></dt>
607
 
<dd><em class="refcount">Return value: New reference.</em><p>Create a Unicode object by decoding <em>size</em> bytes of the UTF-8 encoded string
608
 
<em>s</em>. Return <em>NULL</em> if an exception was raised by the codec.</p>
609
 
<div class="versionchanged">
610
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
611
 
changes in your code for properly supporting 64-bit systems.</p>
612
 
</div>
613
 
</dd></dl>
614
 
 
615
 
<dl class="function">
616
 
<dt id="c.PyUnicode_DecodeUTF8Stateful">
617
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_DecodeUTF8Stateful</code><span class="sig-paren">(</span>const char<em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em>, Py_ssize_t<em>&nbsp;*consumed</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_DecodeUTF8Stateful" title="Permalink to this definition">¶</a></dt>
618
 
<dd><em class="refcount">Return value: New reference.</em><p>If <em>consumed</em> is <em>NULL</em>, behave like <a class="reference internal" href="#c.PyUnicode_DecodeUTF8" title="PyUnicode_DecodeUTF8"><code class="xref c c-func docutils literal"><span class="pre">PyUnicode_DecodeUTF8()</span></code></a>. If
619
 
<em>consumed</em> is not <em>NULL</em>, trailing incomplete UTF-8 byte sequences will not be
620
 
treated as an error. Those bytes will not be decoded and the number of bytes
621
 
that have been decoded will be stored in <em>consumed</em>.</p>
622
 
<div class="versionadded">
623
 
<p><span class="versionmodified">New in version 2.4.</span></p>
624
 
</div>
625
 
<div class="versionchanged">
626
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
627
 
changes in your code for properly supporting 64-bit systems.</p>
628
 
</div>
629
 
</dd></dl>
630
 
 
631
 
<dl class="function">
632
 
<dt id="c.PyUnicode_EncodeUTF8">
633
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_EncodeUTF8</code><span class="sig-paren">(</span>const <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_EncodeUTF8" title="Permalink to this definition">¶</a></dt>
634
 
<dd><em class="refcount">Return value: New reference.</em><p>Encode the <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></code></a> buffer <em>s</em> of the given <em>size</em> using UTF-8 and return a
635
 
Python string object.  Return <em>NULL</em> if an exception was raised by the codec.</p>
636
 
<div class="versionchanged">
637
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
638
 
changes in your code for properly supporting 64-bit systems.</p>
639
 
</div>
640
 
</dd></dl>
641
 
 
642
 
<dl class="function">
643
 
<dt id="c.PyUnicode_AsUTF8String">
644
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_AsUTF8String</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*unicode</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_AsUTF8String" title="Permalink to this definition">¶</a></dt>
645
 
<dd><em class="refcount">Return value: New reference.</em><p>Encode a Unicode object using UTF-8 and return the result as Python string
646
 
object.  Error handling is &#8220;strict&#8221;.  Return <em>NULL</em> if an exception was raised
647
 
by the codec.</p>
648
 
</dd></dl>
649
 
 
650
 
</div>
651
 
<div class="section" id="utf-32-codecs">
652
 
<h3>UTF-32 Codecs<a class="headerlink" href="#utf-32-codecs" title="Permalink to this headline">¶</a></h3>
653
 
<p>These are the UTF-32 codec APIs:</p>
654
 
<dl class="function">
655
 
<dt id="c.PyUnicode_DecodeUTF32">
656
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_DecodeUTF32</code><span class="sig-paren">(</span>const char<em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em>, int<em>&nbsp;*byteorder</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_DecodeUTF32" title="Permalink to this definition">¶</a></dt>
657
 
<dd><p>Decode <em>size</em> bytes from a UTF-32 encoded buffer string and return the
658
 
corresponding Unicode object.  <em>errors</em> (if non-<em>NULL</em>) defines the error
659
 
handling. It defaults to &#8220;strict&#8221;.</p>
660
 
<p>If <em>byteorder</em> is non-<em>NULL</em>, the decoder starts decoding using the given byte
661
 
order:</p>
662
 
<div class="highlight-c"><div class="highlight"><pre><span class="o">*</span><span class="n">byteorder</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="o">:</span> <span class="n">little</span> <span class="n">endian</span>
663
 
<span class="o">*</span><span class="n">byteorder</span> <span class="o">==</span> <span class="mi">0</span><span class="o">:</span>  <span class="n">native</span> <span class="n">order</span>
664
 
<span class="o">*</span><span class="n">byteorder</span> <span class="o">==</span> <span class="mi">1</span><span class="o">:</span>  <span class="n">big</span> <span class="n">endian</span>
665
 
</pre></div>
666
 
</div>
667
 
<p>If <code class="docutils literal"><span class="pre">*byteorder</span></code> is zero, and the first four bytes of the input data are a
668
 
byte order mark (BOM), the decoder switches to this byte order and the BOM is
669
 
not copied into the resulting Unicode string.  If <code class="docutils literal"><span class="pre">*byteorder</span></code> is <code class="docutils literal"><span class="pre">-1</span></code> or
670
 
<code class="docutils literal"><span class="pre">1</span></code>, any byte order mark is copied to the output.</p>
671
 
<p>After completion, <em>*byteorder</em> is set to the current byte order at the end
672
 
of input data.</p>
673
 
<p>In a narrow build code points outside the BMP will be decoded as surrogate pairs.</p>
674
 
<p>If <em>byteorder</em> is <em>NULL</em>, the codec starts in native order mode.</p>
675
 
<p>Return <em>NULL</em> if an exception was raised by the codec.</p>
676
 
<div class="versionadded">
677
 
<p><span class="versionmodified">New in version 2.6.</span></p>
678
 
</div>
679
 
</dd></dl>
680
 
 
681
 
<dl class="function">
682
 
<dt id="c.PyUnicode_DecodeUTF32Stateful">
683
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_DecodeUTF32Stateful</code><span class="sig-paren">(</span>const char<em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em>, int<em>&nbsp;*byteorder</em>, Py_ssize_t<em>&nbsp;*consumed</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_DecodeUTF32Stateful" title="Permalink to this definition">¶</a></dt>
684
 
<dd><p>If <em>consumed</em> is <em>NULL</em>, behave like <a class="reference internal" href="#c.PyUnicode_DecodeUTF32" title="PyUnicode_DecodeUTF32"><code class="xref c c-func docutils literal"><span class="pre">PyUnicode_DecodeUTF32()</span></code></a>. If
685
 
<em>consumed</em> is not <em>NULL</em>, <a class="reference internal" href="#c.PyUnicode_DecodeUTF32Stateful" title="PyUnicode_DecodeUTF32Stateful"><code class="xref c c-func docutils literal"><span class="pre">PyUnicode_DecodeUTF32Stateful()</span></code></a> will not treat
686
 
trailing incomplete UTF-32 byte sequences (such as a number of bytes not divisible
687
 
by four) as an error. Those bytes will not be decoded and the number of bytes
688
 
that have been decoded will be stored in <em>consumed</em>.</p>
689
 
<div class="versionadded">
690
 
<p><span class="versionmodified">New in version 2.6.</span></p>
691
 
</div>
692
 
</dd></dl>
693
 
 
694
 
<dl class="function">
695
 
<dt id="c.PyUnicode_EncodeUTF32">
696
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_EncodeUTF32</code><span class="sig-paren">(</span>const <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em>, int<em>&nbsp;byteorder</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_EncodeUTF32" title="Permalink to this definition">¶</a></dt>
697
 
<dd><p>Return a Python bytes object holding the UTF-32 encoded value of the Unicode
698
 
data in <em>s</em>.  Output is written according to the following byte order:</p>
699
 
<div class="highlight-c"><div class="highlight"><pre><span class="n">byteorder</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="o">:</span> <span class="n">little</span> <span class="n">endian</span>
700
 
<span class="n">byteorder</span> <span class="o">==</span> <span class="mi">0</span><span class="o">:</span>  <span class="n">native</span> <span class="n">byte</span> <span class="n">order</span> <span class="p">(</span><span class="n">writes</span> <span class="n">a</span> <span class="n">BOM</span> <span class="n">mark</span><span class="p">)</span>
701
 
<span class="n">byteorder</span> <span class="o">==</span> <span class="mi">1</span><span class="o">:</span>  <span class="n">big</span> <span class="n">endian</span>
702
 
</pre></div>
703
 
</div>
704
 
<p>If byteorder is <code class="docutils literal"><span class="pre">0</span></code>, the output string will always start with the Unicode BOM
705
 
mark (U+FEFF). In the other two modes, no BOM mark is prepended.</p>
706
 
<p>If <em>Py_UNICODE_WIDE</em> is not defined, surrogate pairs will be output
707
 
as a single code point.</p>
708
 
<p>Return <em>NULL</em> if an exception was raised by the codec.</p>
709
 
<div class="versionadded">
710
 
<p><span class="versionmodified">New in version 2.6.</span></p>
711
 
</div>
712
 
</dd></dl>
713
 
 
714
 
<dl class="function">
715
 
<dt id="c.PyUnicode_AsUTF32String">
716
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_AsUTF32String</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*unicode</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_AsUTF32String" title="Permalink to this definition">¶</a></dt>
717
 
<dd><p>Return a Python string using the UTF-32 encoding in native byte order. The
718
 
string always starts with a BOM mark.  Error handling is &#8220;strict&#8221;.  Return
719
 
<em>NULL</em> if an exception was raised by the codec.</p>
720
 
<div class="versionadded">
721
 
<p><span class="versionmodified">New in version 2.6.</span></p>
722
 
</div>
723
 
</dd></dl>
724
 
 
725
 
</div>
726
 
<div class="section" id="utf-16-codecs">
727
 
<h3>UTF-16 Codecs<a class="headerlink" href="#utf-16-codecs" title="Permalink to this headline">¶</a></h3>
728
 
<p>These are the UTF-16 codec APIs:</p>
729
 
<dl class="function">
730
 
<dt id="c.PyUnicode_DecodeUTF16">
731
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_DecodeUTF16</code><span class="sig-paren">(</span>const char<em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em>, int<em>&nbsp;*byteorder</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_DecodeUTF16" title="Permalink to this definition">¶</a></dt>
732
 
<dd><em class="refcount">Return value: New reference.</em><p>Decode <em>size</em> bytes from a UTF-16 encoded buffer string and return the
733
 
corresponding Unicode object.  <em>errors</em> (if non-<em>NULL</em>) defines the error
734
 
handling. It defaults to &#8220;strict&#8221;.</p>
735
 
<p>If <em>byteorder</em> is non-<em>NULL</em>, the decoder starts decoding using the given byte
736
 
order:</p>
737
 
<div class="highlight-c"><div class="highlight"><pre><span class="o">*</span><span class="n">byteorder</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="o">:</span> <span class="n">little</span> <span class="n">endian</span>
738
 
<span class="o">*</span><span class="n">byteorder</span> <span class="o">==</span> <span class="mi">0</span><span class="o">:</span>  <span class="n">native</span> <span class="n">order</span>
739
 
<span class="o">*</span><span class="n">byteorder</span> <span class="o">==</span> <span class="mi">1</span><span class="o">:</span>  <span class="n">big</span> <span class="n">endian</span>
740
 
</pre></div>
741
 
</div>
742
 
<p>If <code class="docutils literal"><span class="pre">*byteorder</span></code> is zero, and the first two bytes of the input data are a
743
 
byte order mark (BOM), the decoder switches to this byte order and the BOM is
744
 
not copied into the resulting Unicode string.  If <code class="docutils literal"><span class="pre">*byteorder</span></code> is <code class="docutils literal"><span class="pre">-1</span></code> or
745
 
<code class="docutils literal"><span class="pre">1</span></code>, any byte order mark is copied to the output (where it will result in
746
 
either a <code class="docutils literal"><span class="pre">\ufeff</span></code> or a <code class="docutils literal"><span class="pre">\ufffe</span></code> character).</p>
747
 
<p>After completion, <em>*byteorder</em> is set to the current byte order at the end
748
 
of input data.</p>
749
 
<p>If <em>byteorder</em> is <em>NULL</em>, the codec starts in native order mode.</p>
750
 
<p>Return <em>NULL</em> if an exception was raised by the codec.</p>
751
 
<div class="versionchanged">
752
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
753
 
changes in your code for properly supporting 64-bit systems.</p>
754
 
</div>
755
 
</dd></dl>
756
 
 
757
 
<dl class="function">
758
 
<dt id="c.PyUnicode_DecodeUTF16Stateful">
759
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_DecodeUTF16Stateful</code><span class="sig-paren">(</span>const char<em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em>, int<em>&nbsp;*byteorder</em>, Py_ssize_t<em>&nbsp;*consumed</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_DecodeUTF16Stateful" title="Permalink to this definition">¶</a></dt>
760
 
<dd><em class="refcount">Return value: New reference.</em><p>If <em>consumed</em> is <em>NULL</em>, behave like <a class="reference internal" href="#c.PyUnicode_DecodeUTF16" title="PyUnicode_DecodeUTF16"><code class="xref c c-func docutils literal"><span class="pre">PyUnicode_DecodeUTF16()</span></code></a>. If
761
 
<em>consumed</em> is not <em>NULL</em>, <a class="reference internal" href="#c.PyUnicode_DecodeUTF16Stateful" title="PyUnicode_DecodeUTF16Stateful"><code class="xref c c-func docutils literal"><span class="pre">PyUnicode_DecodeUTF16Stateful()</span></code></a> will not treat
762
 
trailing incomplete UTF-16 byte sequences (such as an odd number of bytes or a
763
 
split surrogate pair) as an error. Those bytes will not be decoded and the
764
 
number of bytes that have been decoded will be stored in <em>consumed</em>.</p>
765
 
<div class="versionadded">
766
 
<p><span class="versionmodified">New in version 2.4.</span></p>
767
 
</div>
768
 
<div class="versionchanged">
769
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em> and an <code class="xref c c-type docutils literal"><span class="pre">int</span> <span class="pre">*</span></code>
770
 
type for <em>consumed</em>. This might require changes in your code for
771
 
properly supporting 64-bit systems.</p>
772
 
</div>
773
 
</dd></dl>
774
 
 
775
 
<dl class="function">
776
 
<dt id="c.PyUnicode_EncodeUTF16">
777
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_EncodeUTF16</code><span class="sig-paren">(</span>const <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em>, int<em>&nbsp;byteorder</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_EncodeUTF16" title="Permalink to this definition">¶</a></dt>
778
 
<dd><em class="refcount">Return value: New reference.</em><p>Return a Python string object holding the UTF-16 encoded value of the Unicode
779
 
data in <em>s</em>.  Output is written according to the following byte order:</p>
780
 
<div class="highlight-c"><div class="highlight"><pre><span class="n">byteorder</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="o">:</span> <span class="n">little</span> <span class="n">endian</span>
781
 
<span class="n">byteorder</span> <span class="o">==</span> <span class="mi">0</span><span class="o">:</span>  <span class="n">native</span> <span class="n">byte</span> <span class="n">order</span> <span class="p">(</span><span class="n">writes</span> <span class="n">a</span> <span class="n">BOM</span> <span class="n">mark</span><span class="p">)</span>
782
 
<span class="n">byteorder</span> <span class="o">==</span> <span class="mi">1</span><span class="o">:</span>  <span class="n">big</span> <span class="n">endian</span>
783
 
</pre></div>
784
 
</div>
785
 
<p>If byteorder is <code class="docutils literal"><span class="pre">0</span></code>, the output string will always start with the Unicode BOM
786
 
mark (U+FEFF). In the other two modes, no BOM mark is prepended.</p>
787
 
<p>If <em>Py_UNICODE_WIDE</em> is defined, a single <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></code></a> value may get
788
 
represented as a surrogate pair. If it is not defined, each <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></code></a>
789
 
values is interpreted as an UCS-2 character.</p>
790
 
<p>Return <em>NULL</em> if an exception was raised by the codec.</p>
791
 
<div class="versionchanged">
792
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
793
 
changes in your code for properly supporting 64-bit systems.</p>
794
 
</div>
795
 
</dd></dl>
796
 
 
797
 
<dl class="function">
798
 
<dt id="c.PyUnicode_AsUTF16String">
799
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_AsUTF16String</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*unicode</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_AsUTF16String" title="Permalink to this definition">¶</a></dt>
800
 
<dd><em class="refcount">Return value: New reference.</em><p>Return a Python string using the UTF-16 encoding in native byte order. The
801
 
string always starts with a BOM mark.  Error handling is &#8220;strict&#8221;.  Return
802
 
<em>NULL</em> if an exception was raised by the codec.</p>
803
 
</dd></dl>
804
 
 
805
 
</div>
806
 
<div class="section" id="utf-7-codecs">
807
 
<h3>UTF-7 Codecs<a class="headerlink" href="#utf-7-codecs" title="Permalink to this headline">¶</a></h3>
808
 
<p>These are the UTF-7 codec APIs:</p>
809
 
<dl class="function">
810
 
<dt id="c.PyUnicode_DecodeUTF7">
811
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_DecodeUTF7</code><span class="sig-paren">(</span>const char<em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_DecodeUTF7" title="Permalink to this definition">¶</a></dt>
812
 
<dd><p>Create a Unicode object by decoding <em>size</em> bytes of the UTF-7 encoded string
813
 
<em>s</em>.  Return <em>NULL</em> if an exception was raised by the codec.</p>
814
 
</dd></dl>
815
 
 
816
 
<dl class="function">
817
 
<dt id="c.PyUnicode_DecodeUTF7Stateful">
818
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_DecodeUTF7Stateful</code><span class="sig-paren">(</span>const char<em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em>, Py_ssize_t<em>&nbsp;*consumed</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_DecodeUTF7Stateful" title="Permalink to this definition">¶</a></dt>
819
 
<dd><p>If <em>consumed</em> is <em>NULL</em>, behave like <a class="reference internal" href="#c.PyUnicode_DecodeUTF7" title="PyUnicode_DecodeUTF7"><code class="xref c c-func docutils literal"><span class="pre">PyUnicode_DecodeUTF7()</span></code></a>.  If
820
 
<em>consumed</em> is not <em>NULL</em>, trailing incomplete UTF-7 base-64 sections will not
821
 
be treated as an error.  Those bytes will not be decoded and the number of
822
 
bytes that have been decoded will be stored in <em>consumed</em>.</p>
823
 
</dd></dl>
824
 
 
825
 
<dl class="function">
826
 
<dt id="c.PyUnicode_EncodeUTF7">
827
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_EncodeUTF7</code><span class="sig-paren">(</span>const <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, int<em>&nbsp;base64SetO</em>, int<em>&nbsp;base64WhiteSpace</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_EncodeUTF7" title="Permalink to this definition">¶</a></dt>
828
 
<dd><p>Encode the <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></code></a> buffer of the given size using UTF-7 and
829
 
return a Python bytes object.  Return <em>NULL</em> if an exception was raised by
830
 
the codec.</p>
831
 
<p>If <em>base64SetO</em> is nonzero, &#8220;Set O&#8221; (punctuation that has no otherwise
832
 
special meaning) will be encoded in base-64.  If <em>base64WhiteSpace</em> is
833
 
nonzero, whitespace will be encoded in base-64.  Both are set to zero for the
834
 
Python &#8220;utf-7&#8221; codec.</p>
835
 
</dd></dl>
836
 
 
837
 
</div>
838
 
<div class="section" id="unicode-escape-codecs">
839
 
<h3>Unicode-Escape Codecs<a class="headerlink" href="#unicode-escape-codecs" title="Permalink to this headline">¶</a></h3>
840
 
<p>These are the &#8220;Unicode Escape&#8221; codec APIs:</p>
841
 
<dl class="function">
842
 
<dt id="c.PyUnicode_DecodeUnicodeEscape">
843
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_DecodeUnicodeEscape</code><span class="sig-paren">(</span>const char<em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_DecodeUnicodeEscape" title="Permalink to this definition">¶</a></dt>
844
 
<dd><em class="refcount">Return value: New reference.</em><p>Create a Unicode object by decoding <em>size</em> bytes of the Unicode-Escape encoded
845
 
string <em>s</em>.  Return <em>NULL</em> if an exception was raised by the codec.</p>
846
 
<div class="versionchanged">
847
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
848
 
changes in your code for properly supporting 64-bit systems.</p>
849
 
</div>
850
 
</dd></dl>
851
 
 
852
 
<dl class="function">
853
 
<dt id="c.PyUnicode_EncodeUnicodeEscape">
854
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_EncodeUnicodeEscape</code><span class="sig-paren">(</span>const <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_EncodeUnicodeEscape" title="Permalink to this definition">¶</a></dt>
855
 
<dd><em class="refcount">Return value: New reference.</em><p>Encode the <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></code></a> buffer of the given <em>size</em> using Unicode-Escape and
856
 
return a Python string object.  Return <em>NULL</em> if an exception was raised by the
857
 
codec.</p>
858
 
<div class="versionchanged">
859
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
860
 
changes in your code for properly supporting 64-bit systems.</p>
861
 
</div>
862
 
</dd></dl>
863
 
 
864
 
<dl class="function">
865
 
<dt id="c.PyUnicode_AsUnicodeEscapeString">
866
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_AsUnicodeEscapeString</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*unicode</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_AsUnicodeEscapeString" title="Permalink to this definition">¶</a></dt>
867
 
<dd><em class="refcount">Return value: New reference.</em><p>Encode a Unicode object using Unicode-Escape and return the result as Python
868
 
string object.  Error handling is &#8220;strict&#8221;. Return <em>NULL</em> if an exception was
869
 
raised by the codec.</p>
870
 
</dd></dl>
871
 
 
872
 
</div>
873
 
<div class="section" id="raw-unicode-escape-codecs">
874
 
<h3>Raw-Unicode-Escape Codecs<a class="headerlink" href="#raw-unicode-escape-codecs" title="Permalink to this headline">¶</a></h3>
875
 
<p>These are the &#8220;Raw Unicode Escape&#8221; codec APIs:</p>
876
 
<dl class="function">
877
 
<dt id="c.PyUnicode_DecodeRawUnicodeEscape">
878
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_DecodeRawUnicodeEscape</code><span class="sig-paren">(</span>const char<em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_DecodeRawUnicodeEscape" title="Permalink to this definition">¶</a></dt>
879
 
<dd><em class="refcount">Return value: New reference.</em><p>Create a Unicode object by decoding <em>size</em> bytes of the Raw-Unicode-Escape
880
 
encoded string <em>s</em>.  Return <em>NULL</em> if an exception was raised by the codec.</p>
881
 
<div class="versionchanged">
882
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
883
 
changes in your code for properly supporting 64-bit systems.</p>
884
 
</div>
885
 
</dd></dl>
886
 
 
887
 
<dl class="function">
888
 
<dt id="c.PyUnicode_EncodeRawUnicodeEscape">
889
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_EncodeRawUnicodeEscape</code><span class="sig-paren">(</span>const <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_EncodeRawUnicodeEscape" title="Permalink to this definition">¶</a></dt>
890
 
<dd><em class="refcount">Return value: New reference.</em><p>Encode the <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></code></a> buffer of the given <em>size</em> using Raw-Unicode-Escape
891
 
and return a Python string object.  Return <em>NULL</em> if an exception was raised by
892
 
the codec.</p>
893
 
<div class="versionchanged">
894
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
895
 
changes in your code for properly supporting 64-bit systems.</p>
896
 
</div>
897
 
</dd></dl>
898
 
 
899
 
<dl class="function">
900
 
<dt id="c.PyUnicode_AsRawUnicodeEscapeString">
901
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_AsRawUnicodeEscapeString</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*unicode</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_AsRawUnicodeEscapeString" title="Permalink to this definition">¶</a></dt>
902
 
<dd><em class="refcount">Return value: New reference.</em><p>Encode a Unicode object using Raw-Unicode-Escape and return the result as
903
 
Python string object. Error handling is &#8220;strict&#8221;. Return <em>NULL</em> if an exception
904
 
was raised by the codec.</p>
905
 
</dd></dl>
906
 
 
907
 
</div>
908
 
<div class="section" id="latin-1-codecs">
909
 
<h3>Latin-1 Codecs<a class="headerlink" href="#latin-1-codecs" title="Permalink to this headline">¶</a></h3>
910
 
<p>These are the Latin-1 codec APIs: Latin-1 corresponds to the first 256 Unicode
911
 
ordinals and only these are accepted by the codecs during encoding.</p>
912
 
<dl class="function">
913
 
<dt id="c.PyUnicode_DecodeLatin1">
914
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_DecodeLatin1</code><span class="sig-paren">(</span>const char<em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_DecodeLatin1" title="Permalink to this definition">¶</a></dt>
915
 
<dd><em class="refcount">Return value: New reference.</em><p>Create a Unicode object by decoding <em>size</em> bytes of the Latin-1 encoded string
916
 
<em>s</em>.  Return <em>NULL</em> if an exception was raised by the codec.</p>
917
 
<div class="versionchanged">
918
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
919
 
changes in your code for properly supporting 64-bit systems.</p>
920
 
</div>
921
 
</dd></dl>
922
 
 
923
 
<dl class="function">
924
 
<dt id="c.PyUnicode_EncodeLatin1">
925
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_EncodeLatin1</code><span class="sig-paren">(</span>const <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_EncodeLatin1" title="Permalink to this definition">¶</a></dt>
926
 
<dd><em class="refcount">Return value: New reference.</em><p>Encode the <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></code></a> buffer of the given <em>size</em> using Latin-1 and return
927
 
a Python string object.  Return <em>NULL</em> if an exception was raised by the codec.</p>
928
 
<div class="versionchanged">
929
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
930
 
changes in your code for properly supporting 64-bit systems.</p>
931
 
</div>
932
 
</dd></dl>
933
 
 
934
 
<dl class="function">
935
 
<dt id="c.PyUnicode_AsLatin1String">
936
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_AsLatin1String</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*unicode</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_AsLatin1String" title="Permalink to this definition">¶</a></dt>
937
 
<dd><em class="refcount">Return value: New reference.</em><p>Encode a Unicode object using Latin-1 and return the result as Python string
938
 
object.  Error handling is &#8220;strict&#8221;.  Return <em>NULL</em> if an exception was raised
939
 
by the codec.</p>
940
 
</dd></dl>
941
 
 
942
 
</div>
943
 
<div class="section" id="ascii-codecs">
944
 
<h3>ASCII Codecs<a class="headerlink" href="#ascii-codecs" title="Permalink to this headline">¶</a></h3>
945
 
<p>These are the ASCII codec APIs.  Only 7-bit ASCII data is accepted. All other
946
 
codes generate errors.</p>
947
 
<dl class="function">
948
 
<dt id="c.PyUnicode_DecodeASCII">
949
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_DecodeASCII</code><span class="sig-paren">(</span>const char<em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_DecodeASCII" title="Permalink to this definition">¶</a></dt>
950
 
<dd><em class="refcount">Return value: New reference.</em><p>Create a Unicode object by decoding <em>size</em> bytes of the ASCII encoded string
951
 
<em>s</em>.  Return <em>NULL</em> if an exception was raised by the codec.</p>
952
 
<div class="versionchanged">
953
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
954
 
changes in your code for properly supporting 64-bit systems.</p>
955
 
</div>
956
 
</dd></dl>
957
 
 
958
 
<dl class="function">
959
 
<dt id="c.PyUnicode_EncodeASCII">
960
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_EncodeASCII</code><span class="sig-paren">(</span>const <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_EncodeASCII" title="Permalink to this definition">¶</a></dt>
961
 
<dd><em class="refcount">Return value: New reference.</em><p>Encode the <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></code></a> buffer of the given <em>size</em> using ASCII and return a
962
 
Python string object.  Return <em>NULL</em> if an exception was raised by the codec.</p>
963
 
<div class="versionchanged">
964
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
965
 
changes in your code for properly supporting 64-bit systems.</p>
966
 
</div>
967
 
</dd></dl>
968
 
 
969
 
<dl class="function">
970
 
<dt id="c.PyUnicode_AsASCIIString">
971
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_AsASCIIString</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*unicode</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_AsASCIIString" title="Permalink to this definition">¶</a></dt>
972
 
<dd><em class="refcount">Return value: New reference.</em><p>Encode a Unicode object using ASCII and return the result as Python string
973
 
object.  Error handling is &#8220;strict&#8221;.  Return <em>NULL</em> if an exception was raised
974
 
by the codec.</p>
975
 
</dd></dl>
976
 
 
977
 
</div>
978
 
<div class="section" id="character-map-codecs">
979
 
<h3>Character Map Codecs<a class="headerlink" href="#character-map-codecs" title="Permalink to this headline">¶</a></h3>
980
 
<p>This codec is special in that it can be used to implement many different codecs
981
 
(and this is in fact what was done to obtain most of the standard codecs
982
 
included in the <code class="xref py py-mod docutils literal"><span class="pre">encodings</span></code> package). The codec uses mapping to encode and
983
 
decode characters.</p>
984
 
<p>Decoding mappings must map single string characters to single Unicode
985
 
characters, integers (which are then interpreted as Unicode ordinals) or None
986
 
(meaning &#8220;undefined mapping&#8221; and causing an error).</p>
987
 
<p>Encoding mappings must map single Unicode characters to single string
988
 
characters, integers (which are then interpreted as Latin-1 ordinals) or None
989
 
(meaning &#8220;undefined mapping&#8221; and causing an error).</p>
990
 
<p>The mapping objects provided must only support the __getitem__ mapping
991
 
interface.</p>
992
 
<p>If a character lookup fails with a LookupError, the character is copied as-is
993
 
meaning that its ordinal value will be interpreted as Unicode or Latin-1 ordinal
994
 
resp. Because of this, mappings only need to contain those mappings which map
995
 
characters to different code points.</p>
996
 
<p>These are the mapping codec APIs:</p>
997
 
<dl class="function">
998
 
<dt id="c.PyUnicode_DecodeCharmap">
999
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_DecodeCharmap</code><span class="sig-paren">(</span>const char<em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*mapping</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_DecodeCharmap" title="Permalink to this definition">¶</a></dt>
1000
 
<dd><em class="refcount">Return value: New reference.</em><p>Create a Unicode object by decoding <em>size</em> bytes of the encoded string <em>s</em> using
1001
 
the given <em>mapping</em> object.  Return <em>NULL</em> if an exception was raised by the
1002
 
codec. If <em>mapping</em> is <em>NULL</em> latin-1 decoding will be done. Else it can be a
1003
 
dictionary mapping byte or a unicode string, which is treated as a lookup table.
1004
 
Byte values greater that the length of the string and U+FFFE &#8220;characters&#8221; are
1005
 
treated as &#8220;undefined mapping&#8221;.</p>
1006
 
<div class="versionchanged">
1007
 
<p><span class="versionmodified">Changed in version 2.4: </span>Allowed unicode string as mapping argument.</p>
1008
 
</div>
1009
 
<div class="versionchanged">
1010
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
1011
 
changes in your code for properly supporting 64-bit systems.</p>
1012
 
</div>
1013
 
</dd></dl>
1014
 
 
1015
 
<dl class="function">
1016
 
<dt id="c.PyUnicode_EncodeCharmap">
1017
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_EncodeCharmap</code><span class="sig-paren">(</span>const <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*mapping</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_EncodeCharmap" title="Permalink to this definition">¶</a></dt>
1018
 
<dd><em class="refcount">Return value: New reference.</em><p>Encode the <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></code></a> buffer of the given <em>size</em> using the given
1019
 
<em>mapping</em> object and return a Python string object. Return <em>NULL</em> if an
1020
 
exception was raised by the codec.</p>
1021
 
<div class="versionchanged">
1022
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
1023
 
changes in your code for properly supporting 64-bit systems.</p>
1024
 
</div>
1025
 
</dd></dl>
1026
 
 
1027
 
<dl class="function">
1028
 
<dt id="c.PyUnicode_AsCharmapString">
1029
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_AsCharmapString</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*unicode</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*mapping</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_AsCharmapString" title="Permalink to this definition">¶</a></dt>
1030
 
<dd><em class="refcount">Return value: New reference.</em><p>Encode a Unicode object using the given <em>mapping</em> object and return the result
1031
 
as Python string object.  Error handling is &#8220;strict&#8221;.  Return <em>NULL</em> if an
1032
 
exception was raised by the codec.</p>
1033
 
</dd></dl>
1034
 
 
1035
 
<p>The following codec API is special in that maps Unicode to Unicode.</p>
1036
 
<dl class="function">
1037
 
<dt id="c.PyUnicode_TranslateCharmap">
1038
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_TranslateCharmap</code><span class="sig-paren">(</span>const <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*table</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_TranslateCharmap" title="Permalink to this definition">¶</a></dt>
1039
 
<dd><em class="refcount">Return value: New reference.</em><p>Translate a <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></code></a> buffer of the given <em>size</em> by applying a
1040
 
character mapping <em>table</em> to it and return the resulting Unicode object.  Return
1041
 
<em>NULL</em> when an exception was raised by the codec.</p>
1042
 
<p>The <em>mapping</em> table must map Unicode ordinal integers to Unicode ordinal
1043
 
integers or None (causing deletion of the character).</p>
1044
 
<p>Mapping tables need only provide the <a class="reference internal" href="../reference/datamodel.html#object.__getitem__" title="object.__getitem__"><code class="xref py py-meth docutils literal"><span class="pre">__getitem__()</span></code></a> interface; dictionaries
1045
 
and sequences work well.  Unmapped character ordinals (ones which cause a
1046
 
<a class="reference internal" href="../library/exceptions.html#exceptions.LookupError" title="exceptions.LookupError"><code class="xref py py-exc docutils literal"><span class="pre">LookupError</span></code></a>) are left untouched and are copied as-is.</p>
1047
 
<div class="versionchanged">
1048
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
1049
 
changes in your code for properly supporting 64-bit systems.</p>
1050
 
</div>
1051
 
</dd></dl>
1052
 
 
1053
 
</div>
1054
 
<div class="section" id="mbcs-codecs-for-windows">
1055
 
<h3>MBCS codecs for Windows<a class="headerlink" href="#mbcs-codecs-for-windows" title="Permalink to this headline">¶</a></h3>
1056
 
<p>These are the MBCS codec APIs. They are currently only available on Windows and
1057
 
use the Win32 MBCS converters to implement the conversions.  Note that MBCS (or
1058
 
DBCS) is a class of encodings, not just one.  The target encoding is defined by
1059
 
the user settings on the machine running the codec.</p>
1060
 
<dl class="function">
1061
 
<dt id="c.PyUnicode_DecodeMBCS">
1062
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_DecodeMBCS</code><span class="sig-paren">(</span>const char<em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_DecodeMBCS" title="Permalink to this definition">¶</a></dt>
1063
 
<dd><em class="refcount">Return value: New reference.</em><p>Create a Unicode object by decoding <em>size</em> bytes of the MBCS encoded string <em>s</em>.
1064
 
Return <em>NULL</em> if an exception was raised by the codec.</p>
1065
 
<div class="versionchanged">
1066
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
1067
 
changes in your code for properly supporting 64-bit systems.</p>
1068
 
</div>
1069
 
</dd></dl>
1070
 
 
1071
 
<dl class="function">
1072
 
<dt id="c.PyUnicode_DecodeMBCSStateful">
1073
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_DecodeMBCSStateful</code><span class="sig-paren">(</span>const char<em>&nbsp;*s</em>, int<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em>, int<em>&nbsp;*consumed</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_DecodeMBCSStateful" title="Permalink to this definition">¶</a></dt>
1074
 
<dd><p>If <em>consumed</em> is <em>NULL</em>, behave like <a class="reference internal" href="#c.PyUnicode_DecodeMBCS" title="PyUnicode_DecodeMBCS"><code class="xref c c-func docutils literal"><span class="pre">PyUnicode_DecodeMBCS()</span></code></a>. If
1075
 
<em>consumed</em> is not <em>NULL</em>, <a class="reference internal" href="#c.PyUnicode_DecodeMBCSStateful" title="PyUnicode_DecodeMBCSStateful"><code class="xref c c-func docutils literal"><span class="pre">PyUnicode_DecodeMBCSStateful()</span></code></a> will not decode
1076
 
trailing lead byte and the number of bytes that have been decoded will be stored
1077
 
in <em>consumed</em>.</p>
1078
 
<div class="versionadded">
1079
 
<p><span class="versionmodified">New in version 2.5.</span></p>
1080
 
</div>
1081
 
</dd></dl>
1082
 
 
1083
 
<dl class="function">
1084
 
<dt id="c.PyUnicode_EncodeMBCS">
1085
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_EncodeMBCS</code><span class="sig-paren">(</span>const <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;*s</em>, Py_ssize_t<em>&nbsp;size</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_EncodeMBCS" title="Permalink to this definition">¶</a></dt>
1086
 
<dd><em class="refcount">Return value: New reference.</em><p>Encode the <a class="reference internal" href="#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></code></a> buffer of the given <em>size</em> using MBCS and return a
1087
 
Python string object.  Return <em>NULL</em> if an exception was raised by the codec.</p>
1088
 
<div class="versionchanged">
1089
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>size</em>. This might require
1090
 
changes in your code for properly supporting 64-bit systems.</p>
1091
 
</div>
1092
 
</dd></dl>
1093
 
 
1094
 
<dl class="function">
1095
 
<dt id="c.PyUnicode_AsMBCSString">
1096
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_AsMBCSString</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*unicode</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_AsMBCSString" title="Permalink to this definition">¶</a></dt>
1097
 
<dd><em class="refcount">Return value: New reference.</em><p>Encode a Unicode object using MBCS and return the result as Python string
1098
 
object.  Error handling is &#8220;strict&#8221;.  Return <em>NULL</em> if an exception was raised
1099
 
by the codec.</p>
1100
 
</dd></dl>
1101
 
 
1102
 
</div>
1103
 
<div class="section" id="methods-slots">
1104
 
<h3>Methods &amp; Slots<a class="headerlink" href="#methods-slots" title="Permalink to this headline">¶</a></h3>
1105
 
</div>
1106
 
</div>
1107
 
<div class="section" id="methods-and-slot-functions">
1108
 
<span id="unicodemethodsandslots"></span><h2>Methods and Slot Functions<a class="headerlink" href="#methods-and-slot-functions" title="Permalink to this headline">¶</a></h2>
1109
 
<p>The following APIs are capable of handling Unicode objects and strings on input
1110
 
(we refer to them as strings in the descriptions) and return Unicode objects or
1111
 
integers as appropriate.</p>
1112
 
<p>They all return <em>NULL</em> or <code class="docutils literal"><span class="pre">-1</span></code> if an exception occurs.</p>
1113
 
<dl class="function">
1114
 
<dt id="c.PyUnicode_Concat">
1115
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_Concat</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*left</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*right</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_Concat" title="Permalink to this definition">¶</a></dt>
1116
 
<dd><em class="refcount">Return value: New reference.</em><p>Concat two strings giving a new Unicode string.</p>
1117
 
</dd></dl>
1118
 
 
1119
 
<dl class="function">
1120
 
<dt id="c.PyUnicode_Split">
1121
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_Split</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*s</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*sep</em>, Py_ssize_t<em>&nbsp;maxsplit</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_Split" title="Permalink to this definition">¶</a></dt>
1122
 
<dd><em class="refcount">Return value: New reference.</em><p>Split a string giving a list of Unicode strings.  If <em>sep</em> is <em>NULL</em>, splitting
1123
 
will be done at all whitespace substrings.  Otherwise, splits occur at the given
1124
 
separator.  At most <em>maxsplit</em> splits will be done.  If negative, no limit is
1125
 
set.  Separators are not included in the resulting list.</p>
1126
 
<div class="versionchanged">
1127
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>maxsplit</em>. This might require
1128
 
changes in your code for properly supporting 64-bit systems.</p>
1129
 
</div>
1130
 
</dd></dl>
1131
 
 
1132
 
<dl class="function">
1133
 
<dt id="c.PyUnicode_Splitlines">
1134
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_Splitlines</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*s</em>, int<em>&nbsp;keepend</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_Splitlines" title="Permalink to this definition">¶</a></dt>
1135
 
<dd><em class="refcount">Return value: New reference.</em><p>Split a Unicode string at line breaks, returning a list of Unicode strings.
1136
 
CRLF is considered to be one line break.  If <em>keepend</em> is 0, the Line break
1137
 
characters are not included in the resulting strings.</p>
1138
 
</dd></dl>
1139
 
 
1140
 
<dl class="function">
1141
 
<dt id="c.PyUnicode_Translate">
1142
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_Translate</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*str</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*table</em>, const char<em>&nbsp;*errors</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_Translate" title="Permalink to this definition">¶</a></dt>
1143
 
<dd><em class="refcount">Return value: New reference.</em><p>Translate a string by applying a character mapping table to it and return the
1144
 
resulting Unicode object.</p>
1145
 
<p>The mapping table must map Unicode ordinal integers to Unicode ordinal integers
1146
 
or None (causing deletion of the character).</p>
1147
 
<p>Mapping tables need only provide the <a class="reference internal" href="../reference/datamodel.html#object.__getitem__" title="object.__getitem__"><code class="xref py py-meth docutils literal"><span class="pre">__getitem__()</span></code></a> interface; dictionaries
1148
 
and sequences work well.  Unmapped character ordinals (ones which cause a
1149
 
<a class="reference internal" href="../library/exceptions.html#exceptions.LookupError" title="exceptions.LookupError"><code class="xref py py-exc docutils literal"><span class="pre">LookupError</span></code></a>) are left untouched and are copied as-is.</p>
1150
 
<p><em>errors</em> has the usual meaning for codecs. It may be <em>NULL</em> which indicates to
1151
 
use the default error handling.</p>
1152
 
</dd></dl>
1153
 
 
1154
 
<dl class="function">
1155
 
<dt id="c.PyUnicode_Join">
1156
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_Join</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*separator</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*seq</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_Join" title="Permalink to this definition">¶</a></dt>
1157
 
<dd><em class="refcount">Return value: New reference.</em><p>Join a sequence of strings using the given <em>separator</em> and return the resulting
1158
 
Unicode string.</p>
1159
 
</dd></dl>
1160
 
 
1161
 
<dl class="function">
1162
 
<dt id="c.PyUnicode_Tailmatch">
1163
 
Py_ssize_t <code class="descname">PyUnicode_Tailmatch</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*str</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*substr</em>, Py_ssize_t<em>&nbsp;start</em>, Py_ssize_t<em>&nbsp;end</em>, int<em>&nbsp;direction</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_Tailmatch" title="Permalink to this definition">¶</a></dt>
1164
 
<dd><p>Return 1 if <em>substr</em> matches <code class="docutils literal"><span class="pre">str[start:end]</span></code> at the given tail end
1165
 
(<em>direction</em> == -1 means to do a prefix match, <em>direction</em> == 1 a suffix match),
1166
 
0 otherwise. Return <code class="docutils literal"><span class="pre">-1</span></code> if an error occurred.</p>
1167
 
<div class="versionchanged">
1168
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>start</em> and <em>end</em>. This
1169
 
might require changes in your code for properly supporting 64-bit
1170
 
systems.</p>
1171
 
</div>
1172
 
</dd></dl>
1173
 
 
1174
 
<dl class="function">
1175
 
<dt id="c.PyUnicode_Find">
1176
 
Py_ssize_t <code class="descname">PyUnicode_Find</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*str</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*substr</em>, Py_ssize_t<em>&nbsp;start</em>, Py_ssize_t<em>&nbsp;end</em>, int<em>&nbsp;direction</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_Find" title="Permalink to this definition">¶</a></dt>
1177
 
<dd><p>Return the first position of <em>substr</em> in <code class="docutils literal"><span class="pre">str[start:end]</span></code> using the given
1178
 
<em>direction</em> (<em>direction</em> == 1 means to do a forward search, <em>direction</em> == -1 a
1179
 
backward search).  The return value is the index of the first match; a value of
1180
 
<code class="docutils literal"><span class="pre">-1</span></code> indicates that no match was found, and <code class="docutils literal"><span class="pre">-2</span></code> indicates that an error
1181
 
occurred and an exception has been set.</p>
1182
 
<div class="versionchanged">
1183
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>start</em> and <em>end</em>. This
1184
 
might require changes in your code for properly supporting 64-bit
1185
 
systems.</p>
1186
 
</div>
1187
 
</dd></dl>
1188
 
 
1189
 
<dl class="function">
1190
 
<dt id="c.PyUnicode_Count">
1191
 
Py_ssize_t <code class="descname">PyUnicode_Count</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*str</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*substr</em>, Py_ssize_t<em>&nbsp;start</em>, Py_ssize_t<em>&nbsp;end</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_Count" title="Permalink to this definition">¶</a></dt>
1192
 
<dd><p>Return the number of non-overlapping occurrences of <em>substr</em> in
1193
 
<code class="docutils literal"><span class="pre">str[start:end]</span></code>.  Return <code class="docutils literal"><span class="pre">-1</span></code> if an error occurred.</p>
1194
 
<div class="versionchanged">
1195
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function returned an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type and used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code>
1196
 
type for <em>start</em> and <em>end</em>. This might require changes in your code for
1197
 
properly supporting 64-bit systems.</p>
1198
 
</div>
1199
 
</dd></dl>
1200
 
 
1201
 
<dl class="function">
1202
 
<dt id="c.PyUnicode_Replace">
1203
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_Replace</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*str</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*substr</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*replstr</em>, Py_ssize_t<em>&nbsp;maxcount</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_Replace" title="Permalink to this definition">¶</a></dt>
1204
 
<dd><em class="refcount">Return value: New reference.</em><p>Replace at most <em>maxcount</em> occurrences of <em>substr</em> in <em>str</em> with <em>replstr</em> and
1205
 
return the resulting Unicode object. <em>maxcount</em> == -1 means replace all
1206
 
occurrences.</p>
1207
 
<div class="versionchanged">
1208
 
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> type for <em>maxcount</em>. This might
1209
 
require changes in your code for properly supporting 64-bit systems.</p>
1210
 
</div>
1211
 
</dd></dl>
1212
 
 
1213
 
<dl class="function">
1214
 
<dt id="c.PyUnicode_Compare">
1215
 
int <code class="descname">PyUnicode_Compare</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*left</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*right</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_Compare" title="Permalink to this definition">¶</a></dt>
1216
 
<dd><p>Compare two strings and return -1, 0, 1 for less than, equal, and greater than,
1217
 
respectively.</p>
1218
 
</dd></dl>
1219
 
 
1220
 
<dl class="function">
1221
 
<dt id="c.PyUnicode_RichCompare">
1222
 
int <code class="descname">PyUnicode_RichCompare</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*left</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*right</em>, int<em>&nbsp;op</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_RichCompare" title="Permalink to this definition">¶</a></dt>
1223
 
<dd><p>Rich compare two unicode strings and return one of the following:</p>
1224
 
<ul class="simple">
1225
 
<li><code class="docutils literal"><span class="pre">NULL</span></code> in case an exception was raised</li>
1226
 
<li><code class="xref py py-const docutils literal"><span class="pre">Py_True</span></code> or <code class="xref py py-const docutils literal"><span class="pre">Py_False</span></code> for successful comparisons</li>
1227
 
<li><code class="xref py py-const docutils literal"><span class="pre">Py_NotImplemented</span></code> in case the type combination is unknown</li>
1228
 
</ul>
1229
 
<p>Note that <code class="xref py py-const docutils literal"><span class="pre">Py_EQ</span></code> and <code class="xref py py-const docutils literal"><span class="pre">Py_NE</span></code> comparisons can cause a
1230
 
<a class="reference internal" href="../library/exceptions.html#exceptions.UnicodeWarning" title="exceptions.UnicodeWarning"><code class="xref py py-exc docutils literal"><span class="pre">UnicodeWarning</span></code></a> in case the conversion of the arguments to Unicode fails
1231
 
with a <a class="reference internal" href="../library/exceptions.html#exceptions.UnicodeDecodeError" title="exceptions.UnicodeDecodeError"><code class="xref py py-exc docutils literal"><span class="pre">UnicodeDecodeError</span></code></a>.</p>
1232
 
<p>Possible values for <em>op</em> are <code class="xref py py-const docutils literal"><span class="pre">Py_GT</span></code>, <code class="xref py py-const docutils literal"><span class="pre">Py_GE</span></code>, <code class="xref py py-const docutils literal"><span class="pre">Py_EQ</span></code>,
1233
 
<code class="xref py py-const docutils literal"><span class="pre">Py_NE</span></code>, <code class="xref py py-const docutils literal"><span class="pre">Py_LT</span></code>, and <code class="xref py py-const docutils literal"><span class="pre">Py_LE</span></code>.</p>
1234
 
</dd></dl>
1235
 
 
1236
 
<dl class="function">
1237
 
<dt id="c.PyUnicode_Format">
1238
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyUnicode_Format</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*format</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*args</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_Format" title="Permalink to this definition">¶</a></dt>
1239
 
<dd><em class="refcount">Return value: New reference.</em><p>Return a new string object from <em>format</em> and <em>args</em>; this is analogous to
1240
 
<code class="docutils literal"><span class="pre">format</span> <span class="pre">%</span> <span class="pre">args</span></code>.</p>
1241
 
</dd></dl>
1242
 
 
1243
 
<dl class="function">
1244
 
<dt id="c.PyUnicode_Contains">
1245
 
int <code class="descname">PyUnicode_Contains</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*container</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*element</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicode_Contains" title="Permalink to this definition">¶</a></dt>
1246
 
<dd><p>Check whether <em>element</em> is contained in <em>container</em> and return true or false
1247
 
accordingly.</p>
1248
 
<p><em>element</em> has to coerce to a one element Unicode string. <code class="docutils literal"><span class="pre">-1</span></code> is returned if
1249
 
there was an error.</p>
1250
 
</dd></dl>
1251
 
 
1252
 
</div>
1253
 
</div>
1254
 
 
1255
 
 
1256
 
          </div>
1257
 
        </div>
1258
 
      </div>
1259
 
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
1260
 
        <div class="sphinxsidebarwrapper">
1261
 
  <h3><a href="../contents.html">Table Of Contents</a></h3>
1262
 
  <ul>
1263
 
<li><a class="reference internal" href="#">Unicode Objects and Codecs</a><ul>
1264
 
<li><a class="reference internal" href="#unicode-objects">Unicode Objects</a><ul>
1265
 
<li><a class="reference internal" href="#unicode-type">Unicode Type</a></li>
1266
 
<li><a class="reference internal" href="#unicode-character-properties">Unicode Character Properties</a></li>
1267
 
<li><a class="reference internal" href="#plain-py-unicode">Plain Py_UNICODE</a></li>
1268
 
<li><a class="reference internal" href="#wchar-t-support">wchar_t Support</a></li>
1269
 
</ul>
1270
 
</li>
1271
 
<li><a class="reference internal" href="#built-in-codecs">Built-in Codecs</a><ul>
1272
 
<li><a class="reference internal" href="#generic-codecs">Generic Codecs</a></li>
1273
 
<li><a class="reference internal" href="#utf-8-codecs">UTF-8 Codecs</a></li>
1274
 
<li><a class="reference internal" href="#utf-32-codecs">UTF-32 Codecs</a></li>
1275
 
<li><a class="reference internal" href="#utf-16-codecs">UTF-16 Codecs</a></li>
1276
 
<li><a class="reference internal" href="#utf-7-codecs">UTF-7 Codecs</a></li>
1277
 
<li><a class="reference internal" href="#unicode-escape-codecs">Unicode-Escape Codecs</a></li>
1278
 
<li><a class="reference internal" href="#raw-unicode-escape-codecs">Raw-Unicode-Escape Codecs</a></li>
1279
 
<li><a class="reference internal" href="#latin-1-codecs">Latin-1 Codecs</a></li>
1280
 
<li><a class="reference internal" href="#ascii-codecs">ASCII Codecs</a></li>
1281
 
<li><a class="reference internal" href="#character-map-codecs">Character Map Codecs</a></li>
1282
 
<li><a class="reference internal" href="#mbcs-codecs-for-windows">MBCS codecs for Windows</a></li>
1283
 
<li><a class="reference internal" href="#methods-slots">Methods &amp; Slots</a></li>
1284
 
</ul>
1285
 
</li>
1286
 
<li><a class="reference internal" href="#methods-and-slot-functions">Methods and Slot Functions</a></li>
1287
 
</ul>
1288
 
</li>
1289
 
</ul>
1290
 
 
1291
 
  <h4>Previous topic</h4>
1292
 
  <p class="topless"><a href="string.html"
1293
 
                        title="previous chapter">String/Bytes Objects</a></p>
1294
 
  <h4>Next topic</h4>
1295
 
  <p class="topless"><a href="buffer.html"
1296
 
                        title="next chapter">Buffers and Memoryview Objects</a></p>
1297
 
<h3>This Page</h3>
1298
 
<ul class="this-page-menu">
1299
 
  <li><a href="../bugs.html">Report a Bug</a></li>
1300
 
  <li><a href="../_sources/c-api/unicode.txt"
1301
 
         rel="nofollow">Show Source</a></li>
1302
 
</ul>
1303
 
 
1304
 
<div id="searchbox" style="display: none" role="search">
1305
 
  <h3>Quick search</h3>
1306
 
    <form class="search" action="../search.html" method="get">
1307
 
      <input type="text" name="q" />
1308
 
      <input type="submit" value="Go" />
1309
 
      <input type="hidden" name="check_keywords" value="yes" />
1310
 
      <input type="hidden" name="area" value="default" />
1311
 
    </form>
1312
 
    <p class="searchtip" style="font-size: 90%">
1313
 
    Enter search terms or a module, class or function name.
1314
 
    </p>
1315
 
</div>
1316
 
<script type="text/javascript">$('#searchbox').show(0);</script>
1317
 
        </div>
1318
 
      </div>
1319
 
      <div class="clearer"></div>
1320
 
    </div>  
1321
 
    <div class="related" role="navigation" aria-label="related navigation">
1322
 
      <h3>Navigation</h3>
1323
 
      <ul>
1324
 
        <li class="right" style="margin-right: 10px">
1325
 
          <a href="../genindex.html" title="General Index"
1326
 
             >index</a></li>
1327
 
        <li class="right" >
1328
 
          <a href="../py-modindex.html" title="Python Module Index"
1329
 
             >modules</a> |</li>
1330
 
        <li class="right" >
1331
 
          <a href="buffer.html" title="Buffers and Memoryview Objects"
1332
 
             >next</a> |</li>
1333
 
        <li class="right" >
1334
 
          <a href="string.html" title="String/Bytes Objects"
1335
 
             >previous</a> |</li>
1336
 
        <li><img src="../_static/py.png" alt=""
1337
 
                 style="vertical-align: middle; margin-top: -1px"/></li>
1338
 
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
1339
 
        <li>
1340
 
          <span class="version_switcher_placeholder">2.7.11</span>
1341
 
          <a href="../index.html">Documentation</a> &raquo;
1342
 
        </li>
1343
 
 
1344
 
          <li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> &raquo;</li>
1345
 
          <li class="nav-item nav-item-2"><a href="concrete.html" >Concrete Objects Layer</a> &raquo;</li> 
1346
 
      </ul>
1347
 
    </div>  
1348
 
    <div class="footer">
1349
 
    &copy; <a href="../copyright.html">Copyright</a> 1990-2016, Python Software Foundation.
1350
 
    <br />
1351
 
    The Python Software Foundation is a non-profit corporation.
1352
 
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
1353
 
    <br />
1354
 
    Last updated on Jan 23, 2016.
1355
 
    <a href="../bugs.html">Found a bug</a>?
1356
 
    <br />
1357
 
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
1358
 
    </div>
1359
 
 
1360
 
  </body>
1361
 
</html>
 
 
b'\\ No newline at end of file'