 Issue 5636796054503424:
  Issue 1170 - [adblockplus.org Anwiki to CMS migration] Migrate content  (Closed)
    
  
    Issue 5636796054503424:
  Issue 1170 - [adblockplus.org Anwiki to CMS migration] Migrate content  (Closed) 
  | Index: filters/parse_interface.py | 
| diff --git a/filters/parse_interface.py b/filters/parse_interface.py | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..17137516134f3e219c0642a05575f1be06a57c89 | 
| --- /dev/null | 
| +++ b/filters/parse_interface.py | 
| @@ -0,0 +1,40 @@ | 
| +import re | 
| + | 
| +def parse_interface(interfaces): | 
| 
Wladimir Palant
2014/09/18 20:33:04
Nit: I think what it gets as parameter isn't inter
 
kzar
2014/09/19 11:28:06
Done.
 | 
| + parsed = [] | 
| + for property_key, property in interfaces.iteritems(): | 
| 
Wladimir Palant
2014/09/18 20:33:04
Nit: I think that simple key, value as names would
 
kzar
2014/09/19 11:28:06
Done.
 | 
| + if property_key.find("(") > -1: | 
| 
Wladimir Palant
2014/09/18 20:33:04
Nit: this can be written as simply |"(" in propert
 
kzar
2014/09/19 11:28:06
Done.
 | 
| + match = re.match("^(arrayof\W+\w+|\w+)\W+(\w+)[\W\(]+([^\)]*)[\W\)]+$", property_key) | 
| 
Wladimir Palant
2014/09/18 20:33:04
You generally want to use r"foo" rather than "foo"
 
kzar
2014/09/19 11:28:06
Done.
 | 
| + if not match: | 
| + continue | 
| 
Wladimir Palant
2014/09/18 20:33:04
Just dropping the line without any message is a gr
 
kzar
2014/09/19 11:28:06
Done.
 | 
| + return_type, property_name, argument_string = match.groups() | 
| + arguments = [] | 
| + if "version" in property: | 
| + property_version = property["version"] | 
| + else: | 
| + property_version = "" | 
| 
Wladimir Palant
2014/09/18 20:33:04
Nit: Use None instead of empty string here?
 
kzar
2014/09/19 11:28:06
I think empty strings are more useful for template
 | 
| + if argument_string: | 
| + for i, argument in enumerate(argument_string.split(",")): | 
| 
Wladimir Palant
2014/09/18 20:33:04
Nit: Why use enumerate() here? Doesn't seem to be
 
kzar
2014/09/19 11:28:06
Done.
 | 
| + parts = argument.split(" ") | 
| 
Wladimir Palant
2014/09/18 20:33:04
How about:
  match = re.match(r"^\s*(%s)\s+(\w+)\
 
kzar
2014/09/19 11:28:06
Done.
 | 
| + argument_name = parts[-1] | 
| + argument_type = " ".join(parts[:-1]) | 
| + arguments.append({ | 
| + "name": argument_name, | 
| + "type": argument_type | 
| + }) | 
| + parsed.append({ | 
| + "type": "method", | 
| + "name": property_name, | 
| + "version": property_version, | 
| + "return_type": return_type, | 
| + "arguments": arguments, | 
| + }) | 
| + else: | 
| + parts = property_key.split() | 
| 
Wladimir Palant
2014/09/18 20:33:04
I'd prefer:
  match = re.match(r"^\s*(readonly\s+
 
kzar
2014/09/19 11:28:06
Done.
 | 
| + property = { } | 
| 
Wladimir Palant
2014/09/18 20:33:04
Nit: no space between the brackets.
 
kzar
2014/09/19 11:28:06
Done.
 | 
| + property["type"], property["name"] = parts[-2:] | 
| + if len(parts) == 3: | 
| + property["modifier"] = parts[0] | 
| 
Wladimir Palant
2014/09/18 20:33:04
I think using temporary variables like you've done
 
kzar
2014/09/19 11:28:06
Done.
 | 
| + parsed.append(property) | 
| + parsed = sorted(parsed, key=lambda x: x["name"]) | 
| 
Wladimir Palant
2014/09/18 20:33:04
Please use parse.sort() that will sort the list in
 
kzar
2014/09/19 11:28:06
Done.
 | 
| + return parsed |