Skip to content

Instantly share code, notes, and snippets.

View tommynyquist's full-sized avatar

Tommy Nyquist tommynyquist

View GitHub Profile
@tommynyquist
tommynyquist / fuzzy_public_suffix_list_matching.py
Last active December 13, 2015 21:59
Example fuzzy Public Suffix List matching
def parse(domain, psl):
fuzzy_hosts = ('www', 'mobile', 'm')
domain_parts = domain.split('.')
if domain_parts[0] in fuzzy_hosts:
domain_parts = domain_parts[1:]
if '.'.join(domain_parts[1:]) in psl:
return sorted(['.'.join(domain_parts)] + \
['.'.join([fuzzy_host] + domain_parts) for fuzzy_host in fuzzy_hosts])
else:
return sorted([domain])