Newer
Older

Michał Pogoda
committed
from src.detections import (
Detection,
EmailDetection,
)
from src.string_replacements import replace_and_update
from src.replacers.interface import ReplacerInterface
import random
import string
return "".join(random.choice(string.ascii_letters) for _ in range(char_num))
class EmailReplacer(ReplacerInterface):
def __init__(self):
pass
def replace(
self, text: str, detections: List[Tuple[int, int, Detection]]
) -> Tuple[str, List[Tuple[int, int, Detection]]]:
for item in detections:
start, end, detection = item

Michał Pogoda
committed
if isinstance(detection, EmailDetection):
if text[start:end] not in already_replaced:
already_replaced[text[start:end]] = random_email()
replacements.append((start, end, already_replaced[text[start:end]]))
else:
not_processed.append(item)
return replace_and_update(text, replacements, not_processed)