0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-06-01 10:18:54 +02:00

Compile the regex's used in ASes

This commit is contained in:
Erik Johnston 2017-03-28 13:03:50 +01:00
parent dc56a6b8c8
commit 650f0e69f2
2 changed files with 8 additions and 10 deletions

View file

@ -124,22 +124,18 @@ class ApplicationService(object):
raise ValueError(
"Expected bool for 'exclusive' in ns '%s'" % ns
)
if not isinstance(regex_obj.get("regex"), basestring):
regex = regex_obj.get("regex")
if isinstance(regex, basestring):
regex_obj["regex"] = re.compile(regex)
else:
raise ValueError(
"Expected string for 'regex' in ns '%s'" % ns
)
return namespaces
def _matches_regex(self, test_string, namespace_key, return_obj=False):
if not isinstance(test_string, basestring):
logger.error(
"Expected a string to test regex against, but got %s",
test_string
)
return False
for regex_obj in self.namespaces[namespace_key]:
if re.match(regex_obj["regex"], test_string):
if regex_obj["regex"].match(test_string):
if return_obj:
return regex_obj
return True

View file

@ -19,10 +19,12 @@ from twisted.internet import defer
from mock import Mock
from tests import unittest
import re
def _regex(regex, exclusive=True):
return {
"regex": regex,
"regex": re.compile(regex),
"exclusive": exclusive
}