Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
1db7c13b
Commit
1db7c13b
authored
Nov 10, 2011
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port encoders from Py_UNICODE API to unicode object API.
parent
df8077ec
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
249 additions
and
264 deletions
+249
-264
Include/unicodeobject.h
Include/unicodeobject.h
+16
-0
Modules/_codecsmodule.c
Modules/_codecsmodule.c
+46
-76
Objects/unicodeobject.c
Objects/unicodeobject.c
+187
-188
No files found.
Include/unicodeobject.h
View file @
1db7c13b
...
...
@@ -1088,6 +1088,12 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF7(
int
base64WhiteSpace
,
/* Encode whitespace (sp, ht, nl, cr) in base64 */
const
char
*
errors
/* error handling */
);
PyAPI_FUNC
(
PyObject
*
)
_PyUnicode_EncodeUTF7
(
PyObject
*
unicode
,
/* Unicode object */
int
base64SetO
,
/* Encode RFC2152 Set O characters in base64 */
int
base64WhiteSpace
,
/* Encode whitespace (sp, ht, nl, cr) in base64 */
const
char
*
errors
/* error handling */
);
#endif
/* --- UTF-8 Codecs ------------------------------------------------------- */
...
...
@@ -1195,6 +1201,11 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF32(
const
char
*
errors
,
/* error handling */
int
byteorder
/* byteorder to use 0=BOM+native;-1=LE,1=BE */
);
PyAPI_FUNC
(
PyObject
*
)
_PyUnicode_EncodeUTF32
(
PyObject
*
object
,
/* Unicode object */
const
char
*
errors
,
/* error handling */
int
byteorder
/* byteorder to use 0=BOM+native;-1=LE,1=BE */
);
#endif
/* --- UTF-16 Codecs ------------------------------------------------------ */
...
...
@@ -1275,6 +1286,11 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF16(
const
char
*
errors
,
/* error handling */
int
byteorder
/* byteorder to use 0=BOM+native;-1=LE,1=BE */
);
PyAPI_FUNC
(
PyObject
*
)
_PyUnicode_EncodeUTF16
(
PyObject
*
unicode
,
/* Unicode object */
const
char
*
errors
,
/* error handling */
int
byteorder
/* byteorder to use 0=BOM+native;-1=LE,1=BE */
);
#endif
/* --- Unicode-Escape Codecs ---------------------------------------------- */
...
...
Modules/_codecsmodule.c
View file @
1db7c13b
...
...
@@ -235,8 +235,10 @@ unicode_internal_decode(PyObject *self,
return
NULL
;
if
(
PyUnicode_Check
(
obj
))
{
if
(
PyUnicode_READY
(
obj
)
<
0
)
return
NULL
;
Py_INCREF
(
obj
);
return
codec_tuple
(
obj
,
PyUnicode_GET_
SIZE
(
obj
));
return
codec_tuple
(
obj
,
PyUnicode_GET_
LENGTH
(
obj
));
}
else
{
if
(
PyObject_AsReadBuffer
(
obj
,
(
const
void
**
)
&
data
,
&
size
))
...
...
@@ -676,10 +678,12 @@ unicode_internal_encode(PyObject *self,
return
NULL
;
if
(
PyUnicode_Check
(
obj
))
{
if
(
PyUnicode_READY
(
obj
)
<
0
)
return
NULL
;
data
=
PyUnicode_AS_DATA
(
obj
);
size
=
PyUnicode_GET_DATA_SIZE
(
obj
);
return
codec_tuple
(
PyBytes_FromStringAndSize
(
data
,
size
),
PyUnicode_GET_
SIZE
(
obj
));
PyUnicode_GET_
LENGTH
(
obj
));
}
else
{
if
(
PyObject_AsReadBuffer
(
obj
,
(
const
void
**
)
&
data
,
&
size
))
...
...
@@ -700,14 +704,10 @@ utf_7_encode(PyObject *self,
return
NULL
;
str
=
PyUnicode_FromObject
(
str
);
if
(
str
==
NULL
)
return
NULL
;
v
=
codec_tuple
(
PyUnicode_EncodeUTF7
(
PyUnicode_AS_UNICODE
(
str
),
PyUnicode_GET_SIZE
(
str
),
0
,
0
,
errors
),
PyUnicode_GET_SIZE
(
str
));
if
(
str
==
NULL
||
PyUnicode_READY
(
str
)
<
0
)
return
NULL
;
v
=
codec_tuple
(
_PyUnicode_EncodeUTF7
(
str
,
0
,
0
,
errors
),
PyUnicode_GET_LENGTH
(
str
));
Py_DECREF
(
str
);
return
v
;
}
...
...
@@ -752,13 +752,10 @@ utf_16_encode(PyObject *self,
return
NULL
;
str
=
PyUnicode_FromObject
(
str
);
if
(
str
==
NULL
)
if
(
str
==
NULL
||
PyUnicode_READY
(
str
)
<
0
)
return
NULL
;
v
=
codec_tuple
(
PyUnicode_EncodeUTF16
(
PyUnicode_AS_UNICODE
(
str
),
PyUnicode_GET_SIZE
(
str
),
errors
,
byteorder
),
PyUnicode_GET_SIZE
(
str
));
v
=
codec_tuple
(
_PyUnicode_EncodeUTF16
(
str
,
errors
,
byteorder
),
PyUnicode_GET_LENGTH
(
str
));
Py_DECREF
(
str
);
return
v
;
}
...
...
@@ -775,13 +772,10 @@ utf_16_le_encode(PyObject *self,
return
NULL
;
str
=
PyUnicode_FromObject
(
str
);
if
(
str
==
NULL
)
if
(
str
==
NULL
||
PyUnicode_READY
(
str
)
<
0
)
return
NULL
;
v
=
codec_tuple
(
PyUnicode_EncodeUTF16
(
PyUnicode_AS_UNICODE
(
str
),
PyUnicode_GET_SIZE
(
str
),
errors
,
-
1
),
PyUnicode_GET_SIZE
(
str
));
v
=
codec_tuple
(
_PyUnicode_EncodeUTF16
(
str
,
errors
,
-
1
),
PyUnicode_GET_LENGTH
(
str
));
Py_DECREF
(
str
);
return
v
;
}
...
...
@@ -798,13 +792,10 @@ utf_16_be_encode(PyObject *self,
return
NULL
;
str
=
PyUnicode_FromObject
(
str
);
if
(
str
==
NULL
)
if
(
str
==
NULL
||
PyUnicode_READY
(
str
)
<
0
)
return
NULL
;
v
=
codec_tuple
(
PyUnicode_EncodeUTF16
(
PyUnicode_AS_UNICODE
(
str
),
PyUnicode_GET_SIZE
(
str
),
errors
,
+
1
),
PyUnicode_GET_SIZE
(
str
));
v
=
codec_tuple
(
_PyUnicode_EncodeUTF16
(
str
,
errors
,
+
1
),
PyUnicode_GET_LENGTH
(
str
));
Py_DECREF
(
str
);
return
v
;
}
...
...
@@ -829,13 +820,10 @@ utf_32_encode(PyObject *self,
return
NULL
;
str
=
PyUnicode_FromObject
(
str
);
if
(
str
==
NULL
)
if
(
str
==
NULL
||
PyUnicode_READY
(
str
)
<
0
)
return
NULL
;
v
=
codec_tuple
(
PyUnicode_EncodeUTF32
(
PyUnicode_AS_UNICODE
(
str
),
PyUnicode_GET_SIZE
(
str
),
errors
,
byteorder
),
PyUnicode_GET_SIZE
(
str
));
v
=
codec_tuple
(
_PyUnicode_EncodeUTF32
(
str
,
errors
,
byteorder
),
PyUnicode_GET_LENGTH
(
str
));
Py_DECREF
(
str
);
return
v
;
}
...
...
@@ -852,13 +840,10 @@ utf_32_le_encode(PyObject *self,
return
NULL
;
str
=
PyUnicode_FromObject
(
str
);
if
(
str
==
NULL
)
if
(
str
==
NULL
||
PyUnicode_READY
(
str
)
<
0
)
return
NULL
;
v
=
codec_tuple
(
PyUnicode_EncodeUTF32
(
PyUnicode_AS_UNICODE
(
str
),
PyUnicode_GET_SIZE
(
str
),
errors
,
-
1
),
PyUnicode_GET_SIZE
(
str
));
v
=
codec_tuple
(
_PyUnicode_EncodeUTF32
(
str
,
errors
,
-
1
),
PyUnicode_GET_LENGTH
(
str
));
Py_DECREF
(
str
);
return
v
;
}
...
...
@@ -875,13 +860,10 @@ utf_32_be_encode(PyObject *self,
return
NULL
;
str
=
PyUnicode_FromObject
(
str
);
if
(
str
==
NULL
)
if
(
str
==
NULL
||
PyUnicode_READY
(
str
)
<
0
)
return
NULL
;
v
=
codec_tuple
(
PyUnicode_EncodeUTF32
(
PyUnicode_AS_UNICODE
(
str
),
PyUnicode_GET_SIZE
(
str
),
errors
,
+
1
),
PyUnicode_GET_SIZE
(
str
));
v
=
codec_tuple
(
_PyUnicode_EncodeUTF32
(
str
,
errors
,
+
1
),
PyUnicode_GET_LENGTH
(
str
));
Py_DECREF
(
str
);
return
v
;
}
...
...
@@ -898,11 +880,10 @@ unicode_escape_encode(PyObject *self,
return
NULL
;
str
=
PyUnicode_FromObject
(
str
);
if
(
str
==
NULL
)
if
(
str
==
NULL
||
PyUnicode_READY
(
str
)
<
0
)
return
NULL
;
v
=
codec_tuple
(
PyUnicode_EncodeUnicodeEscape
(
PyUnicode_AS_UNICODE
(
str
),
PyUnicode_GET_SIZE
(
str
)),
PyUnicode_GET_SIZE
(
str
));
v
=
codec_tuple
(
PyUnicode_AsUnicodeEscapeString
(
str
),
PyUnicode_GET_LENGTH
(
str
));
Py_DECREF
(
str
);
return
v
;
}
...
...
@@ -919,12 +900,10 @@ raw_unicode_escape_encode(PyObject *self,
return
NULL
;
str
=
PyUnicode_FromObject
(
str
);
if
(
str
==
NULL
)
if
(
str
==
NULL
||
PyUnicode_READY
(
str
)
<
0
)
return
NULL
;
v
=
codec_tuple
(
PyUnicode_EncodeRawUnicodeEscape
(
PyUnicode_AS_UNICODE
(
str
),
PyUnicode_GET_SIZE
(
str
)),
PyUnicode_GET_SIZE
(
str
));
v
=
codec_tuple
(
PyUnicode_AsRawUnicodeEscapeString
(
str
),
PyUnicode_GET_LENGTH
(
str
));
Py_DECREF
(
str
);
return
v
;
}
...
...
@@ -941,13 +920,10 @@ latin_1_encode(PyObject *self,
return
NULL
;
str
=
PyUnicode_FromObject
(
str
);
if
(
str
==
NULL
)
if
(
str
==
NULL
||
PyUnicode_READY
(
str
)
<
0
)
return
NULL
;
v
=
codec_tuple
(
PyUnicode_EncodeLatin1
(
PyUnicode_AS_UNICODE
(
str
),
PyUnicode_GET_SIZE
(
str
),
errors
),
PyUnicode_GET_SIZE
(
str
));
v
=
codec_tuple
(
_PyUnicode_AsLatin1String
(
str
,
errors
),
PyUnicode_GET_LENGTH
(
str
));
Py_DECREF
(
str
);
return
v
;
}
...
...
@@ -964,13 +940,10 @@ ascii_encode(PyObject *self,
return
NULL
;
str
=
PyUnicode_FromObject
(
str
);
if
(
str
==
NULL
)
if
(
str
==
NULL
||
PyUnicode_READY
(
str
)
<
0
)
return
NULL
;
v
=
codec_tuple
(
PyUnicode_EncodeASCII
(
PyUnicode_AS_UNICODE
(
str
),
PyUnicode_GET_SIZE
(
str
),
errors
),
PyUnicode_GET_SIZE
(
str
));
v
=
codec_tuple
(
_PyUnicode_AsASCIIString
(
str
,
errors
),
PyUnicode_GET_LENGTH
(
str
));
Py_DECREF
(
str
);
return
v
;
}
...
...
@@ -990,10 +963,10 @@ charmap_encode(PyObject *self,
mapping
=
NULL
;
str
=
PyUnicode_FromObject
(
str
);
if
(
str
==
NULL
)
if
(
str
==
NULL
||
PyUnicode_READY
(
str
)
<
0
)
return
NULL
;
v
=
codec_tuple
(
_PyUnicode_EncodeCharmap
(
str
,
mapping
,
errors
),
PyUnicode_GET_
SIZE
(
str
));
PyUnicode_GET_
LENGTH
(
str
));
Py_DECREF
(
str
);
return
v
;
}
...
...
@@ -1021,13 +994,10 @@ mbcs_encode(PyObject *self,
return
NULL
;
str
=
PyUnicode_FromObject
(
str
);
if
(
str
==
NULL
)
if
(
str
==
NULL
||
PyUnicode_READY
(
str
)
<
0
)
return
NULL
;
v
=
codec_tuple
(
PyUnicode_EncodeMBCS
(
PyUnicode_AS_UNICODE
(
str
),
PyUnicode_GET_SIZE
(
str
),
errors
),
PyUnicode_GET_SIZE
(
str
));
v
=
codec_tuple
(
PyUnicode_EncodeCodePage
(
CP_ACP
,
str
,
errors
),
PyUnicode_GET_LENGTH
(
str
));
Py_DECREF
(
str
);
return
v
;
}
...
...
@@ -1045,7 +1015,7 @@ code_page_encode(PyObject *self,
return
NULL
;
str
=
PyUnicode_FromObject
(
str
);
if
(
str
==
NULL
)
if
(
str
==
NULL
||
PyUnicode_READY
(
str
)
<
0
)
return
NULL
;
v
=
codec_tuple
(
PyUnicode_EncodeCodePage
(
code_page
,
str
,
...
...
Objects/unicodeobject.c
View file @
1db7c13b
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment