Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Make _escape_character take MatchObject
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed May 2, 2018
1 parent 32015e1 commit a41117c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions synapse/metrics/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,17 @@ def render(self):
]


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 == "\"":
Expand All @@ -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)

0 comments on commit a41117c

Please sign in to comment.