diff options
Diffstat (limited to 'synapse')
76 files changed, 167 insertions, 74 deletions
diff --git a/synapse/__init__.py b/synapse/__init__.py index aa760fb341..1e7b2ab272 100644 --- a/synapse/__init__.py +++ b/synapse/__init__.py @@ -12,5 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ This is a reference implementation of a synapse home server. """ diff --git a/synapse/api/__init__.py b/synapse/api/__init__.py index fe8a073cd3..2216c0f1ca 100644 --- a/synapse/api/__init__.py +++ b/synapse/api/__init__.py @@ -12,3 +12,4 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + diff --git a/synapse/api/auth.py b/synapse/api/auth.py index 5c66a7261f..84bc0398fd 100644 --- a/synapse/api/auth.py +++ b/synapse/api/auth.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """This module contains classes for authenticating the user.""" from twisted.internet import defer diff --git a/synapse/api/constants.py b/synapse/api/constants.py index 37bf41bfb3..1ff1af76ec 100644 --- a/synapse/api/constants.py +++ b/synapse/api/constants.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """Contains constants from the specification.""" @@ -36,7 +37,7 @@ class Feedback(object): class PresenceState(object): """Represents the presence state of a user.""" - OFFLINE = 0 - BUSY = 1 - ONLINE = 2 - FREE_FOR_CHAT = 3 + OFFLINE = u"offline" + UNAVAILABLE = u"unavailable" + ONLINE = u"online" + FREE_FOR_CHAT = u"free_for_chat" diff --git a/synapse/api/errors.py b/synapse/api/errors.py index 7ad4d636c2..8b9766fab7 100644 --- a/synapse/api/errors.py +++ b/synapse/api/errors.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """Contains exceptions and error codes.""" import logging diff --git a/synapse/api/events/__init__.py b/synapse/api/events/__init__.py index bc2daf3361..921fd08832 100644 --- a/synapse/api/events/__init__.py +++ b/synapse/api/events/__init__.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from synapse.api.errors import SynapseError, Codes from synapse.util.jsonobject import JsonEncodedObject diff --git a/synapse/api/events/factory.py b/synapse/api/events/factory.py index ea7afa234e..12aa04fc6e 100644 --- a/synapse/api/events/factory.py +++ b/synapse/api/events/factory.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from synapse.api.events.room import ( RoomTopicEvent, MessageEvent, RoomMemberEvent, FeedbackEvent, InviteJoinEvent, RoomConfigEvent diff --git a/synapse/api/events/room.py b/synapse/api/events/room.py index b31cd19f4b..f3df849af2 100644 --- a/synapse/api/events/room.py +++ b/synapse/api/events/room.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from . import SynapseEvent diff --git a/synapse/api/notifier.py b/synapse/api/notifier.py index 974f7f0ba0..22d2914d38 100644 --- a/synapse/api/notifier.py +++ b/synapse/api/notifier.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from synapse.api.constants import Membership from synapse.api.events.room import RoomMemberEvent diff --git a/synapse/api/streams/__init__.py b/synapse/api/streams/__init__.py index 08137c1e79..989e63f9ec 100644 --- a/synapse/api/streams/__init__.py +++ b/synapse/api/streams/__init__.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from synapse.api.errors import SynapseError diff --git a/synapse/api/streams/event.py b/synapse/api/streams/event.py index 0cc1a3e36a..4b6d739e54 100644 --- a/synapse/api/streams/event.py +++ b/synapse/api/streams/event.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """This module contains classes for streaming from the event stream: /events. """ from twisted.internet import defer diff --git a/synapse/app/__init__.py b/synapse/app/__init__.py index fe8a073cd3..2216c0f1ca 100644 --- a/synapse/app/__init__.py +++ b/synapse/app/__init__.py @@ -12,3 +12,4 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index 5708b3ad95..82afb04c7d 100644 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright 2014 matrix.org # @@ -12,7 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -#!/usr/bin/env python from synapse.storage import read_schema @@ -88,13 +88,12 @@ def setup_logging(verbosity=0, filename=None, config_path=None): '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(message)s' ) - if not verbosity or verbosity == 0: - level = logging.WARNING - elif verbosity == 1: - level = logging.INFO - else: + level = logging.INFO + if verbosity: level = logging.DEBUG + # FIXME: we need a logging.WARN for a -q quiet option + logging.basicConfig(level=level, filename=filename, format=log_format) else: logging.config.fileConfig(config_path) @@ -126,6 +125,8 @@ def setup(): parser.add_argument('--pid-file', dest="pid", help="When running as a " "daemon, the file to store the pid in", default="hs.pid") + parser.add_argument("-w", "--webclient", dest="webclient", + action="store_true", help="Host the web client.") args = parser.parse_args() verbosity = int(args.verbose) if args.verbose else None diff --git a/synapse/crypto/__init__.py b/synapse/crypto/__init__.py index fe8a073cd3..2216c0f1ca 100644 --- a/synapse/crypto/__init__.py +++ b/synapse/crypto/__init__.py @@ -12,3 +12,4 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + diff --git a/synapse/crypto/config.py b/synapse/crypto/config.py index 801dfd8656..2330133e71 100644 --- a/synapse/crypto/config.py +++ b/synapse/crypto/config.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + import ConfigParser as configparser import argparse import socket diff --git a/synapse/crypto/keyclient.py b/synapse/crypto/keyclient.py index b53d1c572b..e615866b68 100644 --- a/synapse/crypto/keyclient.py +++ b/synapse/crypto/keyclient.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.web.http import HTTPClient from twisted.internet import defer, reactor from twisted.internet.protocol import ClientFactory diff --git a/synapse/crypto/keyserver.py b/synapse/crypto/keyserver.py index 48bd380781..3d80a0e660 100644 --- a/synapse/crypto/keyserver.py +++ b/synapse/crypto/keyserver.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import reactor, ssl from twisted.web import server from twisted.web.resource import Resource diff --git a/synapse/crypto/resource/__init__.py b/synapse/crypto/resource/__init__.py index fe8a073cd3..2216c0f1ca 100644 --- a/synapse/crypto/resource/__init__.py +++ b/synapse/crypto/resource/__init__.py @@ -12,3 +12,4 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + diff --git a/synapse/crypto/resource/key.py b/synapse/crypto/resource/key.py index 6ce6e0b034..6aecd2b95f 100644 --- a/synapse/crypto/resource/key.py +++ b/synapse/crypto/resource/key.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.web.resource import Resource from twisted.web.server import NOT_DONE_YET from twisted.internet import defer diff --git a/synapse/federation/__init__.py b/synapse/federation/__init__.py index b4d95ed5ac..ac0c10dc33 100644 --- a/synapse/federation/__init__.py +++ b/synapse/federation/__init__.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ This package includes all the federation specific logic. """ diff --git a/synapse/federation/handler.py b/synapse/federation/handler.py index 31e8470b33..d361f0aaf7 100644 --- a/synapse/federation/handler.py +++ b/synapse/federation/handler.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from .pdu_codec import PduCodec diff --git a/synapse/federation/pdu_codec.py b/synapse/federation/pdu_codec.py index 9155930e47..adc166c564 100644 --- a/synapse/federation/pdu_codec.py +++ b/synapse/federation/pdu_codec.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from .units import Pdu import copy diff --git a/synapse/federation/persistence.py b/synapse/federation/persistence.py index ad4111c683..372245712a 100644 --- a/synapse/federation/persistence.py +++ b/synapse/federation/persistence.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ This module contains all the persistence actions done by the federation package. diff --git a/synapse/federation/replication.py b/synapse/federation/replication.py index 0f5b974291..bea5335f89 100644 --- a/synapse/federation/replication.py +++ b/synapse/federation/replication.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """This layer is responsible for replicating with remote home servers using a given transport. """ diff --git a/synapse/federation/transport.py b/synapse/federation/transport.py index 2136adf8d7..ff3fc34419 100644 --- a/synapse/federation/transport.py +++ b/synapse/federation/transport.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """The transport layer is responsible for both sending transactions to remote home servers and receiving a variety of requests from other home servers. @@ -32,6 +33,9 @@ import re logger = logging.getLogger(__name__) +PREFIX = "/matrix/federation/v1" + + class TransportLayer(object): """This is a basic implementation of the transport layer that translates transactions and other requests to/from HTTP. @@ -83,9 +87,9 @@ class TransportLayer(object): logger.debug("get_context_state dest=%s, context=%s", destination, context) - path = "/state/%s/" % context + subpath = "/state/%s/" % context - return self._do_request_for_transaction(destination, path) + return self._do_request_for_transaction(destination, subpath) @log_function def get_pdu(self, destination, pdu_origin, pdu_id): @@ -103,9 +107,9 @@ class TransportLayer(object): logger.debug("get_pdu dest=%s, pdu_origin=%s, pdu_id=%s", destination, pdu_origin, pdu_id) - path = "/pdu/%s/%s/" % (pdu_origin, pdu_id) + subpath = "/pdu/%s/%s/" % (pdu_origin, pdu_id) - return self._do_request_for_transaction(destination, path) + return self._do_request_for_transaction(destination, subpath) @log_function def paginate(self, dest, context, pdu_tuples, limit): @@ -129,14 +133,14 @@ class TransportLayer(object): if not pdu_tuples: return - path = "/paginate/%s/" % context + subpath = "/paginate/%s/" % context args = {"v": ["%s,%s" % (i, o) for i, o in pdu_tuples]} args["limit"] = limit return self._do_request_for_transaction( dest, - path, + subpath, args=args, ) @@ -165,7 +169,7 @@ class TransportLayer(object): code, response = yield self.client.put_json( transaction.destination, - path="/send/%s/" % transaction.transaction_id, + path=PREFIX + "/send/%s/" % transaction.transaction_id, data=data ) @@ -188,7 +192,7 @@ class TransportLayer(object): # This is when someone is trying to send us a bunch of data. self.server.register_path( "PUT", - re.compile("^/send/([^/]*)/$"), + re.compile("^" + PREFIX + "/send/([^/]*)/$"), self._on_send_request ) @@ -206,7 +210,7 @@ class TransportLayer(object): # This is for when someone asks us for everything since version X self.server.register_path( "GET", - re.compile("^/pull/$"), + re.compile("^" + PREFIX + "/pull/$"), lambda request: handler.on_pull_request( request.args["origin"][0], request.args["v"] @@ -217,7 +221,7 @@ class TransportLayer(object): # data_id pair. self.server.register_path( "GET", - re.compile("^/pdu/([^/]*)/([^/]*)/$"), + re.compile("^" + PREFIX + "/pdu/([^/]*)/([^/]*)/$"), lambda request, pdu_origin, pdu_id: handler.on_pdu_request( pdu_origin, pdu_id ) @@ -226,7 +230,7 @@ class TransportLayer(object): # This is when someone asks for all data for a given context. self.server.register_path( "GET", - re.compile("^/state/([^/]*)/$"), + re.compile("^" + PREFIX + "/state/([^/]*)/$"), lambda request, context: handler.on_context_state_request( context ) @@ -234,7 +238,7 @@ class TransportLayer(object): self.server.register_path( "GET", - re.compile("^/paginate/([^/]*)/$"), + re.compile("^" + PREFIX + "/paginate/([^/]*)/$"), lambda request, context: self._on_paginate_request( context, request.args["v"], request.args["limit"] @@ -243,7 +247,7 @@ class TransportLayer(object): self.server.register_path( "GET", - re.compile("^/context/([^/]*)/$"), + re.compile("^" + PREFIX + "/context/([^/]*)/$"), lambda request, context: handler.on_context_pdus_request(context) ) @@ -299,7 +303,7 @@ class TransportLayer(object): @defer.inlineCallbacks @log_function - def _do_request_for_transaction(self, destination, path, args={}): + def _do_request_for_transaction(self, destination, subpath, args={}): """ Args: destination (str) @@ -312,7 +316,7 @@ class TransportLayer(object): data = yield self.client.get_json( destination, - path=path, + path=PREFIX + subpath, args=args, ) diff --git a/synapse/federation/units.py b/synapse/federation/units.py index 0efea7b768..2b2f11f36a 100644 --- a/synapse/federation/units.py +++ b/synapse/federation/units.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ Defines the JSON structure of the protocol units used by the server to server protocol. """ diff --git a/synapse/handlers/__init__.py b/synapse/handlers/__init__.py index 5688b68e49..8a4aa6e5d6 100644 --- a/synapse/handlers/__init__.py +++ b/synapse/handlers/__init__.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from .register import RegistrationHandler from .room import ( MessageHandler, RoomCreationHandler, RoomMemberHandler, RoomListHandler diff --git a/synapse/handlers/_base.py b/synapse/handlers/_base.py index 87a392dd77..c2f4685c92 100644 --- a/synapse/handlers/_base.py +++ b/synapse/handlers/_base.py @@ -14,6 +14,7 @@ # limitations under the License. + class BaseHandler(object): def __init__(self, hs): diff --git a/synapse/handlers/directory.py b/synapse/handlers/directory.py index 456007c71d..3cc6348906 100644 --- a/synapse/handlers/directory.py +++ b/synapse/handlers/directory.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from ._base import BaseHandler diff --git a/synapse/handlers/events.py b/synapse/handlers/events.py index 79742a4e1c..3af7d824a2 100644 --- a/synapse/handlers/events.py +++ b/synapse/handlers/events.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from ._base import BaseHandler diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index 12e7afca4c..7026df90a2 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """Contains handlers for federation events.""" from ._base import BaseHandler diff --git a/synapse/handlers/login.py b/synapse/handlers/login.py index 5a1acd7102..ca69829d77 100644 --- a/synapse/handlers/login.py +++ b/synapse/handlers/login.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from ._base import BaseHandler diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index 38db4b1d67..1c24efd454 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from synapse.api.errors import SynapseError, AuthError diff --git a/synapse/handlers/profile.py b/synapse/handlers/profile.py index a27206b002..976b8cfcdc 100644 --- a/synapse/handlers/profile.py +++ b/synapse/handlers/profile.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from synapse.api.errors import SynapseError, AuthError diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py index 246c1f6530..593c603346 100644 --- a/synapse/handlers/register.py +++ b/synapse/handlers/register.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """Contains functions for registering clients.""" from twisted.internet import defer diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 4d82b33993..eae40765b3 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """Contains functions for performing events on rooms.""" from twisted.internet import defer diff --git a/synapse/http/__init__.py b/synapse/http/__init__.py index fe8a073cd3..2216c0f1ca 100644 --- a/synapse/http/__init__.py +++ b/synapse/http/__init__.py @@ -12,3 +12,4 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + diff --git a/synapse/http/client.py b/synapse/http/client.py index bb22b0ee9a..d0facbdc6c 100644 --- a/synapse/http/client.py +++ b/synapse/http/client.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer, reactor from twisted.web.client import _AgentBase, _URI, readBody from twisted.web.http_headers import Headers diff --git a/synapse/http/endpoint.py b/synapse/http/endpoint.py index c4e6e63a80..d91500b07d 100644 --- a/synapse/http/endpoint.py +++ b/synapse/http/endpoint.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet.endpoints import SSL4ClientEndpoint, TCP4ClientEndpoint from twisted.internet import defer from twisted.internet.error import ConnectError diff --git a/synapse/http/server.py b/synapse/http/server.py index 9fb45971d5..d7f4b691bc 100644 --- a/synapse/http/server.py +++ b/synapse/http/server.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from syutil.jsonutil import ( encode_canonical_json, encode_pretty_printed_json ) diff --git a/synapse/rest/__init__.py b/synapse/rest/__init__.py index 5598295793..74a372e2ff 100644 --- a/synapse/rest/__init__.py +++ b/synapse/rest/__init__.py @@ -13,10 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. + from . import ( - room, events, register, profile, public, presence, im, directory + room, events, register, login, profile, public, presence, im, directory, + webclient ) + class RestServletFactory(object): """ A factory for creating REST servlets. @@ -35,10 +38,13 @@ class RestServletFactory(object): room.register_servlets(hs, http_server) events.register_servlets(hs, http_server) register.register_servlets(hs, http_server) + login.register_servlets(hs, http_server) profile.register_servlets(hs, http_server) public.register_servlets(hs, http_server) presence.register_servlets(hs, http_server) im.register_servlets(hs, http_server) directory.register_servlets(hs, http_server) - + def register_web_client(self, hs): + http_server = hs.get_http_server() + webclient.register_servlets(hs, http_server) diff --git a/synapse/rest/base.py b/synapse/rest/base.py index d90ac611fe..65d417f757 100644 --- a/synapse/rest/base.py +++ b/synapse/rest/base.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ This module contains base REST classes for constructing REST servlets. """ import re @@ -29,48 +30,6 @@ def client_path_pattern(path_regex): return re.compile("^/matrix/client/api/v1" + path_regex) -class RestServletFactory(object): - - """ A factory for creating REST servlets. - - These REST servlets represent the entire client-server REST API. Generally - speaking, they serve as wrappers around events and the handlers that - process them. - - See synapse.api.events for information on synapse events. - """ - - def __init__(self, hs): - http_server = hs.get_http_server() - - # You get import errors if you try to import before the classes in this - # file are defined, hence importing here instead. - - import room - room.register_servlets(hs, http_server) - - import events - events.register_servlets(hs, http_server) - - import register - register.register_servlets(hs, http_server) - - import profile - profile.register_servlets(hs, http_server) - - import public - public.register_servlets(hs, http_server) - - import presence - presence.register_servlets(hs, http_server) - - import im - im.register_servlets(hs, http_server) - - import login - login.register_servlets(hs, http_server) - - class RestServlet(object): """ A Synapse REST Servlet. diff --git a/synapse/rest/directory.py b/synapse/rest/directory.py index a426003a38..31fd26e848 100644 --- a/synapse/rest/directory.py +++ b/synapse/rest/directory.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from synapse.types import RoomAlias, RoomID diff --git a/synapse/rest/events.py b/synapse/rest/events.py index 147257a940..dc811b813a 100644 --- a/synapse/rest/events.py +++ b/synapse/rest/events.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """This module contains REST servlets to do with event streaming, /events.""" from twisted.internet import defer diff --git a/synapse/rest/im.py b/synapse/rest/im.py index 39f2dbd749..63a77716a0 100644 --- a/synapse/rest/im.py +++ b/synapse/rest/im.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from synapse.api.streams import PaginationConfig diff --git a/synapse/rest/login.py b/synapse/rest/login.py index 0284e125b4..88a3218332 100644 --- a/synapse/rest/login.py +++ b/synapse/rest/login.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from synapse.api.errors import SynapseError diff --git a/synapse/rest/presence.py b/synapse/rest/presence.py index e4925c20a5..6043848595 100644 --- a/synapse/rest/presence.py +++ b/synapse/rest/presence.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ This module contains REST servlets to do with presence: /presence/<paths> """ from twisted.internet import defer diff --git a/synapse/rest/profile.py b/synapse/rest/profile.py index f384227c29..3d0427bf72 100644 --- a/synapse/rest/profile.py +++ b/synapse/rest/profile.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ This module contains REST servlets to do with profile: /profile/<paths> """ from twisted.internet import defer diff --git a/synapse/rest/public.py b/synapse/rest/public.py index 6fd1731a61..3430c8049f 100644 --- a/synapse/rest/public.py +++ b/synapse/rest/public.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """This module contains REST servlets to do with public paths: /public""" from twisted.internet import defer diff --git a/synapse/rest/register.py b/synapse/rest/register.py index f1cbce5c67..eb457562b9 100644 --- a/synapse/rest/register.py +++ b/synapse/rest/register.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """This module contains REST servlets to do with registration: /register""" from twisted.internet import defer diff --git a/synapse/rest/room.py b/synapse/rest/room.py index c96de5e65d..228bc9623d 100644 --- a/synapse/rest/room.py +++ b/synapse/rest/room.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ This module contains REST servlets to do with rooms: /rooms/<paths> """ from twisted.internet import defer diff --git a/synapse/rest/webclient.py b/synapse/rest/webclient.py new file mode 100644 index 0000000000..75a425c14c --- /dev/null +++ b/synapse/rest/webclient.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from synapse.rest.base import RestServlet + +import logging +import re + +logger = logging.getLogger(__name__) + + +class WebClientRestServlet(RestServlet): + # No PATTERN; we have custom dispatch rules here + + def register(self, http_server): + http_server.register_path("GET", + re.compile("^/$"), + self.on_GET_redirect) + http_server.register_path("GET", + re.compile("^/matrix/client$"), + self.on_GET) + + def on_GET(self, request): + return (200, "not implemented") + + def on_GET_redirect(self, request): + request.setHeader("Location", request.uri + "matrix/client") + return (302, None) + + +def register_servlets(hs, http_server): + logger.info("Registering web client.") + WebClientRestServlet(hs).register(http_server) \ No newline at end of file diff --git a/synapse/server.py b/synapse/server.py index 0aff75f399..0211972d05 100644 --- a/synapse/server.py +++ b/synapse/server.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + # This file provides some classes for setting up (partially-populated) # homeservers; either as a full homeserver as a real application, or a small # partial one for unit test mocking. @@ -171,6 +172,10 @@ class HomeServer(BaseHomeServer): return Distributor() def register_servlets(self): - """Simply building the ServletFactory is sufficient to have it - register.""" - self.get_rest_servlet_factory() + """ Register all servlets associated with this HomeServer. + + Args: + host_web_client (bool): True to host the web client as well. + """ + # Simply building the ServletFactory is sufficient to have it register + factory = self.get_rest_servlet_factory() diff --git a/synapse/state.py b/synapse/state.py index 439c0b519a..b081de8f4f 100644 --- a/synapse/state.py +++ b/synapse/state.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from synapse.federation.pdu_codec import encode_event_id diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py index ec93f9f8a7..3c27428c08 100644 --- a/synapse/storage/__init__.py +++ b/synapse/storage/__init__.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from synapse.api.events.room import ( RoomMemberEvent, MessageEvent, RoomTopicEvent, FeedbackEvent, RoomConfigEvent diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py index 4d98a6fd0d..65f691ead4 100644 --- a/synapse/storage/_base.py +++ b/synapse/storage/_base.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import logging from twisted.internet import defer diff --git a/synapse/storage/directory.py b/synapse/storage/directory.py index 71fa9d9c9c..b22ce02f3f 100644 --- a/synapse/storage/directory.py +++ b/synapse/storage/directory.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore from twisted.internet import defer diff --git a/synapse/storage/feedback.py b/synapse/storage/feedback.py index 2b421e3342..9bd562c762 100644 --- a/synapse/storage/feedback.py +++ b/synapse/storage/feedback.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore, Table from synapse.api.events.room import FeedbackEvent diff --git a/synapse/storage/message.py b/synapse/storage/message.py index 4822fa709d..7bb69c1384 100644 --- a/synapse/storage/message.py +++ b/synapse/storage/message.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore, Table from synapse.api.events.room import MessageEvent diff --git a/synapse/storage/pdu.py b/synapse/storage/pdu.py index a1cdde0a3b..202d7f6cb6 100644 --- a/synapse/storage/pdu.py +++ b/synapse/storage/pdu.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore, Table, JoinHelper from synapse.util.logutils import log_function diff --git a/synapse/storage/presence.py b/synapse/storage/presence.py index e57ddaf149..6f5b042c25 100644 --- a/synapse/storage/presence.py +++ b/synapse/storage/presence.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore diff --git a/synapse/storage/profile.py b/synapse/storage/profile.py index d2f24930c1..91dd565033 100644 --- a/synapse/storage/profile.py +++ b/synapse/storage/profile.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore diff --git a/synapse/storage/registration.py b/synapse/storage/registration.py index 4a970dd546..68cdfbb4ca 100644 --- a/synapse/storage/registration.py +++ b/synapse/storage/registration.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from sqlite3 import IntegrityError diff --git a/synapse/storage/room.py b/synapse/storage/room.py index 174cbcf3d8..a97162831b 100644 --- a/synapse/storage/room.py +++ b/synapse/storage/room.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from sqlite3 import IntegrityError @@ -92,7 +93,10 @@ class RoomStore(SQLBaseStore): latest_topic = ("SELECT max(room_data.id) FROM room_data WHERE " + "room_data.type = ? GROUP BY room_id") - query = ("SELECT rooms.*, room_data.content FROM rooms LEFT JOIN " + query = ("SELECT rooms.*, room_data.content, room_alias FROM rooms " + + "LEFT JOIN " + + "room_aliases ON room_aliases.room_id = rooms.room_id " + + "LEFT JOIN " + "room_data ON rooms.room_id = room_data.room_id WHERE " + "(room_data.id IN (" + latest_topic + ") " + "OR room_data.id IS NULL) AND rooms.is_public = ?") @@ -102,7 +106,7 @@ class RoomStore(SQLBaseStore): ) # return only the keys the specification expects - ret_keys = ["room_id", "topic"] + ret_keys = ["room_id", "topic", "room_alias"] # extract topic from the json (icky) FIXME for i, room_row in enumerate(res): diff --git a/synapse/storage/roomdata.py b/synapse/storage/roomdata.py index 781d477931..cc04d1ba14 100644 --- a/synapse/storage/roomdata.py +++ b/synapse/storage/roomdata.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore, Table import collections diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py index e6e7617797..ef73be4af4 100644 --- a/synapse/storage/roommember.py +++ b/synapse/storage/roommember.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from synapse.types import UserID diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py index c3b1bfeb32..1dedffac49 100644 --- a/synapse/storage/stream.py +++ b/synapse/storage/stream.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore from .message import MessagesTable from .feedback import FeedbackTable diff --git a/synapse/storage/transactions.py b/synapse/storage/transactions.py index aa41e2ad7f..a277e4971a 100644 --- a/synapse/storage/transactions.py +++ b/synapse/storage/transactions.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore, Table from .pdu import PdusTable diff --git a/synapse/types.py b/synapse/types.py index 1adc95bbb0..054b1e713c 100644 --- a/synapse/types.py +++ b/synapse/types.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from synapse.api.errors import SynapseError from collections import namedtuple diff --git a/synapse/util/__init__.py b/synapse/util/__init__.py index 5361cb7ec2..3ea431a7f9 100644 --- a/synapse/util/__init__.py +++ b/synapse/util/__init__.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import reactor import time diff --git a/synapse/util/async.py b/synapse/util/async.py index e04db8e285..ebbdc00ae1 100644 --- a/synapse/util/async.py +++ b/synapse/util/async.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer, reactor diff --git a/synapse/util/distributor.py b/synapse/util/distributor.py index 32d19402b4..9605d7d1b9 100644 --- a/synapse/util/distributor.py +++ b/synapse/util/distributor.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer import logging diff --git a/synapse/util/jsonobject.py b/synapse/util/jsonobject.py index 190a80a322..e2840b59f9 100644 --- a/synapse/util/jsonobject.py +++ b/synapse/util/jsonobject.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + import copy class JsonEncodedObject(object): diff --git a/synapse/util/lockutils.py b/synapse/util/lockutils.py index e4d609d84e..758be0b901 100644 --- a/synapse/util/lockutils.py +++ b/synapse/util/lockutils.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer import logging diff --git a/synapse/util/logutils.py b/synapse/util/logutils.py index 08d5aafca4..9270a1790b 100644 --- a/synapse/util/logutils.py +++ b/synapse/util/logutils.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from inspect import getcallargs import logging diff --git a/synapse/util/stringutils.py b/synapse/util/stringutils.py index 91550583a4..e1b0796e56 100644 --- a/synapse/util/stringutils.py +++ b/synapse/util/stringutils.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import random import string |