utf_16_be.py 1.01 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
""" Python 'utf-16-be' Codec


Written by Marc-Andre Lemburg (mal@lemburg.com).

(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.

"""
import codecs

### Codec APIs

13
encode = codecs.utf_16_be_encode
14

15 16
def decode(input, errors='strict'):
    return codecs.utf_16_be_decode(input, errors, True)
Tim Peters's avatar
Tim Peters committed
17

18 19 20 21 22 23 24
class IncrementalEncoder(codecs.IncrementalEncoder):
    def encode(self, input, final=False):
        return codecs.utf_16_be_encode(input, self.errors)[0]

class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
    _buffer_decode = codecs.utf_16_be_decode

25 26
class StreamWriter(codecs.StreamWriter):
    encode = codecs.utf_16_be_encode
27

28 29
class StreamReader(codecs.StreamReader):
    decode = codecs.utf_16_be_decode
30 31 32 33

### encodings module API

def getregentry():
34 35 36 37 38 39 40 41 42
    return codecs.CodecInfo(
        name='utf-16-be',
        encode=encode,
        decode=decode,
        incrementalencoder=IncrementalEncoder,
        incrementaldecoder=IncrementalDecoder,
        streamreader=StreamReader,
        streamwriter=StreamWriter,
    )