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

Make the rest of the .iterwhatever go away #3562

Merged
merged 6 commits into from
Jul 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added changelog.d/3562.misc
Empty file.
6 changes: 4 additions & 2 deletions synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import os
import sys

from six import iteritems

from twisted.application import service
from twisted.internet import defer, reactor
from twisted.web.resource import EncodingResourceWrapper, NoResource
Expand Down Expand Up @@ -442,7 +444,7 @@ def phone_stats_home():
stats["total_nonbridged_users"] = total_nonbridged_users

daily_user_type_results = yield hs.get_datastore().count_daily_user_type()
for name, count in daily_user_type_results.iteritems():
for name, count in iteritems(daily_user_type_results):
stats["daily_user_type_" + name] = count

room_count = yield hs.get_datastore().get_room_count()
Expand All @@ -453,7 +455,7 @@ def phone_stats_home():
stats["daily_messages"] = yield hs.get_datastore().count_daily_messages()

r30_results = yield hs.get_datastore().count_r30_users()
for name, count in r30_results.iteritems():
for name, count in iteritems(r30_results):
stats["r30_users_" + name] = count

daily_sent_messages = yield hs.get_datastore().count_daily_sent_messages()
Expand Down
4 changes: 3 additions & 1 deletion synapse/app/synctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import sys
import time

from six import iteritems

import yaml

SYNAPSE = [sys.executable, "-B", "-m", "synapse.app.homeserver"]
Expand Down Expand Up @@ -173,7 +175,7 @@ def main():
os.environ["SYNAPSE_CACHE_FACTOR"] = str(cache_factor)

cache_factors = config.get("synctl_cache_factors", {})
for cache_name, factor in cache_factors.iteritems():
for cache_name, factor in iteritems(cache_factors):
os.environ["SYNAPSE_CACHE_FACTOR_" + cache_name.upper()] = str(factor)

worker_configfiles = []
Expand Down
4 changes: 3 additions & 1 deletion synapse/events/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from six import iteritems

from frozendict import frozendict

from twisted.internet import defer
Expand Down Expand Up @@ -159,7 +161,7 @@ def _encode_state_dict(state_dict):

return [
(etype, state_key, v)
for (etype, state_key), v in state_dict.iteritems()
for (etype, state_key), v in iteritems(state_dict)
]


Expand Down
18 changes: 9 additions & 9 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import sys

import six
from six import iteritems
from six.moves import http_client
from six import iteritems, itervalues
from six.moves import http_client, zip

from signedjson.key import decode_verify_key_bytes
from signedjson.sign import verify_signed_json
Expand Down Expand Up @@ -731,7 +731,7 @@ def get_domains_from_state(state):
"""
joined_users = [
(state_key, int(event.depth))
for (e_type, state_key), event in state.iteritems()
for (e_type, state_key), event in iteritems(state)
if e_type == EventTypes.Member
and event.membership == Membership.JOIN
]
Expand All @@ -748,7 +748,7 @@ def get_domains_from_state(state):
except Exception:
pass

return sorted(joined_domains.iteritems(), key=lambda d: d[1])
return sorted(joined_domains.items(), key=lambda d: d[1])

curr_domains = get_domains_from_state(curr_state)

Expand Down Expand Up @@ -811,7 +811,7 @@ def try_backfill(domains):
tried_domains = set(likely_domains)
tried_domains.add(self.server_name)

event_ids = list(extremities.iterkeys())
event_ids = list(extremities.keys())

logger.debug("calling resolve_state_groups in _maybe_backfill")
resolve = logcontext.preserve_fn(
Expand All @@ -827,15 +827,15 @@ def try_backfill(domains):
states = dict(zip(event_ids, [s.state for s in states]))

state_map = yield self.store.get_events(
[e_id for ids in states.itervalues() for e_id in ids.itervalues()],
[e_id for ids in itervalues(states) for e_id in itervalues(ids)],
get_prev_content=False
)
states = {
key: {
k: state_map[e_id]
for k, e_id in state_dict.iteritems()
for k, e_id in iteritems(state_dict)
if e_id in state_map
} for key, state_dict in states.iteritems()
} for key, state_dict in iteritems(states)
}

for e_id, _ in sorted_extremeties_tuple:
Expand Down Expand Up @@ -1515,7 +1515,7 @@ def _handle_new_events(self, origin, event_infos, backfilled=False):
yield self.store.persist_events(
[
(ev_info["event"], context)
for ev_info, context in itertools.izip(event_infos, contexts)
for ev_info, context in zip(event_infos, contexts)
],
backfilled=backfilled,
)
Expand Down
6 changes: 3 additions & 3 deletions synapse/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import logging
from collections import namedtuple

from six import iteritems, itervalues
from six import iteritems, iterkeys, itervalues

from frozendict import frozendict

Expand Down Expand Up @@ -647,7 +647,7 @@ def resolve_events_with_factory(state_sets, event_map, state_map_factory):
for event_id in event_ids
)
if event_map is not None:
needed_events -= set(event_map.iterkeys())
needed_events -= set(iterkeys(event_map))

logger.info("Asking for %d conflicted events", len(needed_events))

Expand All @@ -668,7 +668,7 @@ def resolve_events_with_factory(state_sets, event_map, state_map_factory):
new_needed_events = set(itervalues(auth_events))
new_needed_events -= needed_events
if event_map is not None:
new_needed_events -= set(event_map.iterkeys())
new_needed_events -= set(iterkeys(event_map))

logger.info("Asking for %d auth events", len(new_needed_events))

Expand Down
19 changes: 10 additions & 9 deletions synapse/visibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import itertools

import logging
import operator

import six
from six import iteritems, itervalues
from six.moves import map

from twisted.internet import defer

Expand Down Expand Up @@ -221,7 +222,7 @@ def allowed(event):
return event

# check each event: gives an iterable[None|EventBase]
filtered_events = itertools.imap(allowed, events)
filtered_events = map(allowed, events)

# remove the None entries
filtered_events = filter(operator.truth, filtered_events)
Expand Down Expand Up @@ -261,7 +262,7 @@ def redact_disallowed(event, state):
# membership states for the requesting server to determine
# if the server is either in the room or has been invited
# into the room.
for ev in state.itervalues():
for ev in itervalues(state):
if ev.type != EventTypes.Member:
continue
try:
Expand Down Expand Up @@ -295,7 +296,7 @@ def redact_disallowed(event, state):
)

visibility_ids = set()
for sids in event_to_state_ids.itervalues():
for sids in itervalues(event_to_state_ids):
hist = sids.get((EventTypes.RoomHistoryVisibility, ""))
if hist:
visibility_ids.add(hist)
Expand All @@ -308,7 +309,7 @@ def redact_disallowed(event, state):
event_map = yield store.get_events(visibility_ids)
all_open = all(
e.content.get("history_visibility") in (None, "shared", "world_readable")
for e in event_map.itervalues()
for e in itervalues(event_map)
)

if all_open:
Expand Down Expand Up @@ -346,7 +347,7 @@ def redact_disallowed(event, state):
#
state_key_to_event_id_set = {
e
for key_to_eid in six.itervalues(event_to_state_ids)
for key_to_eid in itervalues(event_to_state_ids)
for e in key_to_eid.items()
}

Expand All @@ -369,10 +370,10 @@ def include(typ, state_key):
event_to_state = {
e_id: {
key: event_map[inner_e_id]
for key, inner_e_id in key_to_eid.iteritems()
for key, inner_e_id in iteritems(key_to_eid)
if inner_e_id in event_map
}
for e_id, key_to_eid in event_to_state_ids.iteritems()
for e_id, key_to_eid in iteritems(event_to_state_ids)
}

defer.returnValue([
Expand Down
3 changes: 1 addition & 2 deletions tests/test_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ def post_json(destination, path, data, headers=None, timeout=0):
)
self.assertEqual(self.successResultOf(extrem)[0], "$join:test.serv")

@unittest.DEBUG
def test_cant_hide_past_history(self):
"""
If you send a message, you must be able to provide the direct
Expand Down Expand Up @@ -178,7 +177,7 @@ def get_json(destination, path, args, headers=None):
for x, y in d.items()
if x == ("m.room.member", "@us:test")
],
"auth_chain_ids": d.values(),
"auth_chain_ids": list(d.values()),
}
)

Expand Down