Debian Codegraph @

pypy/module/_codecs/moduledef.py

raw symbols SCIP
1 from pypy.interpreter.mixedmodule import MixedModule
2 from rpython.rlib.objectmodel import not_rpython
3 from pypy.module._codecs import interp_codecs
4
5 class Module(MixedModule):
6 """
7 _codecs -- Provides access to the codec registry and the builtin
8 codecs.
9
10 This module should never be imported directly. The standard library
11 module "codecs" wraps this builtin module for use within Python.
12
13 The codec registry is accessible via:
14
15 register(search_function) -> None
16
17 lookup(encoding) -> (encoder, decoder, stream_reader, stream_writer)
18
19 The builtin Unicode codecs use the following interface:
20
21 <encoding>_encode(Unicode_object[,errors='strict']) ->
22 (string object, bytes consumed)
23
24 <encoding>_decode(char_buffer_obj[,errors='strict']) ->
25 (Unicode object, bytes consumed)
26
27 <encoding>_encode() interfaces also accept non-Unicode object as
28 input. The objects are then converted to Unicode using
29 PyUnicode_FromObject() prior to applying the conversion.
30
31 These <encoding>s are available: utf_8, unicode_escape,
32 raw_unicode_escape, latin_1, ascii (7-bit),
33 mbcs (on win32).
34
35
36 Written by Marc-Andre Lemburg ([email protected]).
37
38 Copyright (c) Corporation for National Research Initiatives.
39 """
40
41 appleveldefs = {}
42
43 interpleveldefs = {
44 'encode': 'interp_codecs.encode',
45 'decode': 'interp_codecs.decode',
46 'lookup': 'interp_codecs.lookup_codec',
47 'lookup_error': 'interp_codecs.lookup_error',
48 'register': 'interp_codecs.register_codec',
49 'register_error': 'interp_codecs.register_error',
50 'charmap_build' : 'interp_codecs.charmap_build',
51 'unregister' : 'interp_codecs.unregister',
52
53 # encoders and decoders
54 'ascii_decode' : 'interp_codecs.ascii_decode',
55 'ascii_encode' : 'interp_codecs.ascii_encode',
56 'latin_1_decode' : 'interp_codecs.latin_1_decode',
57 'latin_1_encode' : 'interp_codecs.latin_1_encode',
58 'utf_7_decode' : 'interp_codecs.utf_7_decode',
59 'utf_7_encode' : 'interp_codecs.utf_7_encode',
60 'utf_8_decode' : 'interp_codecs.utf_8_decode',
61 'utf_8_encode' : 'interp_codecs.utf_8_encode',
62 'utf_16_be_decode' : 'interp_codecs.utf_16_be_decode',
63 'utf_16_be_encode' : 'interp_codecs.utf_16_be_encode',
64 'utf_16_decode' : 'interp_codecs.utf_16_decode',
65 'utf_16_encode' : 'interp_codecs.utf_16_encode',
66 'utf_16_le_decode' : 'interp_codecs.utf_16_le_decode',
67 'utf_16_le_encode' : 'interp_codecs.utf_16_le_encode',
68 'utf_16_ex_decode' : 'interp_codecs.utf_16_ex_decode',
69 'utf_32_decode' : 'interp_codecs.utf_32_decode',
70 'utf_32_encode' : 'interp_codecs.utf_32_encode',
71 'utf_32_be_decode' : 'interp_codecs.utf_32_be_decode',
72 'utf_32_be_encode' : 'interp_codecs.utf_32_be_encode',
73 'utf_32_le_decode' : 'interp_codecs.utf_32_le_decode',
74 'utf_32_le_encode' : 'interp_codecs.utf_32_le_encode',
75 'utf_32_ex_decode' : 'interp_codecs.utf_32_ex_decode',
76 'readbuffer_encode': 'interp_codecs.readbuffer_encode',
77 'charmap_decode' : 'interp_codecs.charmap_decode',
78 'charmap_encode' : 'interp_codecs.charmap_encode',
79 'escape_encode' : 'interp_codecs.escape_encode',
80 'escape_decode' : 'interp_codecs.escape_decode',
81 'unicode_escape_decode' : 'interp_codecs.unicode_escape_decode',
82 'unicode_escape_encode' : 'interp_codecs.unicode_escape_encode',
83 'raw_unicode_escape_decode' : 'interp_codecs.raw_unicode_escape_decode',
84 'raw_unicode_escape_encode' : 'interp_codecs.raw_unicode_escape_encode',
85 }
86
87 @not_rpython
88 def __init__(self, space, *args):
89 # mbcs codec is Windows specific, and based on rffi system calls.
90 if (hasattr(interp_codecs, 'mbcs_encode')):
91 self.interpleveldefs['mbcs_encode'] = 'interp_codecs.mbcs_encode'
92 self.interpleveldefs['oem_encode'] = 'interp_codecs.oem_encode'
93 self.interpleveldefs['code_page_encode'] = 'interp_codecs.code_page_encode'
94 self.interpleveldefs['mbcs_decode'] = 'interp_codecs.mbcs_decode'
95 self.interpleveldefs['oem_decode'] = 'interp_codecs.oem_decode'
96 self.interpleveldefs['code_page_decode'] = 'interp_codecs.code_page_decode'
97
98 MixedModule.__init__(self, space, *args)
99
100 interp_codecs.register_builtin_error_handlers(space)