Replace hs.parse_roomalias with RoomAlias.from_string

This commit is contained in:
Mark Haines 2015-01-23 13:21:58 +00:00
parent 1c06c48ce2
commit ada711504e
8 changed files with 18 additions and 26 deletions

View File

@ -19,6 +19,7 @@ from ._base import BaseHandler
from synapse.api.errors import SynapseError, Codes, CodeMessageException from synapse.api.errors import SynapseError, Codes, CodeMessageException
from synapse.api.constants import EventTypes from synapse.api.constants import EventTypes
from synapse.types import RoomAlias
import logging import logging
@ -122,7 +123,7 @@ class DirectoryHandler(BaseHandler):
@defer.inlineCallbacks @defer.inlineCallbacks
def on_directory_query(self, args): def on_directory_query(self, args):
room_alias = self.hs.parse_roomalias(args["room_alias"]) room_alias = RoomAlias.from_string(args["room_alias"])
if not self.hs.is_mine(room_alias): if not self.hs.is_mine(room_alias):
raise SynapseError( raise SynapseError(
400, "Room Alias is not hosted on this Home Server" 400, "Room Alias is not hosted on this Home Server"

View File

@ -17,7 +17,8 @@
from twisted.internet import defer from twisted.internet import defer
from synapse.api.errors import AuthError, SynapseError, Codes from synapse.api.errors import AuthError, SynapseError, Codes
from base import RestServlet, client_path_pattern from synapse.types import RoomAlias
from .base import RestServlet, client_path_pattern
import json import json
import logging import logging
@ -35,7 +36,7 @@ class ClientDirectoryServer(RestServlet):
@defer.inlineCallbacks @defer.inlineCallbacks
def on_GET(self, request, room_alias): def on_GET(self, request, room_alias):
room_alias = self.hs.parse_roomalias(room_alias) room_alias = RoomAlias.from_string(room_alias)
dir_handler = self.handlers.directory_handler dir_handler = self.handlers.directory_handler
res = yield dir_handler.get_association(room_alias) res = yield dir_handler.get_association(room_alias)
@ -53,7 +54,7 @@ class ClientDirectoryServer(RestServlet):
logger.debug("Got content: %s", content) logger.debug("Got content: %s", content)
room_alias = self.hs.parse_roomalias(room_alias) room_alias = RoomAlias.from_string(room_alias)
logger.debug("Got room name: %s", room_alias.to_string()) logger.debug("Got room name: %s", room_alias.to_string())
@ -92,7 +93,7 @@ class ClientDirectoryServer(RestServlet):
dir_handler = self.handlers.directory_handler dir_handler = self.handlers.directory_handler
room_alias = self.hs.parse_roomalias(room_alias) room_alias = RoomAlias.from_string(room_alias)
yield dir_handler.delete_association( yield dir_handler.delete_association(
user.to_string(), room_alias user.to_string(), room_alias

View File

@ -20,7 +20,7 @@ from base import RestServlet, client_path_pattern
from synapse.api.errors import SynapseError, Codes from synapse.api.errors import SynapseError, Codes
from synapse.streams.config import PaginationConfig from synapse.streams.config import PaginationConfig
from synapse.api.constants import EventTypes, Membership from synapse.api.constants import EventTypes, Membership
from synapse.types import UserID, RoomID from synapse.types import UserID, RoomID, RoomAlias
import json import json
import logging import logging
@ -224,7 +224,7 @@ class JoinRoomAliasServlet(RestServlet):
identifier = None identifier = None
is_room_alias = False is_room_alias = False
try: try:
identifier = self.hs.parse_roomalias(room_identifier) identifier = RoomAlias.from_string(room_identifier)
is_room_alias = True is_room_alias = True
except SynapseError: except SynapseError:
identifier = RoomID.from_string(room_identifier) identifier = RoomID.from_string(room_identifier)

View File

@ -26,7 +26,7 @@ from synapse.api.auth import Auth
from synapse.handlers import Handlers from synapse.handlers import Handlers
from synapse.state import StateHandler from synapse.state import StateHandler
from synapse.storage import DataStore from synapse.storage import DataStore
from synapse.types import RoomAlias, EventID from synapse.types import EventID
from synapse.util import Clock from synapse.util import Clock
from synapse.util.distributor import Distributor from synapse.util.distributor import Distributor
from synapse.util.lockutils import LockManager from synapse.util.lockutils import LockManager
@ -127,11 +127,6 @@ class BaseHomeServer(object):
# TODO: Why are these parse_ methods so high up along with other globals? # TODO: Why are these parse_ methods so high up along with other globals?
# Surely these should be in a util package or in the api package? # Surely these should be in a util package or in the api package?
def parse_roomalias(self, s):
"""Parse the string given by 's' as a Room Alias and return a RoomAlias
object."""
return RoomAlias.from_string(s)
def parse_eventid(self, s): def parse_eventid(self, s):
"""Parse the string given by 's' as a Event ID and return a EventID """Parse the string given by 's' as a Event ID and return a EventID
object.""" object."""

View File

@ -21,6 +21,7 @@ from mock import Mock
from synapse.server import HomeServer from synapse.server import HomeServer
from synapse.handlers.directory import DirectoryHandler from synapse.handlers.directory import DirectoryHandler
from synapse.types import RoomAlias
from tests.utils import SQLiteMemoryDbPool, MockKey from tests.utils import SQLiteMemoryDbPool, MockKey
@ -65,9 +66,9 @@ class DirectoryTestCase(unittest.TestCase):
self.store = hs.get_datastore() self.store = hs.get_datastore()
self.my_room = hs.parse_roomalias("#my-room:test") self.my_room = RoomAlias.from_string("#my-room:test")
self.your_room = hs.parse_roomalias("#your-room:test") self.your_room = RoomAlias.from_string("#your-room:test")
self.remote_room = hs.parse_roomalias("#another:remote") self.remote_room = RoomAlias.from_string("#another:remote")
@defer.inlineCallbacks @defer.inlineCallbacks
def test_get_local_association(self): def test_get_local_association(self):

View File

@ -19,7 +19,7 @@ from twisted.internet import defer
from synapse.server import HomeServer from synapse.server import HomeServer
from synapse.storage.directory import DirectoryStore from synapse.storage.directory import DirectoryStore
from synapse.types import RoomID from synapse.types import RoomID, RoomAlias
from tests.utils import SQLiteMemoryDbPool from tests.utils import SQLiteMemoryDbPool
@ -39,7 +39,7 @@ class DirectoryStoreTestCase(unittest.TestCase):
self.store = DirectoryStore(hs) self.store = DirectoryStore(hs)
self.room = RoomID.from_string("!abcde:test") self.room = RoomID.from_string("!abcde:test")
self.alias = hs.parse_roomalias("#my-room:test") self.alias = RoomAlias.from_string("#my-room:test")
@defer.inlineCallbacks @defer.inlineCallbacks
def test_room_to_alias(self): def test_room_to_alias(self):

View File

@ -19,7 +19,7 @@ from twisted.internet import defer
from synapse.server import HomeServer from synapse.server import HomeServer
from synapse.api.constants import EventTypes from synapse.api.constants import EventTypes
from synapse.types import UserID, RoomID from synapse.types import UserID, RoomID, RoomAlias
from tests.utils import SQLiteMemoryDbPool from tests.utils import SQLiteMemoryDbPool
@ -40,7 +40,7 @@ class RoomStoreTestCase(unittest.TestCase):
self.store = hs.get_datastore() self.store = hs.get_datastore()
self.room = RoomID.from_string("!abcde:test") self.room = RoomID.from_string("!abcde:test")
self.alias = hs.parse_roomalias("#a-room-name:test") self.alias = RoomAlias.from_string("#a-room-name:test")
self.u_creator = UserID.from_string("@creator:test") self.u_creator = UserID.from_string("@creator:test")
yield self.store.store_room(self.room.to_string(), yield self.store.store_room(self.room.to_string(),

View File

@ -56,9 +56,3 @@ class RoomAliasTestCase(unittest.TestCase):
room = RoomAlias("channel", "my.domain") room = RoomAlias("channel", "my.domain")
self.assertEquals(room.to_string(), "#channel:my.domain") self.assertEquals(room.to_string(), "#channel:my.domain")
def test_via_homeserver(self):
room = mock_homeserver.parse_roomalias("#elsewhere:my.domain")
self.assertEquals("elsewhere", room.localpart)
self.assertEquals("my.domain", room.domain)