| OLD | NEW |
| (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 """ |
| 8 Scrapes ARIA attributes from online resources. |
| 9 To be run by hand if and when these change. |
| 10 """ |
| 11 |
| 12 import json |
| 13 import urllib2 |
| 14 import xml.dom.minidom |
| 15 |
| 16 import sys |
| 17 |
| 18 |
| 19 def add_array_property(obj, name, info_node): |
| 20 value = '' |
| 21 if info_node.hasAttribute('rdf:resource'): |
| 22 value = info_node.getAttribute('rdf:resource').split('#')[-1] |
| 23 else: |
| 24 text_node = info_node.firstChild |
| 25 value = text_node.data.strip() |
| 26 if value == '': |
| 27 return |
| 28 if name in obj: |
| 29 obj[name].append(value) |
| 30 else: |
| 31 obj[name] = [value] |
| 32 |
| 33 |
| 34 def fetch_roles(): |
| 35 response = urllib2.urlopen("http://www.w3.org/WAI/ARIA/schemata/aria-1.rdf",
timeout=5) |
| 36 content = response.read() |
| 37 tree = xml.dom.minidom.parseString(content) |
| 38 roles = {} |
| 39 for role_node in tree.getElementsByTagName('owl:Class'): |
| 40 role = {} |
| 41 for info_node in role_node.childNodes: |
| 42 if info_node.nodeType != xml.dom.minidom.Node.ELEMENT_NODE: |
| 43 continue |
| 44 if info_node.tagName == 'rdfs:subClassOf': |
| 45 add_array_property(role, 'superclasses', info_node) |
| 46 elif info_node.tagName == 'role:supportedState': |
| 47 add_array_property(role, 'supportedAttributes', info_node) |
| 48 elif info_node.tagName == 'role:requiredState': |
| 49 add_array_property(role, 'requiredAttributes', info_node) |
| 50 elif info_node.tagName == 'role:scope': |
| 51 add_array_property(role, 'scope', info_node) |
| 52 elif info_node.tagName == 'role:mustContain': |
| 53 add_array_property(role, 'mustContain', info_node) |
| 54 elif info_node.tagName == 'role:nameFrom': |
| 55 add_array_property(role, 'nameFrom', info_node) |
| 56 roles[role_node.getAttribute('rdf:ID')] = role |
| 57 return roles |
| 58 |
| 59 |
| 60 def fetch_attributes(): |
| 61 xs = 'http://www.w3.org/2001/XMLSchema' |
| 62 response = urllib2.urlopen("https://www.w3.org/MarkUp/SCHEMA/aria-attributes
-1.xsd", timeout=5) |
| 63 content = response.read() |
| 64 tree = xml.dom.minidom.parseString(content) |
| 65 attributes = {} |
| 66 for attribute_node in tree.getElementsByTagNameNS(xs, 'attribute'): |
| 67 attribute = {} |
| 68 if attribute_node.hasAttribute('type'): |
| 69 attribute['type'] = attribute_node.getAttribute('type').split(':')[-
1] |
| 70 else: |
| 71 type_node = attribute_node.getElementsByTagNameNS(xs, 'simpleType')[
0] |
| 72 restriction_node = type_node.getElementsByTagNameNS(xs, 'restriction
')[0] |
| 73 attribute['type'] = restriction_node.getAttribute('base').split(':')
[-1] |
| 74 attribute['enum'] = [] |
| 75 for enum in restriction_node.getElementsByTagNameNS(xs, 'enumeration
'): |
| 76 attribute['enum'].append(enum.getAttribute('value')) |
| 77 if attribute_node.hasAttribute('default'): |
| 78 attribute['default'] = attribute_node.getAttribute('default') |
| 79 attributes[attribute_node.getAttribute('name')] = attribute |
| 80 return attributes |
| 81 |
| 82 |
| 83 def main(_): |
| 84 aria = {} |
| 85 aria['roles'] = fetch_roles() |
| 86 aria['attributes'] = fetch_attributes() |
| 87 |
| 88 print json.dumps(aria, sort_keys=True, indent=4) |
| 89 |
| 90 if __name__ == '__main__': |
| 91 sys.exit(main(sys.argv)) |
| OLD | NEW |