Remove raw string notation

Makes it fiddlier to add new domains, and is only needed to generate the
regular expression. Much cleaner to just insert them as part of
generating the regular expression.
This commit is contained in:
Chris Hill-Scott
2018-02-06 09:36:04 +00:00
parent 3e79ae1bfe
commit 156625a994

View File

@@ -439,42 +439,42 @@ class NotGovernmentDomain(Exception):
class GovernmentDomain: class GovernmentDomain:
domains = [ domains = [
r"gov\.uk", "gov.uk",
r"mod\.uk", "mod.uk",
r"mil\.uk", "mil.uk",
r"ddc-mod\.org", "ddc-mod.org",
r"slc\.co\.uk", "slc.co.uk",
r"gov\.scot", "gov.scot",
r"parliament\.uk", "parliament.uk",
r"nhs\.uk", "nhs.uk",
r"nhs\.net", "nhs.net",
r"police\.uk", "police.uk",
r"dclgdatamart\.co\.uk", "dclgdatamart.co.uk",
r"ucds\.email", "ucds.email",
r"naturalengland\.org\.uk", "naturalengland.org.uk",
r"hmcts\.net", "hmcts.net",
r"scotent\.co\.uk", "scotent.co.uk",
r"assembly\.wales", "assembly.wales",
r"cjsm\.net", "cjsm.net",
r"cqc\.org\.uk", "cqc.org.uk",
r"bl\.uk", "bl.uk",
r"stfc\.ac\.uk", "stfc.ac.uk",
r"wmfs\.net", "wmfs.net",
r"bbsrc\.ac\.uk", "bbsrc.ac.uk",
r"acas\.org\.uk", "acas.org.uk",
r"gov\.wales", "gov.wales",
r"biglotteryfund\.org\.uk", "biglotteryfund.org.uk",
r"marinemanagement\.org\.uk", "marinemanagement.org.uk",
r"britishmuseum\.org", "britishmuseum.org",
r"derrystrabane\.com", "derrystrabane.com",
r"highwaysengland\.co\.uk", "highwaysengland.co.uk",
] ]
def __init__(self, email_address_or_domain): def __init__(self, email_address_or_domain):
for domain in self.domains: for domain in self.domains:
if re.search( if re.search(
r"[\.|@]({})$".format(domain), "[\.|@]({})$".format(domain.replace(".", "\.")),
email_address_or_domain.lower() email_address_or_domain.lower()
): ):
return return