Top Description Inners Constructors Methods
org.python.modules

public Class _codecs

extends Object
Class Inheritance
Imports
java.nio.ByteBuffer, java.nio.charset.Charset, java.util.Iterator, org.python.core.Py, .PyDictionary, .PyInteger, .PyNone, .PyObject, .PyString, .PySystemState, .PyTuple, .PyUnicode, .codecs, .Untraversable, org.python.expose.ExposedType

This class corresponds to the Python _codecs module, which in turn lends its functions to the codecs module (in Lib/codecs.py). It exposes the implementing functions of several codec families called out in the Python codecs library Lib/encodings/*.py, where it is usually claimed that they are bound "as C functions". Obviously, C stands for "compiled" in this context, rather than dependence on a particular implementation language. Actual transcoding methods often come from the related codecs class.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum
_codecs.ByteOrder

Enumeration representing the possible endianness of UTF-32 (possibly UTF-16) encodings.

public static class
_codecs.EncodingMap

Optimized charmap encoder mapping.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static String
public static PyTuple
public static PyTuple
ascii_decode(String str, String errors)

public static PyTuple
public static PyTuple
ascii_encode(String str, String errors)

public static PyObject
public static PyTuple

Returns:

decoded string and number of bytes consumed
charmap_decode
(String
sequence of bytes to decode
bytes
)

Equivalent to charmap_decode(bytes, errors, null).

public static PyTuple

Returns:

decoded string and number of bytes consumed
charmap_decode
(String
sequence of bytes to decode
bytes
,
String
error policy
errors
)

Equivalent to charmap_decode(bytes, errors, null).

public static PyTuple

Returns:

decoded string and number of bytes consumed
charmap_decode
(String
sequence of bytes to decode
bytes
,
String
error policy
errors
,
PyObject
to convert bytes to characters
mapping
)

Decode a sequence of bytes into Unicode characters via a mapping supplied as a container to be indexed by the byte values (as unsigned integers).

public static PyTuple

Returns:

decoded string and number of bytes consumed
charmap_decode
(String
sequence of bytes to decode
bytes
,
String
error policy
errors
,
PyObject
to convert bytes to characters
mapping
,
boolean
if true, pass unmapped byte values as character codes [0..256)
ignoreUnmapped
)

Decode a sequence of bytes into Unicode characters via a mapping supplied as a container to be indexed by the byte values (as unsigned integers).

public static PyTuple

Returns:

(encoded data, size(str)) as a pair
charmap_encode
(String
to be encoded
str
)

Equivalent to charmap_encode(str, null, null).

public static PyTuple

Returns:

(encoded data, size(str)) as a pair
charmap_encode
(String
to be encoded
str
,
String
error policy name (e.g. "ignore")
errors
)

Equivalent to charmap_encode(str, errors, null).

public static PyTuple

Returns:

(encoded data, size(str)) as a pair
charmap_encode
(String
to be encoded
str
,
String
error policy name (e.g. "ignore")
errors
,
PyObject
from character code to output byte (or string)
mapping
)

Encoder based on an optional character mapping.

private static PyTuple

Returns:

(encoded data, size(str)) as a pair
charmap_encode_internal
(String
to be encoded
str
,
String
error policy name (e.g. "ignore")
errors
,
PyObject
from character code to output byte (or string)
mapping
,
StringBuilder
to contain the encoded bytes
v
,
boolean letLookupHandleError)

Helper to implement the several variants of charmap_encode, given an optional mapping.

public static PyObject

Returns:

Unicode string decoded from bytes
decode
(PyString
to be decoded
bytes
)

Decode bytes using the system default encoding (see codecs#getDefaultEncoding()).

public static PyObject

Returns:

Unicode string decoded from bytes
decode
(PyString
to be decoded
bytes
,
PyString
name of encoding (to look up in codec registry)
encoding
)

Decode bytes using the codec registered for the encoding.

public static PyObject

Returns:

Unicode string decoded from bytes
decode
(PyString
to be decoded
bytes
,
PyString
name of encoding (to look up in codec registry)
encoding
,
PyString
error policy name (e.g. "ignore")
errors
)

Decode bytes using the codec registered for the encoding.

private static PyTuple

Returns:

the tuple (unicode(u), bytesConsumed)
decode_tuple
(String
the unicode result as a UTF-16 Java String
u
,
int
the number of bytes consumed
bytesConsumed
)

Convenience method to construct the return value of decoders, providing the Unicode result as a String, and the number of bytes consumed.

private static PyTuple

Returns:

the tuple (unicode(u), bytesConsumed)
decode_tuple
(String
the unicode result as a UTF-16 Java String
u
,
int[]
if not null, element [0] is the number of bytes consumed
consumed
,
int
if consumed==null, use this as the number of bytes consumed
defConsumed
)

Convenience method to construct the return value of decoders, providing the Unicode result as a String, and the number of bytes consumed in decoding as either a single-element array or an int to be used if the array argument is null.

private static PyTuple

Returns:

the tuple (unicode(u), bytesConsumed, byteOrder)
decode_tuple
(String
the unicode result as a UTF-16 Java String
u
,
int
the number of bytes consumed
bytesConsumed
,
_codecs.ByteOrder
the byte order (deduced by codec)
order
)

Convenience method to construct the return value of decoders that infer the byte order from the byte-order mark.

private static PyTuple
private static String
decode_UTF16(String str, String errors, int[] byteorder)

private static String
decode_UTF16(String str, String errors, int[] byteorder, int[] consumed)

public static PyString

Returns:

bytes object encoding unicode
encode
(PyUnicode
string to be encoded
unicode
)

Encode unicode using the system default encoding (see codecs#getDefaultEncoding()).

public static PyString

Returns:

bytes object encoding unicode
encode
(PyUnicode
string to be encoded
unicode
,
PyString
name of encoding (to look up in codec registry)
encoding
)

Encode unicode using the codec registered for the encoding.

public static PyString

Returns:

bytes object encoding unicode
encode
(PyUnicode
string to be encoded
unicode
,
PyString
name of encoding (to look up in codec registry)
encoding
,
PyString
error policy name (e.g. "ignore")
errors
)

Encode unicode using the codec registered for the encoding.

private static PyTuple
encode_tuple(String s, int len)

public static String
encode_UTF16(String str, String errors, int byteorder)

public static PyTuple
public static PyTuple
public static PyTuple
public static PyTuple
private static int

Returns:

index of last character of problematic section
handleBadMapping
(String
to be encoded
str
,
String
error policy name (e.g. "ignore")
errors
,
PyObject
from character code to output byte (or string)
mapping
,
StringBuilder
to contain the encoded bytes
v
,
int
of str
size
,
int
index in str of current (and problematic) character
i
)

Helper for charmap_encode_internal(String, String, PyObject, StringBuilder, boolean) called when we need some kind of substitute in the output for an invalid input.

public static PyTuple
public static PyTuple
public static PyTuple
public static PyTuple
public static PyTuple
lookup(PyString encoding)

public static PyObject
lookup_error(PyString handlerName)

private static int

Returns:

number of elements consumed now from bytes array
PyUnicode_DecodeUTF32BELoop
(StringBuilder
character output
unicode
,
String
input represented as String (Jython PyString convention)
bytes
,
int
number of elements already consumed from bytes array
q
,
int
(multiple of 4) first byte not to process
limit
,
String
error policy name (e.g. "ignore", "replace")
errors
)

Helper to PyUnicode_DecodeUTF32Stateful(String, String, ByteOrder, boolean, boolean) when big-endian decoding is to be carried out.

private static int

Returns:

number of elements consumed now from bytes array
PyUnicode_DecodeUTF32LELoop
(StringBuilder
character output
unicode
,
String
input represented as String (Jython PyString convention)
bytes
,
int
number of elements already consumed from bytes array
q
,
int
(multiple of 4) first byte not to process
limit
,
String
error policy name (e.g. "ignore", "replace")
errors
)

Helper to PyUnicode_DecodeUTF32Stateful(String, String, ByteOrder, boolean, boolean) when little-endian decoding is to be carried out.

private static PyTuple

Returns:

tuple (unicode_result, bytes_consumed [, endianness])
PyUnicode_DecodeUTF32Stateful
(String
input represented as String (Jython PyString convention)
bytes
,
String
error policy name (e.g. "ignore", "replace")
errors
,
_codecs.ByteOrder
LE, BE or UNDEFINED (meaning bytes may begin with a byte order mark)
order
,
boolean
if a "final" call, meaning the input must all be consumed
isFinal
,
boolean
if the returned tuple should include a report of the byte order
findOrder
)

Decode (perhaps partially) a sequence of bytes representing the UTF-32 encoded form of a Unicode string and return as a tuple the (Jython internal representation of) the unicode text, the amount of input consumed, and if requested, the decoding "endianness" used (in Python -1, 0, +1 conventions).

private static PyTuple

Returns:

tuple (encoded_bytes, unicode_consumed)
PyUnicode_EncodeUTF32
(String
to be encoded
unicode
,
String
error policy name or null meaning "strict"
errors
,
_codecs.ByteOrder
byte order to use BE, LE or UNDEFINED (a BOM will be written)
order
)

Encode a Unicode Java String as UTF-32 in specified byte order.

private static int

Returns:

number of Java characters consumed from unicode
PyUnicode_EncodeUTF32BELoop
(StringBuilder
output buffer building String of bytes (Jython PyString convention)
v
,
String
character input
unicode
,
String
error policy name (e.g. "ignore", "replace")
errors
)

Helper to PyUnicode_EncodeUTF32(String, String, ByteOrder) when big-endian encoding is to be carried out.

private static int

Returns:

position within input at which to restart
PyUnicode_EncodeUTF32Error
(StringBuilder
output buffer building String of bytes (Jython PyString convention)
v
,
String
error policy name (e.g. "ignore", "replace")
errors
,
_codecs.ByteOrder
LE or BE indicator
order
,
String
character input
toEncode
,
int
index of first problematic character
start
,
int
index of character after the last problematic character
end
,
String
text contribution to the exception raised (if any)
reason
)

Specific UTF-32 encoder error handler.

private static int

Returns:

number of Java characters consumed from unicode
PyUnicode_EncodeUTF32LELoop
(StringBuilder
output buffer building String of bytes (Jython PyString convention)
v
,
String
character input
unicode
,
String
error policy name (e.g. "ignore", "replace")
errors
)

Helper to PyUnicode_EncodeUTF32(String, String, ByteOrder) when big-endian encoding is to be carried out.

public static PyTuple
public static PyTuple
public static PyTuple
public static PyTuple
public static void
register(PyObject search_function)

public static void
register_error(String name, PyObject errorHandler)

public static PyObject
translateCharmap(PyUnicode str, String errors, PyObject mapping)

public static PyTuple
public static PyTuple
public static PyTuple
public static PyTuple
public static PyTuple
unicode_internal_decode(String bytes)
Deprecated

Legacy method to decode given bytes as if CPython wide-build internal format (equivalent UTF-32BE).

public static PyTuple
unicode_internal_decode(String bytes, String errors)
Deprecated

Legacy method to decode given bytes as if CPython wide-build internal format (equivalent UTF-32BE).

public static PyTuple
unicode_internal_encode(String unicode)
Deprecated

Legacy method to encode given unicode in CPython wide-build internal format (equivalent UTF-32BE).

public static PyTuple
unicode_internal_encode(String unicode, String errors)
Deprecated

Legacy method to encode given unicode in CPython wide-build internal format (equivalent UTF-32BE).

public static PyTuple
public static PyTuple
public static PyTuple
utf_16_be_decode(String str, String errors, boolean final_)

public static PyTuple
public static PyTuple
public static PyTuple
public static PyTuple
public static PyTuple
utf_16_decode(String str, String errors, boolean final_)

public static PyTuple
public static PyTuple
public static PyTuple
utf_16_encode(String str, String errors, int byteorder)

public static PyTuple
public static PyTuple
public static PyTuple
utf_16_ex_decode(String str, String errors, int byteorder)

public static PyTuple
utf_16_ex_decode(String str, String errors, int byteorder, boolean final_)

public static PyTuple
public static PyTuple
public static PyTuple
utf_16_le_decode(String str, String errors, boolean final_)

public static PyTuple
public static PyTuple
public static PyTuple

Returns:

tuple (unicode_result, bytes_consumed)
utf_32_be_decode
(String
to be decoded (Jython PyString convention)
bytes
)

Decode a sequence of bytes representing the UTF-32 big-endian encoded form of a Unicode string and return as a tuple the unicode text, and the amount of input consumed.

public static PyTuple

Returns:

tuple (unicode_result, bytes_consumed)
utf_32_be_decode
(String
to be decoded (Jython PyString convention)
bytes
,
String
error policy name (e.g. "ignore", "replace")
errors
)

Decode a sequence of bytes representing the UTF-32 big-endian encoded form of a Unicode string and return as a tuple the unicode text, and the amount of input consumed.

public static PyTuple

Returns:

tuple (unicode_result, bytes_consumed)
utf_32_be_decode
(String
to be decoded (Jython PyString convention)
bytes
,
String
error policy name (e.g. "ignore", "replace")
errors
,
boolean
if a "final" call, meaning the input must all be consumed
isFinal
)

Decode (perhaps partially) a sequence of bytes representing the UTF-32 big-endian encoded form of a Unicode string and return as a tuple the unicode text, and the amount of input consumed.

public static PyTuple

Returns:

tuple (encoded_bytes, unicode_consumed)
utf_32_be_encode
(String
to be encoded
unicode
)

Encode a Unicode Java String as UTF-32 with big-endian byte order.

public static PyTuple

Returns:

tuple (encoded_bytes, unicode_consumed)
utf_32_be_encode
(String
to be encoded
unicode
,
String
error policy name or null meaning "strict"
errors
)

Encode a Unicode Java String as UTF-32 with big-endian byte order.

public static PyTuple

Returns:

tuple (unicode_result, bytes_consumed)
utf_32_decode
(String
to be decoded (Jython PyString convention)
bytes
)

Decode (perhaps partially) a sequence of bytes representing the UTF-32 encoded form of a Unicode string and return as a tuple the unicode text, and the amount of input consumed.

public static PyTuple

Returns:

tuple (unicode_result, bytes_consumed)
utf_32_decode
(String
to be decoded (Jython PyString convention)
bytes
,
String
error policy name (e.g. "ignore", "replace")
errors
)

Decode a sequence of bytes representing the UTF-32 encoded form of a Unicode string and return as a tuple the unicode text, and the amount of input consumed.

public static PyTuple

Returns:

tuple (unicode_result, bytes_consumed)
utf_32_decode
(String
to be decoded (Jython PyString convention)
bytes
,
String
error policy name (e.g. "ignore", "replace")
errors
,
boolean
if a "final" call, meaning the input must all be consumed
isFinal
)

Decode (perhaps partially) a sequence of bytes representing the UTF-32 encoded form of a Unicode string and return as a tuple the unicode text, and the amount of input consumed.

public static PyTuple

Returns:

tuple (encoded_bytes, unicode_consumed)
utf_32_encode
(String
to be encoded
unicode
)

Encode a Unicode Java String as UTF-32 with byte order mark.

public static PyTuple

Returns:

tuple (encoded_bytes, unicode_consumed)
utf_32_encode
(String
to be encoded
unicode
,
String
error policy name or null meaning "strict"
errors
)

Encode a Unicode Java String as UTF-32 with byte order mark.

public static PyTuple

Returns:

tuple (encoded_bytes, unicode_consumed)
utf_32_encode
(String
to be encoded
unicode
,
String
error policy name or null meaning "strict"
errors
,
int
decoding "endianness" specified (in the Python -1, 0, +1 convention)
byteorder
)

Encode a Unicode Java String as UTF-32 in specified byte order with byte order mark.

public static PyTuple

Returns:

tuple (unicode_result, bytes_consumed, endianness)
utf_32_ex_decode
(String
to be decoded (Jython PyString convention)
bytes
,
String
error policy name (e.g. "ignore", "replace")
errors
,
int
decoding "endianness" specified (in the Python -1, 0, +1 convention)
byteorder
)

Decode a sequence of bytes representing the UTF-32 encoded form of a Unicode string and return as a tuple the unicode text, the amount of input consumed, and the decoding "endianness" used (in the Python -1, 0, +1 convention).

public static PyTuple

Returns:

tuple (unicode_result, bytes_consumed, endianness)
utf_32_ex_decode
(String
to be decoded (Jython PyString convention)
bytes
,
String
error policy name (e.g. "ignore", "replace")
errors
,
int
decoding "endianness" specified (in the Python -1, 0, +1 convention)
byteorder
,
boolean
if a "final" call, meaning the input must all be consumed
isFinal
)

Decode (perhaps partially) a sequence of bytes representing the UTF-32 encoded form of a Unicode string and return as a tuple the unicode text, the amount of input consumed, and the decoding "endianness" used (in the Python -1, 0, +1 convention).

public static PyTuple

Returns:

tuple (unicode_result, bytes_consumed)
utf_32_le_decode
(String
to be decoded (Jython PyString convention)
bytes
)

Decode a sequence of bytes representing the UTF-32 little-endian encoded form of a Unicode string and return as a tuple the unicode text, and the amount of input consumed.

public static PyTuple

Returns:

tuple (unicode_result, bytes_consumed)
utf_32_le_decode
(String
to be decoded (Jython PyString convention)
bytes
,
String
error policy name (e.g. "ignore", "replace")
errors
)

Decode a sequence of bytes representing the UTF-32 little-endian encoded form of a Unicode string and return as a tuple the unicode text, and the amount of input consumed.

public static PyTuple

Returns:

tuple (unicode_result, bytes_consumed)
utf_32_le_decode
(String
to be decoded (Jython PyString convention)
bytes
,
String
error policy name (e.g. "ignore", "replace")
errors
,
boolean
if a "final" call, meaning the input must all be consumed
isFinal
)

Decode (perhaps partially) a sequence of bytes representing the UTF-32 little-endian encoded form of a Unicode string and return as a tuple the unicode text, and the amount of input consumed.

public static PyTuple

Returns:

tuple (encoded_bytes, unicode_consumed)
utf_32_le_encode
(String
to be encoded
unicode
)

Encode a Unicode Java String as UTF-32 with little-endian byte order.

public static PyTuple

Returns:

tuple (encoded_bytes, unicode_consumed)
utf_32_le_encode
(String
to be encoded
unicode
,
String
error policy name or null meaning "strict"
errors
)

Encode a Unicode Java String as UTF-32 with little-endian byte order.

public static PyTuple
public static PyTuple
utf_7_decode(String bytes, String errors)

public static PyTuple
utf_7_decode(String bytes, String errors, boolean finalFlag)

public static PyTuple
public static PyTuple
utf_7_encode(String str, String errors)

public static PyTuple
public static PyTuple
utf_8_decode(String str, String errors)

public static PyTuple
utf_8_decode(String str, String errors, PyObject final_)

public static PyTuple
utf_8_decode(String str, String errors, boolean final_)

public static PyTuple
public static PyTuple
utf_8_encode(String str, String errors)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait