Skip to content

iso_ir_197

Python Character Mapping Codec for iso-ir-197.

Codec

Bases: codecs.Codec

Implement the interface for stateless encoders/decoders.

Source code in /home/anders/projects/CorpusTools/corpustools/iso_ir_197.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
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[int, int]): A tuple (output object, 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[int, int]): tuple (output object, 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[int, int]

tuple (output object, length consumed)

Source code in /home/anders/projects/CorpusTools/corpustools/iso_ir_197.py
29
30
31
32
33
34
35
36
37
38
39
40
41
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[int, int]): tuple (output object, 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[int, int]

A tuple (output object, length consumed)

Source code in /home/anders/projects/CorpusTools/corpustools/iso_ir_197.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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[int, int]): A tuple (output object, 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/iso_ir_197.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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[int, int]): tuple (output object, 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[int, int]

tuple (output object, length consumed)

Source code in /home/anders/projects/CorpusTools/corpustools/iso_ir_197.py
63
64
65
66
67
68
69
70
71
72
73
def decode(self, instring, final=False):
    """Decode instring.

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

    Returns:
        (tuple[int, int]): tuple (output object, 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/iso_ir_197.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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[int, int]): tuple (output object, 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[int, int]

tuple (output object, length consumed)

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

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

    Returns:
        (tuple[int, int]): tuple (output object, 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/iso_ir_197.py
79
80
81
82
83
84
85
86
87
88
89
def getregentry():
    """Get the info for this encoding."""
    return codecs.CodecInfo(
        name="ir197",
        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/iso_ir_197.py
357
358
359
360
361
362
363
364
365
366
367
368
369
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 == "ir197":
        return getregentry()
    return None