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

Commit

Permalink
Merge pull request #3106 from NotAFile/py3-six-itervalues-1
Browse files Browse the repository at this point in the history
Use six.itervalues in some places
  • Loading branch information
richvdh authored Apr 20, 2018
2 parents 8dc4a61 + 36c59ce commit dc875d2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
3 changes: 2 additions & 1 deletion synapse/api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import logging

import simplejson as json
from six import iteritems

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -297,7 +298,7 @@ def cs_error(msg, code=Codes.UNKNOWN, **kwargs):
A dict representing the error response JSON.
"""
err = {"error": msg, "errcode": code}
for key, value in kwargs.iteritems():
for key, value in iteritems(kwargs):
err[key] = value
return err

Expand Down
4 changes: 3 additions & 1 deletion synapse/app/synchrotron.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
from twisted.internet import defer, reactor
from twisted.web.resource import NoResource

from six import iteritems

logger = logging.getLogger("synapse.app.synchrotron")


Expand Down Expand Up @@ -211,7 +213,7 @@ def process_replication_rows(self, token, rows):

def get_currently_syncing_users(self):
return [
user_id for user_id, count in self.user_to_num_current_syncs.iteritems()
user_id for user_id, count in iteritems(self.user_to_num_current_syncs)
if count > 0
]

Expand Down
8 changes: 5 additions & 3 deletions synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
from synapse.util.caches.response_cache import ResponseCache
from synapse.util.logutils import log_function

from six import iteritems

# when processing incoming transactions, we try to handle multiple rooms in
# parallel, up to this limit.
TRANSACTION_CONCURRENCY_LIMIT = 10
Expand Down Expand Up @@ -425,9 +427,9 @@ def on_claim_client_keys(self, origin, content):
"Claimed one-time-keys: %s",
",".join((
"%s for %s:%s" % (key_id, user_id, device_id)
for user_id, user_keys in json_result.iteritems()
for device_id, device_keys in user_keys.iteritems()
for key_id, _ in device_keys.iteritems()
for user_id, user_keys in iteritems(json_result)
for device_id, device_keys in iteritems(user_keys)
for key_id, _ in iteritems(device_keys)
)),
)

Expand Down
14 changes: 8 additions & 6 deletions synapse/federation/send_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

import logging

from six import itervalues, iteritems

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -122,7 +124,7 @@ def _clear_queue_before_pos(self, position_to_delete):

user_ids = set(
user_id
for uids in self.presence_changed.itervalues()
for uids in itervalues(self.presence_changed)
for user_id in uids
)

Expand Down Expand Up @@ -276,7 +278,7 @@ def get_replication_rows(self, from_token, to_token, limit, federation_ack=None)
# stream position.
keyed_edus = {self.keyed_edu_changed[k]: k for k in keys[i:j]}

for ((destination, edu_key), pos) in keyed_edus.iteritems():
for ((destination, edu_key), pos) in iteritems(keyed_edus):
rows.append((pos, KeyedEduRow(
key=edu_key,
edu=self.keyed_edu[(destination, edu_key)],
Expand Down Expand Up @@ -309,7 +311,7 @@ def get_replication_rows(self, from_token, to_token, limit, federation_ack=None)
j = keys.bisect_right(to_token) + 1
device_messages = {self.device_messages[k]: k for k in keys[i:j]}

for (destination, pos) in device_messages.iteritems():
for (destination, pos) in iteritems(device_messages):
rows.append((pos, DeviceRow(
destination=destination,
)))
Expand Down Expand Up @@ -528,19 +530,19 @@ def process_rows_for_federation(transaction_queue, rows):
if buff.presence:
transaction_queue.send_presence(buff.presence)

for destination, edu_map in buff.keyed_edus.iteritems():
for destination, edu_map in iteritems(buff.keyed_edus):
for key, edu in edu_map.items():
transaction_queue.send_edu(
edu.destination, edu.edu_type, edu.content, key=key,
)

for destination, edu_list in buff.edus.iteritems():
for destination, edu_list in iteritems(buff.edus):
for edu in edu_list:
transaction_queue.send_edu(
edu.destination, edu.edu_type, edu.content, key=None,
)

for destination, failure_list in buff.failures.iteritems():
for destination, failure_list in iteritems(buff.failures):
for failure in failure_list:
transaction_queue.send_failure(destination, failure)

Expand Down

0 comments on commit dc875d2

Please sign in to comment.