colors: Do not use [] indexing on re.match objects

This indexing (i.e. __getitem__) introduced in Python 3.5 as an alias of
the group method, so using it breaks this plugin on older Python
versions. In particular, messages containing urls cannot be sent and
result in an exception:

	File "matrix/colors.py", line 106, in <lambda>
	    lambda m: "a" * len(m[0]),
	TypeError: '_sre.SRE_Match' object has no attribute '__getitem__'

This commit replaces the use of the index operation / __getitem__ with
the group method, which is equivalent but supported on all python
versions.
This commit is contained in:
Matthijs Kooijman 2021-04-03 22:20:57 +02:00
parent ef09292005
commit d24e6ce6a9

View file

@ -103,7 +103,7 @@ class Formatted(object):
# for the indices to be correct. # for the indices to be correct.
escaped_masked = re.sub( escaped_masked = re.sub(
r"\\[\\*_`]|(?:" + url_regex + ")", r"\\[\\*_`]|(?:" + url_regex + ")",
lambda m: "a" * len(m[0]), lambda m: "a" * len(m.group(0)),
line line
) )