mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
remove to_ascii
this is a no-op on python 3.
This commit is contained in:
parent
08fa96f030
commit
65902e08c3
@ -45,7 +45,6 @@ from synapse.util.async_helpers import Linearizer
|
|||||||
from synapse.util.caches import intern_string
|
from synapse.util.caches import intern_string
|
||||||
from synapse.util.caches.descriptors import cached, cachedInlineCallbacks, cachedList
|
from synapse.util.caches.descriptors import cached, cachedInlineCallbacks, cachedList
|
||||||
from synapse.util.metrics import Measure
|
from synapse.util.metrics import Measure
|
||||||
from synapse.util.stringutils import to_ascii
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -179,7 +178,7 @@ class RoomMemberWorkerStore(EventsWorkerStore):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
txn.execute(sql, (room_id, Membership.JOIN))
|
txn.execute(sql, (room_id, Membership.JOIN))
|
||||||
return [to_ascii(r[0]) for r in txn]
|
return [r[0] for r in txn]
|
||||||
|
|
||||||
@cached(max_entries=100000)
|
@cached(max_entries=100000)
|
||||||
def get_room_summary(self, room_id):
|
def get_room_summary(self, room_id):
|
||||||
@ -223,7 +222,7 @@ class RoomMemberWorkerStore(EventsWorkerStore):
|
|||||||
txn.execute(sql, (room_id,))
|
txn.execute(sql, (room_id,))
|
||||||
res = {}
|
res = {}
|
||||||
for count, membership in txn:
|
for count, membership in txn:
|
||||||
summary = res.setdefault(to_ascii(membership), MemberSummary([], count))
|
summary = res.setdefault(membership, MemberSummary([], count))
|
||||||
|
|
||||||
# we order by membership and then fairly arbitrarily by event_id so
|
# we order by membership and then fairly arbitrarily by event_id so
|
||||||
# heroes are consistent
|
# heroes are consistent
|
||||||
@ -255,11 +254,11 @@ class RoomMemberWorkerStore(EventsWorkerStore):
|
|||||||
# 6 is 5 (number of heroes) plus 1, in case one of them is the calling user.
|
# 6 is 5 (number of heroes) plus 1, in case one of them is the calling user.
|
||||||
txn.execute(sql, (room_id, Membership.JOIN, Membership.INVITE, 6))
|
txn.execute(sql, (room_id, Membership.JOIN, Membership.INVITE, 6))
|
||||||
for user_id, membership, event_id in txn:
|
for user_id, membership, event_id in txn:
|
||||||
summary = res[to_ascii(membership)]
|
summary = res[membership]
|
||||||
# we will always have a summary for this membership type at this
|
# we will always have a summary for this membership type at this
|
||||||
# point given the summary currently contains the counts.
|
# point given the summary currently contains the counts.
|
||||||
members = summary.members
|
members = summary.members
|
||||||
members.append((to_ascii(user_id), to_ascii(event_id)))
|
members.append((user_id, event_id))
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@ -584,13 +583,9 @@ class RoomMemberWorkerStore(EventsWorkerStore):
|
|||||||
ev_entry = event_map.get(event_id)
|
ev_entry = event_map.get(event_id)
|
||||||
if ev_entry:
|
if ev_entry:
|
||||||
if ev_entry.event.membership == Membership.JOIN:
|
if ev_entry.event.membership == Membership.JOIN:
|
||||||
users_in_room[to_ascii(ev_entry.event.state_key)] = ProfileInfo(
|
users_in_room[ev_entry.event.state_key] = ProfileInfo(
|
||||||
display_name=to_ascii(
|
display_name=ev_entry.event.content.get("displayname", None),
|
||||||
ev_entry.event.content.get("displayname", None)
|
avatar_url=ev_entry.event.content.get("avatar_url", None),
|
||||||
),
|
|
||||||
avatar_url=to_ascii(
|
|
||||||
ev_entry.event.content.get("avatar_url", None)
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
missing_member_event_ids.append(event_id)
|
missing_member_event_ids.append(event_id)
|
||||||
@ -604,9 +599,9 @@ class RoomMemberWorkerStore(EventsWorkerStore):
|
|||||||
if event is not None and event.type == EventTypes.Member:
|
if event is not None and event.type == EventTypes.Member:
|
||||||
if event.membership == Membership.JOIN:
|
if event.membership == Membership.JOIN:
|
||||||
if event.event_id in member_event_ids:
|
if event.event_id in member_event_ids:
|
||||||
users_in_room[to_ascii(event.state_key)] = ProfileInfo(
|
users_in_room[event.state_key] = ProfileInfo(
|
||||||
display_name=to_ascii(event.content.get("displayname", None)),
|
display_name=event.content.get("displayname", None),
|
||||||
avatar_url=to_ascii(event.content.get("avatar_url", None)),
|
avatar_url=event.content.get("avatar_url", None),
|
||||||
)
|
)
|
||||||
|
|
||||||
return users_in_room
|
return users_in_room
|
||||||
|
@ -29,7 +29,6 @@ from synapse.storage.database import Database
|
|||||||
from synapse.storage.state import StateFilter
|
from synapse.storage.state import StateFilter
|
||||||
from synapse.util.caches import intern_string
|
from synapse.util.caches import intern_string
|
||||||
from synapse.util.caches.descriptors import cached, cachedList
|
from synapse.util.caches.descriptors import cached, cachedList
|
||||||
from synapse.util.stringutils import to_ascii
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -185,9 +184,7 @@ class StateGroupWorkerStore(EventsWorkerStore, SQLBaseStore):
|
|||||||
(room_id,),
|
(room_id,),
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {(intern_string(r[0]), intern_string(r[1])): r[2] for r in txn}
|
||||||
(intern_string(r[0]), intern_string(r[1])): to_ascii(r[2]) for r in txn
|
|
||||||
}
|
|
||||||
|
|
||||||
return self.db.runInteraction(
|
return self.db.runInteraction(
|
||||||
"get_current_state_ids", _get_current_state_ids_txn
|
"get_current_state_ids", _get_current_state_ids_txn
|
||||||
|
@ -19,8 +19,7 @@ import re
|
|||||||
import string
|
import string
|
||||||
from collections import Iterable
|
from collections import Iterable
|
||||||
|
|
||||||
import six
|
from six import PY3
|
||||||
from six import PY2, PY3
|
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
|
|
||||||
from synapse.api.errors import Codes, SynapseError
|
from synapse.api.errors import Codes, SynapseError
|
||||||
@ -68,23 +67,6 @@ def is_ascii(s):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def to_ascii(s):
|
|
||||||
"""Converts a string to ascii if it is ascii, otherwise leave it alone.
|
|
||||||
|
|
||||||
If given None then will return None.
|
|
||||||
"""
|
|
||||||
if PY3:
|
|
||||||
return s
|
|
||||||
|
|
||||||
if s is None:
|
|
||||||
return None
|
|
||||||
|
|
||||||
try:
|
|
||||||
return s.encode("ascii")
|
|
||||||
except UnicodeEncodeError:
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
def assert_valid_client_secret(client_secret):
|
def assert_valid_client_secret(client_secret):
|
||||||
"""Validate that a given string matches the client_secret regex defined by the spec"""
|
"""Validate that a given string matches the client_secret regex defined by the spec"""
|
||||||
if client_secret_regex.match(client_secret) is None:
|
if client_secret_regex.match(client_secret) is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user