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

Commit

Permalink
Replace some more comparisons with six
Browse files Browse the repository at this point in the history
plus a bonus b"" string I missed last time

Signed-off-by: Adrian Tschira <[email protected]>
  • Loading branch information
NotAFile committed May 19, 2018
1 parent 0846262 commit d9fe2b2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
4 changes: 3 additions & 1 deletion synapse/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import re

from six import string_types

# Split strings on "." but not "\." This uses a negative lookbehind assertion for '\'
# (?<!stuff) matches if the current position in the string is not preceded
# by a match for 'stuff'.
Expand Down Expand Up @@ -277,7 +279,7 @@ def serialize_event(e, time_now_ms, as_client_event=True,

if only_event_fields:
if (not isinstance(only_event_fields, list) or
not all(isinstance(f, basestring) for f in only_event_fields)):
not all(isinstance(f, string_types) for f in only_event_fields)):
raise TypeError("only_event_fields must be a list of strings")
d = only_fields(d, only_event_fields)

Expand Down
6 changes: 4 additions & 2 deletions synapse/events/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from synapse.api.errors import SynapseError
from synapse.api.constants import EventTypes, Membership

from six import string_types


class EventValidator(object):

Expand Down Expand Up @@ -49,7 +51,7 @@ def validate(self, event):
strings.append("state_key")

for s in strings:
if not isinstance(getattr(event, s), basestring):
if not isinstance(getattr(event, s), string_types):
raise SynapseError(400, "Not '%s' a string type" % (s,))

if event.type == EventTypes.Member:
Expand Down Expand Up @@ -88,5 +90,5 @@ def _ensure_strings(self, d, keys):
for s in keys:
if s not in d:
raise SynapseError(400, "'%s' not in content" % (s,))
if not isinstance(d[s], basestring):
if not isinstance(d[s], string_types):
raise SynapseError(400, "Not '%s' a string type" % (s,))
4 changes: 3 additions & 1 deletion synapse/groups/groups_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from synapse.types import GroupID, RoomID, UserID, get_domain_from_id
from twisted.internet import defer

from six import string_types

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -431,7 +433,7 @@ def update_group_profile(self, group_id, requester_user_id, content):
"long_description"):
if keyname in content:
value = content[keyname]
if not isinstance(value, basestring):
if not isinstance(value, string_types):
raise SynapseError(400, "%r value is not a string" % (keyname,))
profile[keyname] = value

Expand Down
8 changes: 5 additions & 3 deletions synapse/http/matrixfederationclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import sys
import urllib
from six.moves.urllib import parse as urlparse
from six import string_types


logger = logging.getLogger(__name__)
outbound_logger = logging.getLogger("synapse.http.outbound")
Expand Down Expand Up @@ -553,7 +555,7 @@ def get_file(self, destination, path, output_stream, args={},

encoded_args = {}
for k, vs in args.items():
if isinstance(vs, basestring):
if isinstance(vs, string_types):
vs = [vs]
encoded_args[k] = [v.encode("UTF-8") for v in vs]

Expand Down Expand Up @@ -668,7 +670,7 @@ def check_content_type_is_json(headers):
RuntimeError if the
"""
c_type = headers.getRawHeaders("Content-Type")
c_type = headers.getRawHeaders(b"Content-Type")
if c_type is None:
raise RuntimeError(
"No Content-Type header"
Expand All @@ -685,7 +687,7 @@ def check_content_type_is_json(headers):
def encode_query_args(args):
encoded_args = {}
for k, vs in args.items():
if isinstance(vs, basestring):
if isinstance(vs, string_types):
vs = [vs]
encoded_args[k] = [v.encode("UTF-8") for v in vs]

Expand Down
4 changes: 3 additions & 1 deletion synapse/push/push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from synapse.util.caches import CACHE_SIZE_FACTOR, register_cache
from synapse.util.caches.lrucache import LruCache

from six import string_types

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -238,7 +240,7 @@ def _flatten_dict(d, prefix=[], result=None):
if result is None:
result = {}
for key, value in d.items():
if isinstance(value, basestring):
if isinstance(value, string_types):
result[".".join(prefix + [key])] = value.lower()
elif hasattr(value, "items"):
_flatten_dict(value, prefix=(prefix + [key]), result=result)
Expand Down
8 changes: 5 additions & 3 deletions synapse/rest/client/v1/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from synapse.http.servlet import parse_json_object_from_request
from .base import ClientV1RestServlet, client_path_patterns

from six import string_types

import logging

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -71,7 +73,7 @@ def on_PUT(self, request, user_id):

if "status_msg" in content:
state["status_msg"] = content.pop("status_msg")
if not isinstance(state["status_msg"], basestring):
if not isinstance(state["status_msg"], string_types):
raise SynapseError(400, "status_msg must be a string.")

if content:
Expand Down Expand Up @@ -129,7 +131,7 @@ def on_POST(self, request, user_id):

if "invite" in content:
for u in content["invite"]:
if not isinstance(u, basestring):
if not isinstance(u, string_types):
raise SynapseError(400, "Bad invite value.")
if len(u) == 0:
continue
Expand All @@ -140,7 +142,7 @@ def on_POST(self, request, user_id):

if "drop" in content:
for u in content["drop"]:
if not isinstance(u, basestring):
if not isinstance(u, string_types):
raise SynapseError(400, "Bad drop value.")
if len(u) == 0:
continue
Expand Down

0 comments on commit d9fe2b2

Please sign in to comment.