Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(614)

Side by Side Diff: third_party/WebKit/Source/devtools/scripts/aria_attributes.py

Issue 2200893003: DevTools: Add autocomplete for ARIA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove done TODO Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 import json
8 import urllib2
9 import xml.dom.minidom
10
11 import sys
12
13
14 def add_array_property(obj, name, info_node):
15 value = ''
16 if info_node.hasAttribute('rdf:resource'):
17 value = info_node.getAttribute('rdf:resource').split('#')[-1]
18 else:
19 text_node = info_node.firstChild
20 value = text_node.data.strip()
21 if value == '':
22 return
23 if name in obj:
24 obj[name].append(value)
25 else:
26 obj[name] = [value]
27
28
29 def fetch_roles():
30 response = urllib2.urlopen("http://www.w3.org/WAI/ARIA/schemata/aria-1.rdf", timeout=5)
lushnikov 2016/08/23 17:23:51 do you intend to run this script as a part of buil
aboxhall 2016/08/23 21:06:17 No, if anything it'd be manually run occasionally
lushnikov 2016/08/24 23:05:10 I see; can we put a clarifying comment in the begi
31 content = response.read()
32 tree = xml.dom.minidom.parseString(content)
33 roles = {}
34 for role_node in tree.getElementsByTagName('owl:Class'):
35 role = {}
36 for info_node in role_node.childNodes:
37 if info_node.nodeType != xml.dom.minidom.Node.ELEMENT_NODE:
38 continue
39 if info_node.tagName == 'rdfs:subClassOf':
40 add_array_property(role, 'superclasses', info_node)
41 elif info_node.tagName == 'role:supportedState':
42 add_array_property(role, 'supportedAttributes', info_node)
43 elif info_node.tagName == 'role:requiredState':
44 add_array_property(role, 'requiredAttributes', info_node)
45 elif info_node.tagName == 'role:scope':
46 add_array_property(role, 'scope', info_node)
47 elif info_node.tagName == 'role:mustContain':
48 add_array_property(role, 'mustContain', info_node)
49 elif info_node.tagName == 'role:nameFrom':
50 add_array_property(role, 'nameFrom', info_node)
51 roles[role_node.getAttribute('rdf:ID')] = role
52 return roles
53
54
55 def fetch_attributes():
56 xs = 'http://www.w3.org/2001/XMLSchema'
57 response = urllib2.urlopen("https://www.w3.org/MarkUp/SCHEMA/aria-attributes -1.xsd", timeout=5)
58 content = response.read()
59 tree = xml.dom.minidom.parseString(content)
60 attributes = {}
61 for attribute_node in tree.getElementsByTagNameNS(xs, 'attribute'):
62 attribute = {}
63 if attribute_node.hasAttribute('type'):
64 attribute['type'] = attribute_node.getAttribute('type').split(':')[- 1]
65 else:
66 type_node = attribute_node.getElementsByTagNameNS(xs, 'simpleType')[ 0]
67 restriction_node = type_node.getElementsByTagNameNS(xs, 'restriction ')[0]
68 attribute['type'] = restriction_node.getAttribute('base').split(':') [-1]
69 attribute['enum'] = []
70 for enum in restriction_node.getElementsByTagNameNS(xs, 'enumeration '):
71 attribute['enum'].append(enum.getAttribute('value'))
72 if attribute_node.hasAttribute('default'):
73 attribute['default'] = attribute_node.getAttribute('default')
74 attributes[attribute_node.getAttribute('name')] = attribute
75 return attributes
76
77
78 def main(_):
aboxhall 2016/08/22 18:47:07 Not sure whether to commit this file or not.
79 aria = {}
80 aria['roles'] = fetch_roles()
81 aria['attributes'] = fetch_attributes()
82
83 print json.dumps(aria, sort_keys=True, indent=4)
84
85 if __name__ == '__main__':
86 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698