Use six.moves.filter when filtering out from MXID
Python 2's filter() function and Python 3's don't return the same type when processing a string (respectively str and filter), therefore use six's compatibility mapping (which resolves to itertools.ifilter() if using Python2), then generate a string from the filtered list, in order to ensure consistent behaviour between Python 2 and Python 3.
This commit is contained in:
@@ -17,6 +17,7 @@ import string
|
||||
from collections import namedtuple
|
||||
|
||||
import attr
|
||||
from six.moves import filter
|
||||
|
||||
from synapse.api.errors import SynapseError
|
||||
|
||||
@@ -240,7 +241,8 @@ def strip_invalid_mxid_characters(localpart):
|
||||
Returns:
|
||||
localpart (basestring): the localpart having been stripped
|
||||
"""
|
||||
return filter(lambda c: c in mxid_localpart_allowed_characters, localpart)
|
||||
filtered = filter(lambda c: c in mxid_localpart_allowed_characters, localpart)
|
||||
return "".join(list(filtered))
|
||||
|
||||
|
||||
UPPER_CASE_PATTERN = re.compile(b"[A-Z_]")
|
||||
|
||||
Reference in New Issue
Block a user