22 lines
620 B
Python
22 lines
620 B
Python
import logging
|
|
|
|
|
|
def record_transformer(public_suffixes):
|
|
def transform(record):
|
|
name = record["name"]
|
|
suffixes = [suffix for suffix in public_suffixes if name.endswith(suffix)]
|
|
suffix = suffixes[0] if suffixes else None
|
|
|
|
if suffix:
|
|
logging.debug(f"stripping {suffix} from {name} as it is a public suffix")
|
|
|
|
record["name"] = name[: -len(suffix)]
|
|
record["internal"] = "off"
|
|
return record
|
|
|
|
logging.debug(f"keeping {name} as it is not a public suffix")
|
|
record["internal"] = "on"
|
|
return record
|
|
|
|
return transform
|