mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-22 17:46:08 +03:00
Code-style fixes
This commit is contained in:
parent
697ab75a34
commit
b085fac735
11 changed files with 57 additions and 36 deletions
|
@ -658,7 +658,9 @@ class PresenceHandler(BaseHandler):
|
|||
|
||||
observers = set(self._remote_recvmap.get(user, set()))
|
||||
if observers:
|
||||
logger.debug(" | %d interested local observers %r", len(observers), observers)
|
||||
logger.debug(
|
||||
" | %d interested local observers %r", len(observers), observers
|
||||
)
|
||||
|
||||
rm_handler = self.homeserver.get_handlers().room_member_handler
|
||||
room_ids = yield rm_handler.get_rooms_for_user(user)
|
||||
|
|
|
@ -105,16 +105,19 @@ class RegistrationHandler(BaseHandler):
|
|||
# do it here.
|
||||
try:
|
||||
auth_user = UserID.from_string(user_id)
|
||||
identicon_resource = self.hs.get_resource_for_media_repository().getChildWithDefault("identicon", None)
|
||||
upload_resource = self.hs.get_resource_for_media_repository().getChildWithDefault("upload", None)
|
||||
media_repository = self.hs.get_resource_for_media_repository()
|
||||
identicon_resource = media_repository.getChildWithDefault("identicon", None)
|
||||
upload_resource = media_repository.getChildWithDefault("upload", None)
|
||||
identicon_bytes = identicon_resource.generate_identicon(user_id, 320, 320)
|
||||
content_uri = yield upload_resource.create_content(
|
||||
"image/png", None, identicon_bytes, len(identicon_bytes), auth_user
|
||||
)
|
||||
profile_handler = self.hs.get_handlers().profile_handler
|
||||
profile_handler.set_avatar_url(auth_user, auth_user, ("%s#auto" % content_uri))
|
||||
profile_handler.set_avatar_url(
|
||||
auth_user, auth_user, ("%s#auto" % (content_uri,))
|
||||
)
|
||||
except NotImplementedError:
|
||||
pass # make tests pass without messing around creating default avatars
|
||||
pass # make tests pass without messing around creating default avatars
|
||||
|
||||
defer.returnValue((user_id, token))
|
||||
|
||||
|
|
|
@ -170,8 +170,10 @@ class Pusher(object):
|
|||
return False
|
||||
if not display_name:
|
||||
return False
|
||||
return re.search("\b%s\b" % re.escape(display_name),
|
||||
ev['content']['body'], flags=re.IGNORECASE) is not None
|
||||
return re.search(
|
||||
"\b%s\b" % re.escape(display_name), ev['content']['body'],
|
||||
flags=re.IGNORECASE
|
||||
) is not None
|
||||
|
||||
elif condition['kind'] == 'room_member_count':
|
||||
if 'is' not in condition:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from synapse.push.rulekinds import PRIORITY_CLASS_MAP, PRIORITY_CLASS_INVERSE_MAP
|
||||
|
||||
|
||||
def list_with_base_rules(rawrules, user_name):
|
||||
ruleslist = []
|
||||
|
||||
|
@ -9,9 +10,9 @@ def list_with_base_rules(rawrules, user_name):
|
|||
if r['priority_class'] < current_prio_class:
|
||||
while r['priority_class'] < current_prio_class:
|
||||
ruleslist.extend(make_base_rules(
|
||||
user_name,
|
||||
PRIORITY_CLASS_INVERSE_MAP[current_prio_class])
|
||||
)
|
||||
user_name,
|
||||
PRIORITY_CLASS_INVERSE_MAP[current_prio_class]
|
||||
))
|
||||
current_prio_class -= 1
|
||||
|
||||
ruleslist.append(r)
|
||||
|
@ -19,8 +20,8 @@ def list_with_base_rules(rawrules, user_name):
|
|||
while current_prio_class > 0:
|
||||
ruleslist.extend(make_base_rules(
|
||||
user_name,
|
||||
PRIORITY_CLASS_INVERSE_MAP[current_prio_class])
|
||||
)
|
||||
PRIORITY_CLASS_INVERSE_MAP[current_prio_class]
|
||||
))
|
||||
current_prio_class -= 1
|
||||
|
||||
return ruleslist
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
PRIORITY_CLASS_MAP = {
|
||||
'underride': 1,
|
||||
'sender': 2,
|
||||
'room': 3,
|
||||
'content': 4,
|
||||
'override': 5,
|
||||
}
|
||||
'underride': 1,
|
||||
'sender': 2,
|
||||
'room': 3,
|
||||
'content': 4,
|
||||
'override': 5,
|
||||
}
|
||||
PRIORITY_CLASS_INVERSE_MAP = {v: k for k, v in PRIORITY_CLASS_MAP.items()}
|
||||
|
|
|
@ -19,10 +19,11 @@ REQUIREMENTS = {
|
|||
"pydenticon": ["pydenticon"],
|
||||
}
|
||||
|
||||
|
||||
def github_link(project, version, egg):
|
||||
return "https://github.com/%s/tarball/%s/#egg=%s" % (project, version, egg)
|
||||
|
||||
DEPENDENCY_LINKS=[
|
||||
DEPENDENCY_LINKS = [
|
||||
github_link(
|
||||
project="matrix-org/syutil",
|
||||
version="v0.0.2",
|
||||
|
@ -101,6 +102,7 @@ def check_requirements():
|
|||
% (dependency, file_path, version, required_version)
|
||||
)
|
||||
|
||||
|
||||
def list_requirements():
|
||||
result = []
|
||||
linked = []
|
||||
|
@ -111,7 +113,7 @@ def list_requirements():
|
|||
for requirement in REQUIREMENTS:
|
||||
is_linked = False
|
||||
for link in linked:
|
||||
if requirement.replace('-','_').startswith(link):
|
||||
if requirement.replace('-', '_').startswith(link):
|
||||
is_linked = True
|
||||
if not is_linked:
|
||||
result.append(requirement)
|
||||
|
|
|
@ -15,12 +15,17 @@
|
|||
|
||||
from twisted.internet import defer
|
||||
|
||||
from synapse.api.errors import SynapseError, Codes, UnrecognizedRequestError, NotFoundError, \
|
||||
StoreError
|
||||
from synapse.api.errors import (
|
||||
SynapseError, Codes, UnrecognizedRequestError, NotFoundError, StoreError
|
||||
)
|
||||
from .base import ClientV1RestServlet, client_path_pattern
|
||||
from synapse.storage.push_rule import InconsistentRuleException, RuleNotFoundException
|
||||
from synapse.storage.push_rule import (
|
||||
InconsistentRuleException, RuleNotFoundException
|
||||
)
|
||||
import synapse.push.baserules as baserules
|
||||
from synapse.push.rulekinds import PRIORITY_CLASS_MAP, PRIORITY_CLASS_INVERSE_MAP
|
||||
from synapse.push.rulekinds import (
|
||||
PRIORITY_CLASS_MAP, PRIORITY_CLASS_INVERSE_MAP
|
||||
)
|
||||
|
||||
import json
|
||||
|
||||
|
@ -105,7 +110,9 @@ class PushRuleRestServlet(ClientV1RestServlet):
|
|||
# we build up the full structure and then decide which bits of it
|
||||
# to send which means doing unnecessary work sometimes but is
|
||||
# is probably not going to make a whole lot of difference
|
||||
rawrules = yield self.hs.get_datastore().get_push_rules_for_user_name(user.to_string())
|
||||
rawrules = yield self.hs.get_datastore().get_push_rules_for_user_name(
|
||||
user.to_string()
|
||||
)
|
||||
|
||||
for r in rawrules:
|
||||
r["conditions"] = json.loads(r["conditions"])
|
||||
|
@ -383,6 +390,7 @@ def _namespaced_rule_id_from_spec(spec):
|
|||
def _rule_id_from_namespaced(in_rule_id):
|
||||
return in_rule_id.split('/')[-1]
|
||||
|
||||
|
||||
class InvalidRuleException(Exception):
|
||||
pass
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@ class PusherRestServlet(ClientV1RestServlet):
|
|||
pusher_pool = self.hs.get_pusherpool()
|
||||
|
||||
if ('pushkey' in content and 'app_id' in content
|
||||
and 'kind' in content and
|
||||
content['kind'] is None):
|
||||
and 'kind' in content and
|
||||
content['kind'] is None):
|
||||
yield pusher_pool.remove_pusher(
|
||||
content['app_id'], content['pushkey']
|
||||
)
|
||||
|
|
|
@ -40,7 +40,8 @@ class UploadResource(BaseMediaResource):
|
|||
return NOT_DONE_YET
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def create_content(self, media_type, upload_name, content, content_length, auth_user):
|
||||
def create_content(self, media_type, upload_name, content, content_length,
|
||||
auth_user):
|
||||
media_id = random_string(24)
|
||||
|
||||
fname = self.filepaths.local_media_filepath(media_id)
|
||||
|
|
|
@ -84,7 +84,7 @@ class PerformanceCounters(object):
|
|||
|
||||
def update(self, key, start_time, end_time=None):
|
||||
if end_time is None:
|
||||
end_time = time.time() * 1000;
|
||||
end_time = time.time() * 1000
|
||||
duration = end_time - start_time
|
||||
count, cum_time = self.current_counters.get(key, (0, 0))
|
||||
count += 1
|
||||
|
@ -588,7 +588,7 @@ class SQLBaseStore(object):
|
|||
"LIMIT 1 "
|
||||
)
|
||||
|
||||
start_time = time.time() * 1000;
|
||||
start_time = time.time() * 1000
|
||||
|
||||
txn.execute(sql, (event_id,))
|
||||
|
||||
|
@ -613,7 +613,7 @@ class SQLBaseStore(object):
|
|||
def _get_event_from_row_txn(self, txn, internal_metadata, js, redacted,
|
||||
check_redacted=True, get_prev_content=False):
|
||||
|
||||
start_time = time.time() * 1000;
|
||||
start_time = time.time() * 1000
|
||||
update_counter = self._get_event_counters.update
|
||||
|
||||
d = json.loads(js)
|
||||
|
|
|
@ -91,7 +91,9 @@ class PushRuleStore(SQLBaseStore):
|
|||
txn.execute(sql, (user_name, relative_to_rule))
|
||||
res = txn.fetchall()
|
||||
if not res:
|
||||
raise RuleNotFoundException("before/after rule not found: %s" % (relative_to_rule))
|
||||
raise RuleNotFoundException(
|
||||
"before/after rule not found: %s" % (relative_to_rule,)
|
||||
)
|
||||
priority_class, base_rule_priority = res[0]
|
||||
|
||||
if 'priority_class' in kwargs and kwargs['priority_class'] != priority_class:
|
||||
|
|
Loading…
Reference in a new issue