Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
mklabels.py
Go to the documentation of this file.
1"""
2
3 webencodings.mklabels
4 ~~~~~~~~~~~~~~~~~~~~~
5
6 Regenarate the webencodings.labels module.
7
8 :copyright: Copyright 2012 by Simon Sapin
9 :license: BSD, see LICENSE for details.
10
11"""
12
13import json
14try:
15 from urllib import urlopen
16except ImportError:
17 from urllib.request import urlopen
18
19
20def assert_lower(string):
21 assert string == string.lower()
22 return string
23
24
25def generate(url):
26 parts = ['''\
27"""
28
29 webencodings.labels
30 ~~~~~~~~~~~~~~~~~~~
31
32 Map encoding labels to their name.
33
34 :copyright: Copyright 2012 by Simon Sapin
35 :license: BSD, see LICENSE for details.
36
37"""
38
39# XXX Do not edit!
40# This file is automatically generated by mklabels.py
41
42LABELS = {
43''']
44 labels = [
45 (repr(assert_lower(label)).lstrip('u'),
46 repr(encoding['name']).lstrip('u'))
47 for category in json.loads(urlopen(url).read().decode('ascii'))
48 for encoding in category['encodings']
49 for label in encoding['labels']]
50 max_len = max(len(label) for label, name in labels)
52 ' %s:%s %s,\n' % (label, ' ' * (max_len - len(label)), name)
53 for label, name in labels)
54 parts.append('}')
55 return ''.join(parts)
56
57
58if __name__ == '__main__':
59 print(generate('http://encoding.spec.whatwg.org/encodings.json'))
for i