blob: fa4320dd50ae4d207095394208faff9870070682 (
plain)
1
2
3
4
5
6
7
8
9
10
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
|
#!/usr/bin/python
import re
def hex_to_bytes(h):
return ''.join(chr(int(h[i:i+2], 16)) for i in xrange(0,len(h),2))
def tv_parse(line):
line = line.strip()
g = re.match(r'TV\((.*?), ?(.*?)\)', line)
if not g:
raise ValueError, "PAS BIEN"
pck = hex_to_bytes(g.group(1))
pec = hex_to_bytes(g.group(2))
return pck, pec
def load_singles(s):
x = {}
for line in s.split('\n'):
line = line.strip()
if not line:
continue
pck, pec = tv_parse(line)
if len(pck) != 1:
continue
pck = ord(pck)
pec = ord(pec)
if pck in x:
raise ValueError, "pck %02x already seen" % pck
x[pck] = pec
return x
|