@@ -35,10 +35,10 @@ def warn(s):
3535def fail (s ):
3636 sys .stdout .write ("failure: %s\n " % s )
3737
38- def test_not_anchored (tree , fi , fm , to ):
38+ def test_not_anchored (tree , filename , from_attrib , to ):
3939 # Rules not anchored to the beginning of a line.
4040 """The 'from' rule is not anchored to beginning of line using the ^ symbol."""
41- for f in fm :
41+ for f in from_attrib :
4242 if not f or f [0 ] != "^" :
4343 return False
4444 return True
@@ -47,10 +47,10 @@ def test_not_anchored(tree, fi, fm, to):
4747xpath_exlusion_pattern = etree .XPath ("/ruleset/exclusion/@pattern" )
4848xpath_cookie_pattern = etree .XPath ("/ruleset/securecookie/@host" )
4949
50- def test_bad_regexp (tree , fi , fm , to ):
50+ def test_bad_regexp (tree , filename , from_attrib , to ):
5151 # Rules with invalid regular expressions.
5252 """The 'from' rule contains an invalid extended regular expression."""
53- patterns = fm + xpath_exlusion_pattern (tree ) + xpath_cookie_pattern (tree )
53+ patterns = from_attrib + xpath_exlusion_pattern (tree ) + xpath_cookie_pattern (tree )
5454 for pat in patterns :
5555 try :
5656 re .compile (pat )
@@ -59,25 +59,25 @@ def test_bad_regexp(tree, fi, fm, to):
5959 return True
6060
6161xpath_rule = etree .XPath ("/ruleset/rule" )
62- def test_missing_to (tree , fi , fm , to ):
62+ def test_missing_to (tree , filename , from_attrib , to ):
6363 # Rules that are terminated before setting 'to'.
6464 # These cases are probably either due to a misplaced
6565 # rule end or intended to be different elements.
6666 """Rule is missing a 'to' value."""
6767 for rule in xpath_rule (tree ):
6868 if not rule .get ("to" ):
69- warn ("'to' attribute missing in %s. " % fi )
69+ warn ("'to' attribute missing in %s. " % filename )
7070 warn ("Misplaced end or misnamed element?" )
7171 return False
7272 return True
7373
74- def test_unescaped_dots (tree , fi , fm , to ):
74+ def test_unescaped_dots (tree , filename , from_attrib , to ):
7575 # Rules containing unescaped dots outside of brackets and before slash.
7676 # Note: this is meant to require example\.com instead of example.com,
7777 # but it also forbids things like .* which usually ought to be replaced
7878 # with something like ([^/:@\.]+)
7979 """The 'from' rule contains unescaped period in regular expression. Try escaping it with a backslash."""
80- for f in fm :
80+ for f in from_attrib :
8181 escaped = False
8282 bracketed = False
8383 s = re .sub ("^\^https?://" , "" , f )
@@ -96,15 +96,15 @@ def test_unescaped_dots(tree, fi, fm, to):
9696 escaped = False
9797 return True
9898
99- def test_space_in_to (tree , fi , fm , to ):
99+ def test_space_in_to (tree , filename , from_attrib , to ):
100100 # Rules where the to pattern contains a space.
101101 """The 'to' rule contains a space."""
102102 for t in to :
103103 if ' ' in t :
104104 return False
105105 return True
106106
107- def test_unencrypted_to (tree , fi , fm , to ):
107+ def test_unencrypted_to (tree , filename , from_attrib , to ):
108108 # Rules that redirect to something other than https or http.
109109 # This used to test for http: but testing for lack of https: will
110110 # catch more kinds of mistakes.
@@ -116,13 +116,13 @@ def test_unencrypted_to(tree, fi, fm, to):
116116 if to [:6 ] != "https:" and to [:5 ] != "http:" :
117117 return False
118118 elif to [:5 ] == "http:" and downgrade :
119- warn ("downgrade rule in %s redirects to http." % fi )
119+ warn ("downgrade rule in %s redirects to http." % filename )
120120 elif to [:5 ] == "http:" :
121- fail ("non-downgrade rule in %s redirects to http." % fi )
121+ fail ("non-downgrade rule in %s redirects to http." % filename )
122122 return False
123123 return True
124124
125- def test_backslash_in_to (tree , fi , fm , to ):
125+ def test_backslash_in_to (tree , filename , from_attrib , to ):
126126 # Rules containing backslashes in to pattern.
127127 """The 'to' rule contains a backslash."""
128128 for t in to :
@@ -132,7 +132,7 @@ def test_backslash_in_to(tree, fi, fm, to):
132132
133133RE_TRAILING_SLASH = re .compile ("//.*/" )
134134
135- def test_no_trailing_slash (tree , fi , fm , to ):
135+ def test_no_trailing_slash (tree , filename , from_attrib , to ):
136136 # Rules not containing trailing slash in from or to pattern.
137137 """Rule omits forward slash after host name."""
138138 for r in xpath_rule (tree ):
@@ -145,7 +145,7 @@ def test_no_trailing_slash(tree, fi, fm, to):
145145
146146printable_characters = set (map (chr , list (range (32 , 127 ))))
147147
148- def test_non_ascii (tree , fi , fm , to ):
148+ def test_non_ascii (tree , filename , from_attrib , to ):
149149 # Rules containing non-printable characters.
150150 """Rule contains non-printable character in 'to' pattern."""
151151 for t in to :
@@ -171,8 +171,8 @@ def nomes_all(where=sys.argv[1:]):
171171 yield i
172172 elif os .path .isdir (i ):
173173 for r , d , f in os .walk (i ):
174- for fi in f :
175- yield os .path .join (r , fi )
174+ for filename in f :
175+ yield os .path .join (r , filename )
176176
177177tests = [test_not_anchored ,
178178 test_bad_regexp ,
@@ -210,10 +210,10 @@ def nomes_all(where=sys.argv[1:]):
210210 fail ("unnamed ruleset" )
211211 continue
212212 rf = xpath_ruleset_name (tree )[0 ]
213- fm = xpath_from (tree )
213+ from_attrib = xpath_from (tree )
214214 to = xpath_to (tree )
215215 for test in tests :
216- if not test (tree , rf , fm = fm , to = to ):
216+ if not test (tree , rf , from_attrib = from_attrib , to = to ):
217217 failure = 1
218218 fail ("%s failed test: %s" % (rf , test .__doc__ ))
219219
0 commit comments