Skip to content

winsami2

Python Character Mapping Codec for winsami2.

Codec

Bases: codecs.Codec

Implement the interface for stateless encoders/decoders.

Source code in /home/anders/projects/CorpusTools/corpustools/winsami2.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Codec(codecs.Codec):
    """Implement the interface for stateless encoders/decoders."""

    def encode(self, instring, errors="strict"):
        """Encode the object instring.

        Args:
            instring (str): the string that should be encoded with this
                codec.
            errors (str): define the error handling to apply. One of
                'strict', 'replace', 'ignore',  'xmlcharrefreplace' or
                'backslashreplace'.

        Returns:
            (tuple[bytes, int]): A tuple of the output object and the 
                length consumed
        """
        return codecs.charmap_encode(instring, errors, encoding_table)

    def decode(self, instring, errors="strict"):
        """Decode the object instring.

        Args:
            instring (str): the string that should be decoded with this
                codec.
            errors (str): define the error handling to apply. One of
                'strict', 'replace' or 'ignore'.

        Returns:
            (tuple[bytes, int]): A tuple of output object and the length
                consumed
        """
        return codecs.charmap_decode(instring, errors, decoding_table)

decode(instring, errors='strict')

Decode the object instring.

Parameters:

Name Type Description Default
instring str

the string that should be decoded with this codec.

required
errors str

define the error handling to apply. One of 'strict', 'replace' or 'ignore'.

'strict'

Returns:

Type Description
tuple[bytes, int]

A tuple of output object and the length consumed

Source code in /home/anders/projects/CorpusTools/corpustools/winsami2.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def decode(self, instring, errors="strict"):
    """Decode the object instring.

    Args:
        instring (str): the string that should be decoded with this
            codec.
        errors (str): define the error handling to apply. One of
            'strict', 'replace' or 'ignore'.

    Returns:
        (tuple[bytes, int]): A tuple of output object and the length
            consumed
    """
    return codecs.charmap_decode(instring, errors, decoding_table)

encode(instring, errors='strict')

Encode the object instring.

Parameters:

Name Type Description Default
instring str

the string that should be encoded with this codec.

required
errors str

define the error handling to apply. One of 'strict', 'replace', 'ignore', 'xmlcharrefreplace' or 'backslashreplace'.

'strict'

Returns:

Type Description
tuple[bytes, int]

A tuple of the output object and the length consumed

Source code in /home/anders/projects/CorpusTools/corpustools/winsami2.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def encode(self, instring, errors="strict"):
    """Encode the object instring.

    Args:
        instring (str): the string that should be encoded with this
            codec.
        errors (str): define the error handling to apply. One of
            'strict', 'replace', 'ignore',  'xmlcharrefreplace' or
            'backslashreplace'.

    Returns:
        (tuple[bytes, int]): A tuple of the output object and the 
            length consumed
    """
    return codecs.charmap_encode(instring, errors, encoding_table)

IncrementalDecoder

Bases: codecs.IncrementalDecoder

Implement an IncrementalDecoder.

Source code in /home/anders/projects/CorpusTools/corpustools/winsami2.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
class IncrementalDecoder(codecs.IncrementalDecoder):
    """Implement an IncrementalDecoder."""

    def decode(self, instring, final=False):
        """Decode instring.

        Args:
            instring (str): the string that should be decoded with this
                codec.

        Returns:
            (tuple[bytes, int]): A tuple of the output object and the length
                consumed
        """
        return codecs.charmap_decode(instring, self.errors, decoding_table)[0]

decode(instring, final=False)

Decode instring.

Parameters:

Name Type Description Default
instring str

the string that should be decoded with this codec.

required

Returns:

Type Description
tuple[bytes, int]

A tuple of the output object and the length consumed

Source code in /home/anders/projects/CorpusTools/corpustools/winsami2.py
66
67
68
69
70
71
72
73
74
75
76
77
def decode(self, instring, final=False):
    """Decode instring.

    Args:
        instring (str): the string that should be decoded with this
            codec.

    Returns:
        (tuple[bytes, int]): A tuple of the output object and the length
            consumed
    """
    return codecs.charmap_decode(instring, self.errors, decoding_table)[0]

IncrementalEncoder

Bases: codecs.IncrementalEncoder

Implement an IncrementalEncoder.

Source code in /home/anders/projects/CorpusTools/corpustools/winsami2.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class IncrementalEncoder(codecs.IncrementalEncoder):
    """Implement an IncrementalEncoder."""

    def encode(self, instring, final=False):
        """Encode instring.

        Args:
            instring (str): the string that should be encoded with this
                codec.

        Returns:
            (tuple[bytes, int]): A tuple of the output object and the length
                consumed
        """
        return codecs.charmap_encode(instring, self.errors, encoding_table)[0]

encode(instring, final=False)

Encode instring.

Parameters:

Name Type Description Default
instring str

the string that should be encoded with this codec.

required

Returns:

Type Description
tuple[bytes, int]

A tuple of the output object and the length consumed

Source code in /home/anders/projects/CorpusTools/corpustools/winsami2.py
49
50
51
52
53
54
55
56
57
58
59
60
def encode(self, instring, final=False):
    """Encode instring.

    Args:
        instring (str): the string that should be encoded with this
            codec.

    Returns:
        (tuple[bytes, int]): A tuple of the output object and the length
            consumed
    """
    return codecs.charmap_encode(instring, self.errors, encoding_table)[0]

getregentry()

Get the info for this encoding.

Source code in /home/anders/projects/CorpusTools/corpustools/winsami2.py
83
84
85
86
87
88
89
90
91
92
93
def getregentry():
    """Get the info for this encoding."""
    return codecs.CodecInfo(
        name="ws2",
        encode=Codec().encode,
        decode=Codec().decode,
        incrementalencoder=IncrementalEncoder,
        incrementaldecoder=IncrementalDecoder,
        streamreader=codecs.StreamReader,
        streamwriter=codecs.StreamWriter,
    )

lookup(encoding)

Lookup the name of the encoding.

Parameters:

Name Type Description Default
encoding str

name of the encoding

required

Returns:

Type Description
Codecs.CodecInfo | None

Codecs.CodecInfo if encoding is the name of the encoding of this file, None otherwise.

Source code in /home/anders/projects/CorpusTools/corpustools/winsami2.py
361
362
363
364
365
366
367
368
369
370
371
372
373
def lookup(encoding):
    """Lookup the name of the encoding.

    Args:
        encoding (str): name of the encoding

    Returns:
        (Codecs.CodecInfo|None): Codecs.CodecInfo if encoding is the name
            of the encoding of this file, None otherwise.
    """
    if encoding == "ws2":
        return getregentry()
    return None