1515import xml .etree .ElementTree
1616
1717def normalize (f ):
18- """
19- OSX and Linux filesystems encode composite characters differently in
20- filenames. We should normalize to NFC: http://unicode.org/reports/tr15/
21- """
22- f = unicodedata .normalize ("NFC" , f )
23- return f
18+ """
19+ OSX and Linux filesystems encode composite characters differently in
20+ filenames. We should normalize to NFC: http://unicode.org/reports/tr15/
21+ """
22+ f = unicodedata .normalize ("NFC" , f )
23+ return f
2424
2525# commandline arguments parsing (nobody use it, though)
2626parser = argparse .ArgumentParser (description = "Merge rulesets" )
@@ -36,50 +36,50 @@ def normalize(f):
3636
3737# Under git bash, sed -i issues errors and sets the file "read-only".
3838if os .path .isfile (ofn ):
39- os .system ("chmod u+w " + ofn )
39+ os .system ("chmod u+w " + ofn )
4040
4141# Library (JSON Object)
4242library = []
4343
4444# Parse XML ruleset and construct JSON library
4545print (" * Parsing XML ruleset and constructing JSON library..." )
4646for filename in sorted (files ):
47- tree = xml .etree .ElementTree .parse (filename )
48- root = tree .getroot ()
47+ tree = xml .etree .ElementTree .parse (filename )
48+ root = tree .getroot ()
4949
50- ruleset = {}
50+ ruleset = {}
5151
52- for attr in root .attrib :
53- ruleset [attr ] = root .attrib [attr ]
52+ for attr in root .attrib :
53+ ruleset [attr ] = root .attrib [attr ]
5454
55- for child in root :
56- if child .tag in ["target" , "rule" , "securecookie" , "exclusion" ]:
57- if child .tag not in ruleset :
58- ruleset [child .tag ] = []
59- else :
60- continue
55+ for child in root :
56+ if child .tag in ["target" , "rule" , "securecookie" , "exclusion" ]:
57+ if child .tag not in ruleset :
58+ ruleset [child .tag ] = []
59+ else :
60+ continue
6161
62- if child .tag == "target" :
63- ruleset ["target" ].append (child .attrib ["host" ])
62+ if child .tag == "target" :
63+ ruleset ["target" ].append (child .attrib ["host" ])
6464
65- elif child .tag == "rule" :
66- ru = {}
67- ru ["from" ] = child .attrib ["from" ]
68- ru ["to" ] = child .attrib ["to" ]
65+ elif child .tag == "rule" :
66+ ru = {}
67+ ru ["from" ] = child .attrib ["from" ]
68+ ru ["to" ] = child .attrib ["to" ]
6969
70- ruleset ["rule" ].append (ru )
70+ ruleset ["rule" ].append (ru )
7171
72- elif child .tag == "securecookie" :
73- sc = {}
74- sc ["host" ] = child .attrib ["host" ]
75- sc ["name" ] = child .attrib ["name" ]
72+ elif child .tag == "securecookie" :
73+ sc = {}
74+ sc ["host" ] = child .attrib ["host" ]
75+ sc ["name" ] = child .attrib ["name" ]
7676
77- ruleset ["securecookie" ].append (sc )
77+ ruleset ["securecookie" ].append (sc )
7878
79- elif child .tag == "exclusion" :
80- ruleset ["exclusion" ].append (child .attrib ["pattern" ])
79+ elif child .tag == "exclusion" :
80+ ruleset ["exclusion" ].append (child .attrib ["pattern" ])
8181
82- library .append (ruleset );
82+ library .append (ruleset );
8383
8484# Write to default.rulesets
8585print (" * Writing JSON library to %s" % ofn )
0 commit comments