Back to index

python3.2  3.2.2
Classes | Functions
encodings.utf_8_sig Namespace Reference

Classes

class  IncrementalEncoder
class  IncrementalDecoder
class  StreamWriter
class  StreamReader

Functions

def encode
 Codec APIs.
def decode
def getregentry

Detailed Description

Python 'utf-8-sig' Codec
This work similar to UTF-8 with the following changes:

* On encoding/writing a UTF-8 encoded BOM will be prepended/written as the
  first three bytes.

* On decoding/reading if the first three bytes are a UTF-8 encoded BOM, these
  bytes will be skipped.

Function Documentation

def encodings.utf_8_sig.decode (   input,
  errors = 'strict' 
)

Definition at line 18 of file utf_8_sig.py.

00018 
00019 def decode(input, errors='strict'):
00020     prefix = 0
00021     if input[:3] == codecs.BOM_UTF8:
00022         input = input[3:]
00023         prefix = 3
00024     (output, consumed) = codecs.utf_8_decode(input, errors, True)
00025     return (output, consumed+prefix)

def encodings.utf_8_sig.encode (   input,
  errors = 'strict' 
)

Codec APIs.

Definition at line 14 of file utf_8_sig.py.

00014 
00015 def encode(input, errors='strict'):
00016     return (codecs.BOM_UTF8 + codecs.utf_8_encode(input, errors)[0],
00017             len(input))

Definition at line 121 of file utf_8_sig.py.

00121 
00122 def getregentry():
00123     return codecs.CodecInfo(
00124         name='utf-8-sig',
00125         encode=encode,
00126         decode=decode,
00127         incrementalencoder=IncrementalEncoder,
00128         incrementaldecoder=IncrementalDecoder,
00129         streamreader=StreamReader,
00130         streamwriter=StreamWriter,
00131     )