On this page
codecs.IncrementalDecoder
Prev: codecs.ignore_errors | Up: codecs | Next: codecs.IncrementalEncoder
Rel: codecs.backslashreplace_errors, codecs.Codec, codecs.CodecInfo, codecs.decode
Ref: docs.python.org — codecs.IncrementalDecoder
Tags: #public #python3 #stdlib #codecs
Import
import codecs
from codecs import IncrementalDecoder
Signature & Overview
codecs.IncrementalDecoder(errors='strict')
An IncrementalDecoder decodes an input in multiple steps. The input can be passed piece by piece to the decode() method. The IncrementalDecoder remembers the state of the decoding process between calls to decode().
Methods & Attributes
IncrementalDecoder.decode(self, input, final=False)— Decode input and returns the resulting object.IncrementalDecoder.getstate(self)— Return the current state of the decoder.IncrementalDecoder.reset(self)— Reset the decoder to the initial state.IncrementalDecoder.setstate(self, state)— Set the current state of the decoder.
Usage
import codecs
dec = codecs.getincrementaldecoder("utf-8")()
raw = "é".encode("utf-8")
assert dec.decode(raw[:1], final=False) == ""
assert dec.decode(raw[1:], final=True) == "é"
Gotchas
- Essential for streaming sockets/chunks: Buffers incomplete multi-byte UTF-8 sequences until the remaining bytes arrive.
REPL Inspect
from codecs import IncrementalDecoder
help(IncrementalDecoder)
Linked from
Related notes
- tuts/python3/stdlib_module/codecs/ignore_errors Linked here; links to this page; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/IncrementalEncoder Linked here; links to this page; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/codecs/backslashreplace_errors Linked here; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/Codec Linked here; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/CodecInfo Linked here; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/decode Linked here; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/encode shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/EncodedFile shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/getdecoder shared tags: #codecs, #stdlib