| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # This file is part of the Adblock Plus website, | |
| 2 # Copyright (C) 2006-2015 Eyeo GmbH | |
| 3 # | |
| 4 # Adblock Plus is free software: you can redistribute it and/or modify | |
| 5 # it under the terms of the GNU General Public License version 3 as | |
| 6 # published by the Free Software Foundation. | |
| 7 # | |
| 8 # Adblock Plus is distributed in the hope that it will be useful, | |
| 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 11 # GNU General Public License for more details. | |
| 12 # | |
| 13 # You should have received a copy of the GNU General Public License | |
| 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | |
| 15 | |
| 16 import re, warnings | |
| 17 | |
| 18 TYPE_REGEXP = r"(?:arrayof\s+)?\w+" | |
| 19 | |
| 20 def parse_interface(interface_items): | |
| 21 parsed = [] | |
| 22 for key, value in interface_items.iteritems(): | |
| 23 if "(" in key: | |
| 24 # Item is a method | |
| 25 match = re.match(r"^\s*(%s)\s+(\S+)\s*\(\s*([^\)]*)\s*\)\s*$" % TYPE_REGEX P, key) | |
| 26 if not match: | |
| 27 warnings.warn("Skipped malformed method: '%s'" % key) | |
| 28 continue | |
| 29 return_type, property_name, argument_string = match.groups() | |
| 30 arguments = [] | |
| 31 if "version" in value: | |
| 32 property_version = value["version"] | |
| 33 else: | |
| 34 property_version = "" | |
|
Wladimir Palant
2015/02/24 20:19:40
Nit: how about:
property_version = value.get("v
kzar
2015/02/26 19:50:17
Done.
| |
| 35 if argument_string: | |
| 36 for argument in argument_string.split(","): | |
| 37 if argument.strip(): | |
| 38 match = re.match(r"^\s*(%s)\s+(\S+)\s*$" % TYPE_REGEXP, argument) | |
| 39 if not match: | |
| 40 warnings.warn("Skipped malformed argument: '%s'" % argument) | |
| 41 continue | |
| 42 argument_type, argument_name = match.groups() | |
| 43 arguments.append({ | |
| 44 "name": argument_name, | |
| 45 "type": argument_type | |
| 46 }) | |
| 47 parsed.append({ | |
| 48 "type": "method", | |
| 49 "name": property_name, | |
| 50 "version": property_version, | |
| 51 "return_type": return_type, | |
| 52 "arguments": arguments | |
| 53 }) | |
| 54 else: | |
| 55 # Item is a property | |
| 56 match = re.match(r"^\s*(readonly\s+)?(%s)\s+(\S+)\s*$" % TYPE_REGEXP, key) | |
| 57 if not match: | |
| 58 warnings.warn("Skipped malformed property: '%s'" % key) | |
| 59 continue | |
| 60 property_modifier, property_type, property_name = match.groups() | |
| 61 parsed.append({ | |
| 62 "type": property_type, | |
| 63 "name": property_name, | |
| 64 "modifier": property_modifier or "" | |
| 65 }) | |
| 66 parsed.sort(key=lambda x: x["name"]) | |
| 67 return parsed | |
| OLD | NEW |