@@ -115,21 +115,21 @@ def add_anchors(self, anchor, status=None):
115115 if ('\n anchor "%s"' % anchor ).encode ('ASCII' ) not in status :
116116 self ._add_anchor_rule (self .PF_PASS , anchor .encode ('ASCII' ))
117117
118- def _add_anchor_rule (self , type , name , pr = None ):
118+ def _add_anchor_rule (self , kind , name , pr = None ):
119119 if pr is None :
120120 pr = self .pfioc_rule ()
121121
122122 memmove (addressof (pr ) + self .ANCHOR_CALL_OFFSET , name ,
123- min (self .MAXPATHLEN , len (name ))) # anchor_call = name
123+ min (self .MAXPATHLEN , len (name ))) # anchor_call = name
124124 memmove (addressof (pr ) + self .RULE_ACTION_OFFSET ,
125- struct .pack ('I' , type ), 4 ) # rule.action = type
125+ struct .pack ('I' , kind ), 4 ) # rule.action = kind
126126
127127 memmove (addressof (pr ) + self .ACTION_OFFSET , struct .pack (
128- 'I' , self .PF_CHANGE_GET_TICKET ), 4 ) # action = PF_CHANGE_GET_TICKET
128+ 'I' , self .PF_CHANGE_GET_TICKET ), 4 ) # action = PF_CHANGE_GET_TICKET
129129 ioctl (pf_get_dev (), pf .DIOCCHANGERULE , pr )
130130
131131 memmove (addressof (pr ) + self .ACTION_OFFSET , struct .pack (
132- 'I' , self .PF_CHANGE_ADD_TAIL ), 4 ) # action = PF_CHANGE_ADD_TAIL
132+ 'I' , self .PF_CHANGE_ADD_TAIL ), 4 ) # action = PF_CHANGE_ADD_TAIL
133133 ioctl (pf_get_dev (), pf .DIOCCHANGERULE , pr )
134134
135135 @staticmethod
@@ -176,9 +176,6 @@ class pfioc_natlook(Structure):
176176 freebsd .pfioc_natlook = pfioc_natlook
177177 return freebsd
178178
179- def __init__ (self ):
180- super (FreeBsd , self ).__init__ ()
181-
182179 def enable (self ):
183180 returncode = ssubprocess .call (['kldload' , 'pf' ])
184181 super (FreeBsd , self ).enable ()
@@ -197,14 +194,14 @@ def add_anchors(self, anchor):
197194 self ._add_anchor_rule (self .PF_RDR , anchor .encode ('ASCII' ))
198195 super (FreeBsd , self ).add_anchors (anchor , status = status )
199196
200- def _add_anchor_rule (self , type , name ):
201- pr = self .pfioc_rule ()
197+ def _add_anchor_rule (self , kind , name , pr = None ):
198+ pr = pr or self .pfioc_rule ()
202199 ppa = self .pfioc_pooladdr ()
203200
204201 ioctl (pf_get_dev (), self .DIOCBEGINADDRS , ppa )
205202 # pool ticket
206203 memmove (addressof (pr ) + self .POOL_TICKET_OFFSET , ppa [4 :8 ], 4 )
207- super (FreeBsd , self )._add_anchor_rule (type , name , pr = pr )
204+ super (FreeBsd , self )._add_anchor_rule (kind , name , pr = pr )
208205
209206 def add_rules (self , anchor , includes , port , dnsport , nslist , family ):
210207 inet_version = self ._inet_version (family )
@@ -224,7 +221,7 @@ def add_rules(self, anchor, includes, port, dnsport, nslist, family):
224221 for exclude , subnet in includes
225222 ]
226223
227- if len ( nslist ) > 0 :
224+ if nslist :
228225 tables .append (
229226 b'table <dns_servers> {%s}' %
230227 b',' .join ([ns [1 ].encode ("ASCII" ) for ns in nslist ]))
@@ -294,7 +291,7 @@ def add_rules(self, anchor, includes, port, dnsport, nslist, family):
294291 for exclude , subnet in includes
295292 ]
296293
297- if len ( nslist ) > 0 :
294+ if nslist :
298295 tables .append (
299296 b'table <dns_servers> {%s}' %
300297 b',' .join ([ns [1 ].encode ("ASCII" ) for ns in nslist ]))
@@ -440,24 +437,21 @@ def get_tcp_dstip(self, sock):
440437
441438 return sock .getsockname ()
442439
443- def setup_firewall (self , port , dnsport , nslist , family , subnets , udp , user ):
444- tables = []
445- translating_rules = []
446- filtering_rules = []
447-
440+ def setup_firewall (self , port , dnsport , nslist , family , subnets , udp ,
441+ user ):
448442 if family not in [socket .AF_INET , socket .AF_INET6 ]:
449443 raise Exception (
450444 'Address family "%s" unsupported by pf method_name'
451445 % family_to_string (family ))
452446 if udp :
453447 raise Exception ("UDP not supported by pf method_name" )
454448
455- if len ( subnets ) > 0 :
449+ if subnets :
456450 includes = []
457451 # If a given subnet is both included and excluded, list the
458452 # exclusion first; the table will ignore the second, opposite
459453 # definition
460- for f , swidth , sexclude , snet , fport , lport \
454+ for _ , swidth , sexclude , snet , fport , lport \
461455 in sorted (subnets , key = subnet_weight , reverse = True ):
462456 includes .append ((sexclude , b"%s/%d%s" % (
463457 snet .encode ("ASCII" ),
0 commit comments