Trees | Indices | Help |
|
---|
codecs -- Python Codec Registry, API and helpers.
Written by Marc-Andre Lemburg (mal@lemburg.com).
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
'
rb
'
,
encoding=None,
errors='
strict
'
,
buffering=1)'
strict
'
)'
strict
'
,
**kwargs)'
strict
'
,
**kwargs)'
\xef\xbb\xbf
'
'
\xff\xfe
'
'
\xff\xfe
'
'
\xfe\xff
'
'
\xfe\xff
'
'
\xff\xfe\x00\x00
'
'
\x00\x00\xfe\xff
'
'
\xff\xfe
'
'
\xff\xfe
'
'
\xff\xfe\x00\x00
'
'
\xff\xfe
'
'
\xfe\xff
'
'
\xff\xfe\x00\x00
'
'
\x00\x00\xfe\xff
'
0
Imports: __builtin__, sys, encodings, ascii_decode, ascii_encode, charbuffer_encode, charmap_build, charmap_decode, charmap_encode, decode, encode, escape_decode, escape_encode, latin_1_decode, latin_1_encode, raw_unicode_escape_decode, raw_unicode_escape_encode, readbuffer_encode, unicode_escape_decode, unicode_escape_encode, unicode_internal_decode, unicode_internal_encode, utf_16_be_decode, utf_16_be_encode, utf_16_decode, utf_16_encode, utf_16_ex_decode, utf_16_le_decode, utf_16_le_encode, utf_7_decode, utf_7_encode, utf_8_decode, utf_8_encode
'
rb
'
,
encoding=None,
errors='
strict
'
,
buffering=1)
Open an encoded file using the given mode and return a wrapped version providing transparent encoding/decoding.
Note: The wrapped version will only accept the object format defined by the codecs, i.e. Unicode objects for most builtin codecs. Output is also codec dependent and will usually be Unicode as well.
Files are always opened in binary mode, even if no binary mode was specified. This is done to avoid data loss due to encodings using 8-bit values. The default file mode is 'rb' meaning to open the file in binary read mode.
encoding specifies the encoding which is to be used for the file.
errors may be given to define the error handling. It defaults to 'strict' which causes ValueErrors to be raised in case an encoding error occurs.
buffering has the same meaning as for the builtin open() API. It defaults to line buffered.
The returned wrapped file object provides an extra attribute .encoding which allows querying the used encoding. This attribute is only available if an encoding was specified as parameter.
'
strict
'
)
Return a wrapped version of file which provides transparent encoding translation.
Strings written to the wrapped file are interpreted according to the given data_encoding and then written to the original file as string using file_encoding. The intermediate encoding will usually be Unicode but depends on the specified codecs.
Strings are read from the file using file_encoding and then passed back to the caller as string using data_encoding.
If file_encoding is not given, it defaults to data_encoding.
errors may be given to define the error handling. It defaults to 'strict' which causes ValueErrors to be raised in case an encoding error occurs.
The returned wrapped file object provides two extra attributes .data_encoding and .file_encoding which reflect the given parameters of the same name. The attributes can be used for introspection by Python programs.
Lookup up the codec for the given encoding and return its encoder function.
Raises a LookupError in case the encoding cannot be found.
Lookup up the codec for the given encoding and return its decoder function.
Raises a LookupError in case the encoding cannot be found.
Lookup up the codec for the given encoding and return its IncrementalEncoder class or factory function.
Raises a LookupError in case the encoding cannot be found or the codecs doesn't provide an incremental encoder.
Lookup up the codec for the given encoding and return its IncrementalDecoder class or factory function.
Raises a LookupError in case the encoding cannot be found or the codecs doesn't provide an incremental decoder.
Lookup up the codec for the given encoding and return its StreamReader class or factory function.
Raises a LookupError in case the encoding cannot be found.
Lookup up the codec for the given encoding and return its StreamWriter class or factory function.
Raises a LookupError in case the encoding cannot be found.
'
strict
'
,
**kwargs)
Encoding iterator.
Encodes the input strings from the iterator using a IncrementalEncoder.
errors and kwargs are passed through to the IncrementalEncoder constructor.
'
strict
'
,
**kwargs)
Decoding iterator.
Decodes the input strings from the iterator using a IncrementalDecoder.
errors and kwargs are passed through to the IncrementalDecoder constructor.
Creates an encoding map from a decoding map.
If a target mapping in the decoding map occurs multiple times, then that target is mapped to None (undefined mapping), causing an exception when encountered by the charmap codec during translation.
One example where this happens is cp875.py which decodes multiple character to \u001a.
Register a codec search function. Search functions are expected to take one argument, the encoding name in all lower case letters, and return a tuple of functions (encoder, decoder, stream_reader, stream_writer).
Register the specified error handler under the name errors. handler must be a callable object, that will be called with an exception instance containing information about the location of the encoding/decoding error and must return a (replacement, new position) tuple.
Trees | Indices | Help |
|
---|