mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Merge pull request #3151 from NotAFile/py3-xrange-1
Move more xrange to six
This commit is contained in:
commit
683149c1f9
@ -19,6 +19,8 @@ import itertools
|
|||||||
import logging
|
import logging
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
from six.moves import range
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
from synapse.api.constants import Membership
|
from synapse.api.constants import Membership
|
||||||
@ -413,7 +415,7 @@ class FederationClient(FederationBase):
|
|||||||
|
|
||||||
batch_size = 20
|
batch_size = 20
|
||||||
missing_events = list(missing_events)
|
missing_events = list(missing_events)
|
||||||
for i in xrange(0, len(missing_events), batch_size):
|
for i in range(0, len(missing_events), batch_size):
|
||||||
batch = set(missing_events[i:i + batch_size])
|
batch = set(missing_events[i:i + batch_size])
|
||||||
|
|
||||||
deferreds = [
|
deferreds = [
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
|
from six.moves import range
|
||||||
|
|
||||||
from ._base import BaseHandler
|
from ._base import BaseHandler
|
||||||
|
|
||||||
from synapse.api.constants import (
|
from synapse.api.constants import (
|
||||||
@ -200,7 +202,7 @@ class RoomListHandler(BaseHandler):
|
|||||||
step = len(rooms_to_scan) if len(rooms_to_scan) != 0 else 1
|
step = len(rooms_to_scan) if len(rooms_to_scan) != 0 else 1
|
||||||
|
|
||||||
chunk = []
|
chunk = []
|
||||||
for i in xrange(0, len(rooms_to_scan), step):
|
for i in range(0, len(rooms_to_scan), step):
|
||||||
batch = rooms_to_scan[i:i + step]
|
batch = rooms_to_scan[i:i + step]
|
||||||
logger.info("Processing %i rooms for result", len(batch))
|
logger.info("Processing %i rooms for result", len(batch))
|
||||||
yield concurrently_execute(
|
yield concurrently_execute(
|
||||||
|
@ -22,6 +22,8 @@ from synapse.storage import background_updates
|
|||||||
from synapse.storage._base import SQLBaseStore
|
from synapse.storage._base import SQLBaseStore
|
||||||
from synapse.util.caches.descriptors import cached, cachedInlineCallbacks
|
from synapse.util.caches.descriptors import cached, cachedInlineCallbacks
|
||||||
|
|
||||||
|
from six.moves import range
|
||||||
|
|
||||||
|
|
||||||
class RegistrationWorkerStore(SQLBaseStore):
|
class RegistrationWorkerStore(SQLBaseStore):
|
||||||
@cached()
|
@cached()
|
||||||
@ -469,7 +471,7 @@ class RegistrationStore(RegistrationWorkerStore,
|
|||||||
match = regex.search(user_id)
|
match = regex.search(user_id)
|
||||||
if match:
|
if match:
|
||||||
found.add(int(match.group(1)))
|
found.add(int(match.group(1)))
|
||||||
for i in xrange(len(found) + 1):
|
for i in range(len(found) + 1):
|
||||||
if i not in found:
|
if i not in found:
|
||||||
return i
|
return i
|
||||||
|
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
import logging
|
import logging
|
||||||
from synapse.config.appservice import load_appservices
|
from synapse.config.appservice import load_appservices
|
||||||
|
|
||||||
|
from six.moves import range
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -58,7 +60,7 @@ def run_upgrade(cur, database_engine, config, *args, **kwargs):
|
|||||||
|
|
||||||
for as_id, user_ids in owned.items():
|
for as_id, user_ids in owned.items():
|
||||||
n = 100
|
n = 100
|
||||||
user_chunks = (user_ids[i:i + 100] for i in xrange(0, len(user_ids), n))
|
user_chunks = (user_ids[i:i + 100] for i in range(0, len(user_ids), n))
|
||||||
for chunk in user_chunks:
|
for chunk in user_chunks:
|
||||||
cur.execute(
|
cur.execute(
|
||||||
database_engine.convert_param_style(
|
database_engine.convert_param_style(
|
||||||
|
@ -47,6 +47,8 @@ from synapse.storage.engines import PostgresEngine, Sqlite3Engine
|
|||||||
import abc
|
import abc
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from six.moves import range
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -196,7 +198,7 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
|
|||||||
|
|
||||||
results = {}
|
results = {}
|
||||||
room_ids = list(room_ids)
|
room_ids = list(room_ids)
|
||||||
for rm_ids in (room_ids[i:i + 20] for i in xrange(0, len(room_ids), 20)):
|
for rm_ids in (room_ids[i:i + 20] for i in range(0, len(room_ids), 20)):
|
||||||
res = yield make_deferred_yieldable(defer.gatherResults([
|
res = yield make_deferred_yieldable(defer.gatherResults([
|
||||||
run_in_background(
|
run_in_background(
|
||||||
self.get_room_events_stream_for_room,
|
self.get_room_events_stream_for_room,
|
||||||
|
@ -22,6 +22,8 @@ from twisted.internet import defer
|
|||||||
import simplejson as json
|
import simplejson as json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from six.moves import range
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -98,7 +100,7 @@ class TagsWorkerStore(AccountDataWorkerStore):
|
|||||||
|
|
||||||
batch_size = 50
|
batch_size = 50
|
||||||
results = []
|
results = []
|
||||||
for i in xrange(0, len(tag_ids), batch_size):
|
for i in range(0, len(tag_ids), batch_size):
|
||||||
tags = yield self.runInteraction(
|
tags = yield self.runInteraction(
|
||||||
"get_all_updated_tag_content",
|
"get_all_updated_tag_content",
|
||||||
get_tag_content,
|
get_tag_content,
|
||||||
|
@ -27,6 +27,8 @@ from contextlib import contextmanager
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from six.moves import range
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -158,13 +160,13 @@ def concurrently_execute(func, args, limit):
|
|||||||
def _concurrently_execute_inner():
|
def _concurrently_execute_inner():
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
yield func(it.next())
|
yield func(next(it))
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return logcontext.make_deferred_yieldable(defer.gatherResults([
|
return logcontext.make_deferred_yieldable(defer.gatherResults([
|
||||||
run_in_background(_concurrently_execute_inner)
|
run_in_background(_concurrently_execute_inner)
|
||||||
for _ in xrange(limit)
|
for _ in range(limit)
|
||||||
], consumeErrors=True)).addErrback(unwrapFirstError)
|
], consumeErrors=True)).addErrback(unwrapFirstError)
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
from six.moves import range
|
||||||
|
|
||||||
_string_with_symbols = (
|
_string_with_symbols = (
|
||||||
string.digits + string.ascii_letters + ".,;:^&*-_+=#~@"
|
string.digits + string.ascii_letters + ".,;:^&*-_+=#~@"
|
||||||
@ -22,12 +23,12 @@ _string_with_symbols = (
|
|||||||
|
|
||||||
|
|
||||||
def random_string(length):
|
def random_string(length):
|
||||||
return ''.join(random.choice(string.ascii_letters) for _ in xrange(length))
|
return ''.join(random.choice(string.ascii_letters) for _ in range(length))
|
||||||
|
|
||||||
|
|
||||||
def random_string_with_symbols(length):
|
def random_string_with_symbols(length):
|
||||||
return ''.join(
|
return ''.join(
|
||||||
random.choice(_string_with_symbols) for _ in xrange(length)
|
random.choice(_string_with_symbols) for _ in range(length)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
from six.moves import range
|
||||||
|
|
||||||
|
|
||||||
class _Entry(object):
|
class _Entry(object):
|
||||||
__slots__ = ["end_key", "queue"]
|
__slots__ = ["end_key", "queue"]
|
||||||
@ -68,7 +70,7 @@ class WheelTimer(object):
|
|||||||
# Add empty entries between the end of the current list and when we want
|
# Add empty entries between the end of the current list and when we want
|
||||||
# to insert. This ensures there are no gaps.
|
# to insert. This ensures there are no gaps.
|
||||||
self.entries.extend(
|
self.entries.extend(
|
||||||
_Entry(key) for key in xrange(last_key, then_key + 1)
|
_Entry(key) for key in range(last_key, then_key + 1)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.entries[-1].queue.append(obj)
|
self.entries[-1].queue.append(obj)
|
||||||
|
Loading…
Reference in New Issue
Block a user