Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/webencodings/mklabels.py @ 1:56ad4e20f292 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:32:28 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:d30785e31577 | 1:56ad4e20f292 |
---|---|
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 | |
13 import json | |
14 try: | |
15 from urllib import urlopen | |
16 except ImportError: | |
17 from urllib.request import urlopen | |
18 | |
19 | |
20 def assert_lower(string): | |
21 assert string == string.lower() | |
22 return string | |
23 | |
24 | |
25 def 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 | |
42 LABELS = { | |
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) | |
51 parts.extend( | |
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 | |
58 if __name__ == '__main__': | |
59 print(generate('http://encoding.spec.whatwg.org/encodings.json')) |