Files
django-ai-blocker/ai_blocker/ualist_backers.py

23 lines
504 B
Python

import re
from abc import ABC, abstractmethod
from django.conf import settings
class UAList(ABC):
@abstractmethod
def get_ua_list(self) -> list[str]:
raise NotImplemented
def __contains__(self, item):
list = self.get_ua_list()
pattern = "|".join(list)
return re.search(pattern, item) is not None
class ConfigBackedUAList(UAList):
def get_ua_list(self) -> list[str]:
return list(getattr(getattr(settings, "AI_BLOCKER_CONF"), "ua_list", []))