ยปCore Development>Code coverage>Lib/encodings/rot_13.py

Python code coverage for Lib/encodings/rot_13.py

#countcontent
1n/a#!/usr/bin/env python
2n/a""" Python Character Mapping Codec for ROT13.
3n/a
4n/aThis codec de/encodes from str to str.
5n/a
6n/aWritten by Marc-Andre Lemburg (mal@lemburg.com).
7n/a"""
8n/a
9n/aimport codecs
10n/a
11n/a### Codec APIs
12n/a
13n/aclass Codec(codecs.Codec):
14n/a def encode(self, input, errors='strict'):
15n/a return (input.translate(rot13_map), len(input))
16n/a
17n/a def decode(self, input, errors='strict'):
18n/a return (input.translate(rot13_map), len(input))
19n/a
20n/aclass IncrementalEncoder(codecs.IncrementalEncoder):
21n/a def encode(self, input, final=False):
22n/a return input.translate(rot13_map)
23n/a
24n/aclass IncrementalDecoder(codecs.IncrementalDecoder):
25n/a def decode(self, input, final=False):
26n/a return input.translate(rot13_map)
27n/a
28n/aclass StreamWriter(Codec,codecs.StreamWriter):
29n/a pass
30n/a
31n/aclass StreamReader(Codec,codecs.StreamReader):
32n/a pass
33n/a
34n/a### encodings module API
35n/a
36n/adef getregentry():
37n/a return codecs.CodecInfo(
38n/a name='rot-13',
39n/a encode=Codec().encode,
40n/a decode=Codec().decode,
41n/a incrementalencoder=IncrementalEncoder,
42n/a incrementaldecoder=IncrementalDecoder,
43n/a streamwriter=StreamWriter,
44n/a streamreader=StreamReader,
45n/a _is_text_encoding=False,
46n/a )
47n/a
48n/a### Map
49n/a
50n/arot13_map = codecs.make_identity_dict(range(256))
51n/arot13_map.update({
52n/a 0x0041: 0x004e,
53n/a 0x0042: 0x004f,
54n/a 0x0043: 0x0050,
55n/a 0x0044: 0x0051,
56n/a 0x0045: 0x0052,
57n/a 0x0046: 0x0053,
58n/a 0x0047: 0x0054,
59n/a 0x0048: 0x0055,
60n/a 0x0049: 0x0056,
61n/a 0x004a: 0x0057,
62n/a 0x004b: 0x0058,
63n/a 0x004c: 0x0059,
64n/a 0x004d: 0x005a,
65n/a 0x004e: 0x0041,
66n/a 0x004f: 0x0042,
67n/a 0x0050: 0x0043,
68n/a 0x0051: 0x0044,
69n/a 0x0052: 0x0045,
70n/a 0x0053: 0x0046,
71n/a 0x0054: 0x0047,
72n/a 0x0055: 0x0048,
73n/a 0x0056: 0x0049,
74n/a 0x0057: 0x004a,
75n/a 0x0058: 0x004b,
76n/a 0x0059: 0x004c,
77n/a 0x005a: 0x004d,
78n/a 0x0061: 0x006e,
79n/a 0x0062: 0x006f,
80n/a 0x0063: 0x0070,
81n/a 0x0064: 0x0071,
82n/a 0x0065: 0x0072,
83n/a 0x0066: 0x0073,
84n/a 0x0067: 0x0074,
85n/a 0x0068: 0x0075,
86n/a 0x0069: 0x0076,
87n/a 0x006a: 0x0077,
88n/a 0x006b: 0x0078,
89n/a 0x006c: 0x0079,
90n/a 0x006d: 0x007a,
91n/a 0x006e: 0x0061,
92n/a 0x006f: 0x0062,
93n/a 0x0070: 0x0063,
94n/a 0x0071: 0x0064,
95n/a 0x0072: 0x0065,
96n/a 0x0073: 0x0066,
97n/a 0x0074: 0x0067,
98n/a 0x0075: 0x0068,
99n/a 0x0076: 0x0069,
100n/a 0x0077: 0x006a,
101n/a 0x0078: 0x006b,
102n/a 0x0079: 0x006c,
103n/a 0x007a: 0x006d,
104n/a})
105n/a
106n/a### Filter API
107n/a
108n/adef rot13(infile, outfile):
109n/a outfile.write(codecs.encode(infile.read(), 'rot-13'))
110n/a
111n/aif __name__ == '__main__':
112n/a import sys
113n/a rot13(sys.stdin, sys.stdout)