text
stringlengths 1
93.6k
|
|---|
self.lookups = 0
|
# New processing limit in RFC 7208, section 4.6.4
|
self.void_lookups = 0
|
# strict can be False, True, or 2 (numeric) for harsh
|
self.strict = strict
|
self.timeout = timeout
|
self.querytime = querytime # Default to not using a global check
|
# timelimit since this is an RFC 4408 MAY
|
if querytime > 0:
|
self.timeout = querytime
|
self.timer = 0
|
self.ipaddr = None
|
if i:
|
self.set_ip(i)
|
# Document bits of the object model not set up here:
|
# self.i = string, expanded dot notation, suitable for PTR lookups
|
# self.c = string, human readable form of the connect IP address
|
# single letter lowercase variable names (e.g. self.i) are used for SPF macros
|
# For IPv4, self.i = self.c, but not in IPv6
|
# self.iplist = list of IPv4/6 addresses that would pass, collected
|
# when list or list6 is passed as 'i'
|
# self.addr = ipaddr/ipaddress object representing the connect IP
|
self.default_modifier = True
|
self.verbose = verbose
|
self.authserv = None # Only used in A-R header generation tests
|
def log(self,mech,d,spf):
|
print('%s: %s "%s"'%(mech,d,spf))
|
def set_ip(self, i):
|
"Set connect ip, and ip6 or ip4 mode."
|
self.iplist = False
|
if i.lower() == 'list':
|
self.iplist = []
|
ip6 = False
|
elif i.lower() == 'list6':
|
self.iplist = []
|
ip6 = True
|
else:
|
try:
|
try:
|
self.ipaddr = ipaddress.ip_address(i)
|
except AttributeError:
|
self.ipaddr = ipaddress.IPAddress(i)
|
except ValueError as x:
|
raise PermError(str(x))
|
if self.ipaddr.version == 6:
|
if self.ipaddr.ipv4_mapped:
|
self.ipaddr = ipaddress.IPv4Address(self.ipaddr.ipv4_mapped)
|
ip6 = False
|
else:
|
ip6 = True
|
else:
|
ip6 = False
|
self.c = str(self.ipaddr)
|
# NOTE: self.A is not lowercase, so isn't a macro. See query.expand()
|
if ip6:
|
self.A = 'AAAA'
|
self.v = 'ip6'
|
if self.ipaddr:
|
self.i = '.'.join(list(self.ipaddr.exploded.replace(':','').upper()))
|
self.cidrmax = 128
|
else:
|
self.A = 'A'
|
self.v = 'in-addr'
|
if self.ipaddr:
|
self.i = self.ipaddr.exploded
|
self.cidrmax = 32
|
def set_default_explanation(self, exp):
|
exps = self.exps
|
defexps = self.defexps
|
for i in 'softfail', 'fail', 'permerror':
|
exps[i] = exp
|
defexps[i] = exp
|
def set_explanation(self, exp):
|
exps = self.exps
|
for i in 'softfail', 'fail', 'permerror':
|
exps[i] = exp
|
# Compute p macro only if needed
|
def getp(self):
|
if not self.p:
|
p = self.validated_ptrs()
|
if not p:
|
self.p = "unknown"
|
elif self.d in p:
|
self.p = self.d
|
else:
|
sfx = '.' + self.d
|
for d in p:
|
if d.endswith(sfx):
|
self.p = d
|
break
|
else:
|
self.p = p[0]
|
return self.p
|
def best_guess(self, spf=DEFAULT_SPF):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.