summary refs log tree commit diff
path: root/synapse/util
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-10-17 16:14:04 +0100
committerErik Johnston <erik@matrix.org>2018-10-19 10:22:45 +0100
commit084046456ec88588779a62f9378c1a8e911bfc7c (patch)
tree12403c9d27e5cb8906be070ac54fb8f667233b2e /synapse/util
parentNewsfile (diff)
downloadsynapse-084046456ec88588779a62f9378c1a8e911bfc7c.tar.xz
Add config option to control alias creation
Diffstat (limited to 'synapse/util')
-rw-r--r--synapse/util/__init__.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/synapse/util/__init__.py b/synapse/util/__init__.py
index 9a8fae0497..163e4b35ff 100644
--- a/synapse/util/__init__.py
+++ b/synapse/util/__init__.py
@@ -14,6 +14,7 @@
 # limitations under the License.
 
 import logging
+import re
 from itertools import islice
 
 import attr
@@ -138,3 +139,23 @@ def log_failure(failure, msg, consumeErrors=True):
 
     if not consumeErrors:
         return failure
+
+
+def glob_to_regex(glob):
+    """Converts a glob to a compiled regex object
+
+    Args:
+        glob (str)
+
+    Returns:
+        re.RegexObject
+    """
+    res = ''
+    for c in glob:
+        if c == '*':
+            res = res + '.*'
+        elif c == '?':
+            res = res + '.'
+        else:
+            res = res + re.escape(c)
+    return re.compile(res + "\\Z", re.IGNORECASE)