It defaults to -1 which means that the default buffer size will be used. Which causes a ValueError to be raised in case an encoding error occurs.īuffering has the same meaning as for the built-in open() function. The data types supported by the file methods depend on the codec used.Įrrors may be given to define the error handling. Open() function the 'b' is automatically added.Įncoding specifies the encoding which is to be used for the file.Īny encoding that encodes to and decodes from bytes is allowed, and
The mode argument may be any binary mode acceptable to the built-in No automatic conversion of '\n' is done on reading and writing. Underlying encoded files are always opened in binary mode. In case a search function cannot find a given encoding, it should return Search functions are expected to take oneĪrgument, being the encoding name in all lower case letters with hyphensĪnd spaces converted to underscores, and return a CodecInfo object. Raises a LookupError in case the encoding cannot be found.Ĭustom codecs are made available by registering a suitable codec searchįunction: codecs. Look up the codec for the given encoding and return its StreamWriter Raises a LookupError in case the encoding cannot be found. Look up the codec for the given encoding and return its StreamReader Look up the codec for the given encoding and return its incremental decoderĭoesn’t support an incremental decoder. Raises a LookupError in case the encoding cannot be found or the codecĭoesn’t support an incremental encoder. Look up the codec for the given encoding and return its incremental encoder Look up the codec for the given encoding and return its decoder function. Look up the codec for the given encoding and return its encoder function. These additional functions which use lookup() for the codec lookup: codecs. To simplify access to the various codec components, the module provides StreamWriter and StreamReader, respectively. Provide the interface defined by the base classes Stream writer and reader classes or factory functions. IncrementalEncoder and IncrementalDecoder, These have to provide the interface defined by the base classes Incremental encoder and decoder classes or factory functions. incrementalencoder ¶ incrementaldecoder ¶ The functions or methods are expected to work in a stateless mode. The encode() and decode() methods of Codec These must beįunctions or methods which have the same interface as The stateless encoding and decoding functions. The constructorĪrguments are stored in attributes of the same name: name ¶ CodecInfo ( encode, decode, streamreader = None, streamwriter = None, incrementalencoder = None, incrementaldecoder = None, name = None ) ¶Ĭodec details when looking up the codec registry. Is stored in the cache and returned to the caller. If no CodecInfo object isįound, a LookupError is raised. Looks up the codec info in the Python codec registry and returns aĮncodings are first looked up in the registry’s cache.
The full details for each codec can also be looked up directly: codecs. decode ( obj, encoding = 'utf-8', errors = 'strict' ) ¶ĭecodes obj using the codec registered for encoding.ĭefault error handler is 'strict' meaning that decoding errors raise ValueError (or a more codec specific subclass, such as Theĭefault error handler is 'strict' meaning that encoding errors raise encode ( obj, encoding = 'utf-8', errors = 'strict' ) ¶Įncodes obj using the codec registered for encoding.Įrrors may be given to set the desired error handling scheme. The module defines the following functions for encoding and decoding withĪny codec: codecs. Text encodings or with codecs that encode to
Types, but some module features are restricted to be used specifically with Custom codecs may encode and decode between arbitrary
Most standard codecsĪre text encodings, which encode text to bytes (andĭecode bytes to text), but there are also codecs provided that encode text to Manages the codec and error handling lookup process. This module defines base classes for standard Python codecs (encoders andĭecoders) and provides access to the internal Python codec registry, which Codecs - Codec registry and base classes ¶