text
stringlengths
1
93.6k
"""
a = RE_DUAL_CIDR.split(str)
if len(a) == 3:
str, cidr6 = a[0], int(a[1])
else:
cidr6 = None
a = RE_CIDR.split(str)
if len(a) == 3:
str, cidr = a[0], int(a[1])
else:
cidr = None
a = str.split(':', 1)
if len(a) < 2:
str = str.lower()
if str == 'exists': d = None
return str, d, cidr, cidr6
return a[0].lower(), a[1], cidr, cidr6
def reverse_dots(name):
"""Reverse dotted IP addresses or domain names.
Example:
>>> reverse_dots('192.168.0.145')
'145.0.168.192'
>>> reverse_dots('email.example.com')
'com.example.email'
"""
a = name.split('.')
a.reverse()
return '.'.join(a)
def domainmatch(ptrs, domainsuffix):
"""grep for a given domain suffix against a list of validated PTR
domain names.
Examples:
>>> domainmatch(['FOO.COM'], 'foo.com')
1
>>> domainmatch(['moo.foo.com'], 'FOO.COM')
1
>>> domainmatch(['moo.bar.com'], 'foo.com')
0
"""
domainsuffix = domainsuffix.lower()
for ptr in ptrs:
ptr = ptr.lower()
if ptr == domainsuffix or ptr.endswith('.' + domainsuffix):
return True
return False
def expand_one(expansion, s, joiner=None):
"""Expand one macro
Examples:
>>> expand_one('example.com','r')
'com.example'
>>> expand_one('strong-bad','-','.')
'strong.bad'
"""
if not s: return expansion
ln, reverse, delimiters = RE_ARGS.split(s)[1:4]
if not delimiters:
delimiters = '.'
expansion = split(expansion, delimiters, joiner)
if reverse: expansion.reverse()
if ln: expansion = expansion[-int(ln)*2+1:]
return ''.join(expansion)
def split(str, delimiters, joiner=None):
"""Split a string into pieces by a set of delimiter characters. The
resulting list is delimited by joiner, or the original delimiter if
joiner is not specified.
Examples:
>>> split('192.168.0.45', '.')
['192', '.', '168', '.', '0', '.', '45']
>>> split('terry@wayforward.net', '@.')
['terry', '@', 'wayforward', '.', 'net']
>>> split('terry@wayforward.net', '@.', '.')
['terry', '.', 'wayforward', '.', 'net']
"""
result, element = [], ''
for c in str:
if c in delimiters:
result.append(element)
element = ''
if joiner:
result.append(joiner)
else:
result.append(c)
else: