def matches(self, message): if message.contact.fields: contact_value = normalize(message.contact.fields.get(self.key, "")) for value in self.values: if value == contact_value: return True return False
def matches(self, message): text = normalize(message.text) def keyword_check(w): return lambda: bool(regex.search(r'\b' + w + r'\b', text, flags=regex.UNICODE | regex.V0)) checks = [keyword_check(keyword) for keyword in self.keywords] return self.quantifier.evaluate(checks)
def matches(self, message): text = normalize(message.text) def keyword_check(w): return lambda: bool(regex.search(r"\b" + w + r"\b", text, flags=regex.UNICODE | regex.V0)) checks = [keyword_check(keyword) for keyword in self.keywords] return self.quantifier.evaluate(checks)
def clean_keywords(self): keywords = parse_csv(self.cleaned_data['keywords']) clean_keywords = [] for keyword in keywords: clean_keyword = normalize(keyword) if not ContainsTest.is_valid_keyword(keyword): raise forms.ValidationError(_("Invalid keyword: %s") % keyword) clean_keywords.append(clean_keyword) return ', '.join(clean_keywords)
def clean_keywords(self): keywords = parse_csv(self.cleaned_data['keywords']) clean_keywords = [] for keyword in keywords: clean_keyword = normalize(keyword) if len(keyword) < Label.KEYWORD_MIN_LENGTH: raise forms.ValidationError(_("Keywords must be at least %d characters long") % Label.KEYWORD_MIN_LENGTH) if not Label.is_valid_keyword(keyword): raise forms.ValidationError(_("Invalid keyword: %s") % keyword) clean_keywords.append(clean_keyword) return ','.join(clean_keywords)
def __init__(self, key, values): self.key = key self.values = [normalize(v) for v in values]
def __init__(self, keywords, quantifier): self.keywords = [normalize(word) for word in keywords] self.quantifier = quantifier