MCPcopy Index your code
hub / github.com/python/cpython / genwinmap

Function genwinmap

Tools/unicode/genwincodec.py:11–41  ·  view source on GitHub ↗
(codepage)

Source from the content-addressed store, hash-verified

9import unicodedata
10
11def genwinmap(codepage):
12 MultiByteToWideChar = ctypes.windll.kernel32.MultiByteToWideChar
13 MultiByteToWideChar.argtypes = [wintypes.UINT, wintypes.DWORD,
14 wintypes.LPCSTR, ctypes.c_int,
15 wintypes.LPWSTR, ctypes.c_int]
16 MultiByteToWideChar.restype = ctypes.c_int
17
18 enc2uni = {}
19
20 for i in list(range(32)) + [127]:
21 enc2uni[i] = (i, 'CONTROL CHARACTER')
22
23 for i in range(256):
24 buf = ctypes.create_unicode_buffer(2)
25 ret = MultiByteToWideChar(
26 codepage, 0,
27 bytes([i]), 1,
28 buf, 2)
29 assert ret == 1, "invalid code page"
30 assert buf[1] == '\x00'
31 try:
32 name = unicodedata.name(buf[0])
33 except ValueError:
34 try:
35 name = enc2uni[i][1]
36 except KeyError:
37 name = ''
38
39 enc2uni[i] = (ord(buf[0]), name)
40
41 return enc2uni
42
43def genwincodec(codepage):
44 import platform

Callers 1

genwincodecFunction · 0.85

Calls 2

listClass · 0.85
nameMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…