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

Commit

Permalink
Use None instead of the empty string
Browse files Browse the repository at this point in the history
Change how we validate the 'url' field as a result.
  • Loading branch information
kegsay committed Aug 30, 2016
1 parent 16b652f commit 572acde
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
10 changes: 5 additions & 5 deletions synapse/appservice/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, hs):

@defer.inlineCallbacks
def query_user(self, service, user_id):
if service.url == "":
if service.url is None:
defer.returnValue(False)
uri = service.url + ("/users/%s" % urllib.quote(user_id))
response = None
Expand All @@ -88,7 +88,7 @@ def query_user(self, service, user_id):

@defer.inlineCallbacks
def query_alias(self, service, alias):
if service.url == "":
if service.url is None:
defer.returnValue(False)
uri = service.url + ("/rooms/%s" % urllib.quote(alias))
response = None
Expand Down Expand Up @@ -117,7 +117,7 @@ def query_3pe(self, service, kind, protocol, fields):
raise ValueError(
"Unrecognised 'kind' argument %r to query_3pe()", kind
)
if service.url == "":
if service.url is None:
defer.returnValue([])

uri = "%s%s/thirdparty/%s/%s" % (
Expand Down Expand Up @@ -151,7 +151,7 @@ def query_3pe(self, service, kind, protocol, fields):
defer.returnValue([])

def get_3pe_protocol(self, service, protocol):
if service.url == "":
if service.url is None:
defer.returnValue({})

@defer.inlineCallbacks
Expand All @@ -175,7 +175,7 @@ def _get():

@defer.inlineCallbacks
def push_bulk(self, service, events, txn_id=None):
if service.url == "":
if service.url is None:
defer.returnValue(True)

events = self._serialize(events)
Expand Down
15 changes: 11 additions & 4 deletions synapse/config/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,21 @@ def load_appservices(hostname, config_files):

def _load_appservice(hostname, as_info, config_filename):
required_string_fields = [
"id", "url", "as_token", "hs_token", "sender_localpart"
"id", "as_token", "hs_token", "sender_localpart"
]
for field in required_string_fields:
if not isinstance(as_info.get(field), basestring):
raise KeyError("Required string field: '%s' (%s)" % (
field, config_filename,
))

# 'url' must either be a string or explicitly null, not missing
# to avoid accidentally turning off push for ASes.
if not isinstance(as_info.get("url"), basestring) and as_info.get("url", "") is not None:
raise KeyError(
"Required string field or explicit null: 'url' (%s)" % (config_filename,)
)

localpart = as_info["sender_localpart"]
if urllib.quote(localpart) != localpart:
raise ValueError(
Expand Down Expand Up @@ -133,10 +140,10 @@ def _load_appservice(hostname, as_info, config_filename):
if not isinstance(p, str):
raise KeyError("Bad value for 'protocols' item")

if as_info["url"] == "":
if as_info["url"] == None:
logger.info(
"(%s) Explicitly empty 'url' provided. This application service " +
"will not receive events or queries.",
"(%s) Explicitly empty 'url' provided. This application service"
" will not receive events or queries.",
config_filename,
)
return ApplicationService(
Expand Down

0 comments on commit 572acde

Please sign in to comment.