summary refs log tree commit diff
path: root/synapse/metrics/metric.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-05-02 17:27:27 +0100
committerErik Johnston <erik@matrix.org>2018-05-02 17:27:27 +0100
commita41117c63b4e7ef2021fb59cb521c77d72f2bf70 (patch)
treef6e7da633dcb3f856ad1ecd60b51628427d01e71 /synapse/metrics/metric.py
parentEscape label values in prometheus metrics (diff)
downloadsynapse-a41117c63b4e7ef2021fb59cb521c77d72f2bf70.tar.xz
Make _escape_character take MatchObject
Diffstat (limited to 'synapse/metrics/metric.py')
-rw-r--r--synapse/metrics/metric.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/synapse/metrics/metric.py b/synapse/metrics/metric.py
index 1a09e417c9..fbba94e633 100644
--- a/synapse/metrics/metric.py
+++ b/synapse/metrics/metric.py
@@ -301,9 +301,17 @@ class MemoryUsageMetric(object):
         ]
 
 
-def _escape_character(c):
+def _escape_character(m):
     """Replaces a single character with its escape sequence.
+
+    Args:
+        m (re.MatchObject): A match object whose first group is the single
+            character to replace
+
+    Returns:
+        str
     """
+    c = m.group(1)
     if c == "\\":
         return "\\\\"
     elif c == "\"":
@@ -316,4 +324,4 @@ def _escape_character(c):
 def _escape_label_value(value):
     """Takes a label value and escapes quotes, newlines and backslashes
     """
-    return re.sub(r"([\n\"\\])", lambda m: _escape_character(m.group(1)), value)
+    return re.sub(r"([\n\"\\])", _escape_character, value)