当前位置: 首页>>代码示例>>Python>>正文


Python types.RoomAlias类代码示例

本文整理汇总了Python中synapse.types.RoomAlias的典型用法代码示例。如果您正苦于以下问题:Python RoomAlias类的具体用法?Python RoomAlias怎么用?Python RoomAlias使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了RoomAlias类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: on_DELETE

    def on_DELETE(self, request, room_alias):
        dir_handler = self.handlers.directory_handler

        try:
            service = yield self.auth.get_appservice_by_req(request)
            room_alias = RoomAlias.from_string(room_alias)
            yield dir_handler.delete_appservice_association(
                service, room_alias
            )
            logger.info(
                "Application service at %s deleted alias %s",
                service.url,
                room_alias.to_string()
            )
            defer.returnValue((200, {}))
        except AuthError:
            # fallback to default user behaviour if they aren't an AS
            pass

        requester = yield self.auth.get_user_by_req(request)
        user = requester.user

        room_alias = RoomAlias.from_string(room_alias)

        yield dir_handler.delete_association(
            requester, user.to_string(), room_alias
        )

        logger.info(
            "User %s deleted alias %s",
            user.to_string(),
            room_alias.to_string()
        )

        defer.returnValue((200, {}))
开发者ID:mebjas,项目名称:synapse,代码行数:35,代码来源:directory.py

示例2: on_DELETE

    def on_DELETE(self, request, room_alias):
        dir_handler = self.handlers.directory_handler

        try:
            service = yield self.auth.get_appservice_by_req(request)
            room_alias = RoomAlias.from_string(room_alias)
            yield dir_handler.delete_appservice_association(service, room_alias)
            logger.info("Application service at %s deleted alias %s", service.url, room_alias.to_string())
            defer.returnValue((200, {}))
        except AuthError:
            # fallback to default user behaviour if they aren't an AS
            pass

        user, _, _ = yield self.auth.get_user_by_req(request)

        is_admin = yield self.auth.is_server_admin(user)
        if not is_admin:
            raise AuthError(403, "You need to be a server admin")

        room_alias = RoomAlias.from_string(room_alias)

        yield dir_handler.delete_association(user.to_string(), room_alias)
        logger.info("User %s deleted alias %s", user.to_string(), room_alias.to_string())

        defer.returnValue((200, {}))
开发者ID:roblabla,项目名称:synapse,代码行数:25,代码来源:directory.py

示例3: setUp

    def setUp(self):
        self.mock_federation = Mock(spec=[
            "make_query",
        ])

        self.query_handlers = {}

        def register_query_handler(query_type, handler):
            self.query_handlers[query_type] = handler
        self.mock_federation.register_query_handler = register_query_handler

        hs = yield setup_test_homeserver(
            http_client=None,
            resource_for_federation=Mock(),
            replication_layer=self.mock_federation,
        )
        hs.handlers = DirectoryHandlers(hs)

        self.handler = hs.get_handlers().directory_handler

        self.store = hs.get_datastore()

        self.my_room = RoomAlias.from_string("#my-room:test")
        self.your_room = RoomAlias.from_string("#your-room:test")
        self.remote_room = RoomAlias.from_string("#another:remote")
开发者ID:0-T-0,项目名称:synapse,代码行数:25,代码来源:test_directory.py

示例4: on_PUT

    def on_PUT(self, request, room_alias):
        room_alias = RoomAlias.from_string(room_alias)

        content = parse_json_object_from_request(request)
        if "room_id" not in content:
            raise SynapseError(400, 'Missing params: ["room_id"]',
                               errcode=Codes.BAD_JSON)

        logger.debug("Got content: %s", content)
        logger.debug("Got room name: %s", room_alias.to_string())

        room_id = content["room_id"]
        servers = content["servers"] if "servers" in content else None

        logger.debug("Got room_id: %s", room_id)
        logger.debug("Got servers: %s", servers)

        # TODO(erikj): Check types.

        room = yield self.store.get_room(room_id)
        if room is None:
            raise SynapseError(400, "Room does not exist")

        requester = yield self.auth.get_user_by_req(request)

        yield self.handlers.directory_handler.create_association(
            requester, room_alias, room_id, servers
        )

        defer.returnValue((200, {}))
开发者ID:DoubleMalt,项目名称:synapse,代码行数:30,代码来源:directory.py

示例5: on_GET

    def on_GET(self, request, room_alias):
        room_alias = RoomAlias.from_string(room_alias)

        dir_handler = self.handlers.directory_handler
        res = yield dir_handler.get_association(room_alias)

        defer.returnValue((200, res))
开发者ID:mebjas,项目名称:synapse,代码行数:7,代码来源:directory.py

示例6: setUp

    def setUp(self):
        hs = yield setup_test_homeserver(self.addCleanup)

        self.store = hs.get_datastore()

        self.room = RoomID.from_string("!abcde:test")
        self.alias = RoomAlias.from_string("#my-room:test")
开发者ID:DoubleMalt,项目名称:synapse,代码行数:7,代码来源:test_directory.py

示例7: read_config

    def read_config(self, config):
        self.enable_registration = bool(
            strtobool(str(config["enable_registration"]))
        )
        if "disable_registration" in config:
            self.enable_registration = not bool(
                strtobool(str(config["disable_registration"]))
            )

        self.registrations_require_3pid = config.get("registrations_require_3pid", [])
        self.allowed_local_3pids = config.get("allowed_local_3pids", [])
        self.registration_shared_secret = config.get("registration_shared_secret")

        self.bcrypt_rounds = config.get("bcrypt_rounds", 12)
        self.trusted_third_party_id_servers = config["trusted_third_party_id_servers"]
        self.default_identity_server = config.get("default_identity_server")
        self.allow_guest_access = config.get("allow_guest_access", False)

        self.invite_3pid_guest = (
            self.allow_guest_access and config.get("invite_3pid_guest", False)
        )

        self.auto_join_rooms = config.get("auto_join_rooms", [])
        for room_alias in self.auto_join_rooms:
            if not RoomAlias.is_valid(room_alias):
                raise ConfigError('Invalid auto_join_rooms entry %s' % (room_alias,))
        self.autocreate_auto_join_rooms = config.get("autocreate_auto_join_rooms", True)
开发者ID:DoubleMalt,项目名称:synapse,代码行数:27,代码来源:registration.py

示例8: on_PUT

    def on_PUT(self, request, room_alias):
        content = parse_json_object_from_request(request)
        if "room_id" not in content:
            raise SynapseError(400, "Missing room_id key",
                               errcode=Codes.BAD_JSON)

        logger.debug("Got content: %s", content)

        room_alias = RoomAlias.from_string(room_alias)

        logger.debug("Got room name: %s", room_alias.to_string())

        room_id = content["room_id"]
        servers = content["servers"] if "servers" in content else None

        logger.debug("Got room_id: %s", room_id)
        logger.debug("Got servers: %s", servers)

        # TODO(erikj): Check types.

        room = yield self.store.get_room(room_id)
        if room is None:
            raise SynapseError(400, "Room does not exist")

        dir_handler = self.handlers.directory_handler

        try:
            # try to auth as a user
            requester = yield self.auth.get_user_by_req(request)
            try:
                user_id = requester.user.to_string()
                yield dir_handler.create_association(
                    user_id, room_alias, room_id, servers
                )
                yield dir_handler.send_room_alias_update_event(
                    requester,
                    user_id,
                    room_id
                )
            except SynapseError as e:
                raise e
            except Exception:
                logger.exception("Failed to create association")
                raise
        except AuthError:
            # try to auth as an application service
            service = yield self.auth.get_appservice_by_req(request)
            yield dir_handler.create_appservice_association(
                service, room_alias, room_id, servers
            )
            logger.info(
                "Application service at %s created alias %s pointing to %s",
                service.url,
                room_alias.to_string(),
                room_id
            )

        defer.returnValue((200, {}))
开发者ID:rubo77,项目名称:synapse,代码行数:58,代码来源:directory.py

示例9: on_POST

    def on_POST(self, request, room_identifier, txn_id=None):
        requester = yield self.auth.get_user_by_req(
            request,
            allow_guest=True,
        )

        try:
            content = parse_json_object_from_request(request)
        except Exception:
            # Turns out we used to ignore the body entirely, and some clients
            # cheekily send invalid bodies.
            content = {}

        if RoomID.is_valid(room_identifier):
            room_id = room_identifier
            try:
                remote_room_hosts = [
                    x.decode('ascii') for x in request.args[b"server_name"]
                ]
            except Exception:
                remote_room_hosts = None
        elif RoomAlias.is_valid(room_identifier):
            handler = self.room_member_handler
            room_alias = RoomAlias.from_string(room_identifier)
            room_id, remote_room_hosts = yield handler.lookup_room_alias(room_alias)
            room_id = room_id.to_string()
        else:
            raise SynapseError(400, "%s was not legal room ID or room alias" % (
                room_identifier,
            ))

        yield self.room_member_handler.update_membership(
            requester=requester,
            target=requester.user,
            room_id=room_id,
            action="join",
            txn_id=txn_id,
            remote_room_hosts=remote_room_hosts,
            content=content,
            third_party_signed=content.get("third_party_signed", None),
        )

        defer.returnValue((200, {"room_id": room_id}))
开发者ID:DoubleMalt,项目名称:synapse,代码行数:43,代码来源:room.py

示例10: test_auto_create_auto_join_rooms_when_support_user_exists

    def test_auto_create_auto_join_rooms_when_support_user_exists(self):
        room_alias_str = "#room:test"
        self.hs.config.auto_join_rooms = [room_alias_str]

        self.store.is_support_user = Mock(return_value=True)
        res = self.get_success(self.handler.register(localpart='support'))
        rooms = self.get_success(self.store.get_rooms_for_user(res[0]))
        self.assertEqual(len(rooms), 0)
        directory_handler = self.hs.get_handlers().directory_handler
        room_alias = RoomAlias.from_string(room_alias_str)
        self.get_failure(directory_handler.get_association(room_alias), SynapseError)
开发者ID:matrix-org,项目名称:synapse,代码行数:11,代码来源:test_register.py

示例11: test_auto_create_auto_join_rooms

    def test_auto_create_auto_join_rooms(self):
        room_alias_str = "#room:test"
        self.hs.config.auto_join_rooms = [room_alias_str]
        res = self.get_success(self.handler.register(localpart='jeff'))
        rooms = self.get_success(self.store.get_rooms_for_user(res[0]))
        directory_handler = self.hs.get_handlers().directory_handler
        room_alias = RoomAlias.from_string(room_alias_str)
        room_id = self.get_success(directory_handler.get_association(room_alias))

        self.assertTrue(room_id['room_id'] in rooms)
        self.assertEqual(len(rooms), 1)
开发者ID:matrix-org,项目名称:synapse,代码行数:11,代码来源:test_register.py

示例12: _auto_join_rooms

    def _auto_join_rooms(self, user_id):
        """Automatically joins users to auto join rooms - creating the room in the first place
        if the user is the first to be created.

        Args:
            user_id(str): The user to join
        """
        # auto-join the user to any rooms we're supposed to dump them into
        fake_requester = create_requester(user_id)

        # try to create the room if we're the first real user on the server. Note
        # that an auto-generated support user is not a real user and will never be
        # the user to create the room
        should_auto_create_rooms = False
        is_support = yield self.store.is_support_user(user_id)
        # There is an edge case where the first user is the support user, then
        # the room is never created, though this seems unlikely and
        # recoverable from given the support user being involved in the first
        # place.
        if self.hs.config.autocreate_auto_join_rooms and not is_support:
            count = yield self.store.count_all_users()
            should_auto_create_rooms = count == 1
        for r in self.hs.config.auto_join_rooms:
            try:
                if should_auto_create_rooms:
                    room_alias = RoomAlias.from_string(r)
                    if self.hs.hostname != room_alias.domain:
                        logger.warning(
                            'Cannot create room alias %s, '
                            'it does not match server domain',
                            r,
                        )
                    else:
                        # create room expects the localpart of the room alias
                        room_alias_localpart = room_alias.localpart

                        # getting the RoomCreationHandler during init gives a dependency
                        # loop
                        yield self.hs.get_room_creation_handler().create_room(
                            fake_requester,
                            config={
                                "preset": "public_chat",
                                "room_alias_name": room_alias_localpart
                            },
                            ratelimit=False,
                        )
                else:
                    yield self._join_user_to_room(fake_requester, r)
            except ConsentNotGivenError as e:
                # Technically not necessary to pull out this error though
                # moving away from bare excepts is a good thing to do.
                logger.error("Failed to join new user to %r: %r", r, e)
            except Exception as e:
                logger.error("Failed to join new user to %r: %r", r, e)
开发者ID:matrix-org,项目名称:synapse,代码行数:54,代码来源:register.py

示例13: _join_user_to_room

    def _join_user_to_room(self, requester, room_identifier):
        room_id = None
        room_member_handler = self.hs.get_room_member_handler()
        if RoomID.is_valid(room_identifier):
            room_id = room_identifier
        elif RoomAlias.is_valid(room_identifier):
            room_alias = RoomAlias.from_string(room_identifier)
            room_id, remote_room_hosts = (
                yield room_member_handler.lookup_room_alias(room_alias)
            )
            room_id = room_id.to_string()
        else:
            raise SynapseError(400, "%s was not legal room ID or room alias" % (
                room_identifier,
            ))

        yield room_member_handler.update_membership(
            requester=requester,
            target=requester.user,
            room_id=room_id,
            remote_room_hosts=remote_room_hosts,
            action="join",
        )
开发者ID:rubo77,项目名称:synapse,代码行数:23,代码来源:register.py

示例14: setUp

    def setUp(self):
        hs = yield setup_test_homeserver()

        # We can't test RoomStore on its own without the DirectoryStore, for
        # management of the 'room_aliases' table
        self.store = hs.get_datastore()

        self.room = RoomID.from_string("!abcde:test")
        self.alias = RoomAlias.from_string("#a-room-name:test")
        self.u_creator = UserID.from_string("@creator:test")

        yield self.store.store_room(self.room.to_string(),
            room_creator_user_id=self.u_creator.to_string(),
            is_public=True
        )
开发者ID:heavenlyhash,项目名称:synapse,代码行数:15,代码来源:test_room.py

示例15: on_POST

    def on_POST(self, request, room_identifier, txn_id=None):
        requester = yield self.auth.get_user_by_req(
            request,
            allow_guest=True,
        )

        # the identifier could be a room alias or a room id. Try one then the
        # other if it fails to parse, without swallowing other valid
        # SynapseErrors.

        identifier = None
        is_room_alias = False
        try:
            identifier = RoomAlias.from_string(room_identifier)
            is_room_alias = True
        except SynapseError:
            identifier = RoomID.from_string(room_identifier)

        # TODO: Support for specifying the home server to join with?

        if is_room_alias:
            handler = self.handlers.room_member_handler
            ret_dict = yield handler.join_room_alias(
                requester.user,
                identifier,
            )
            defer.returnValue((200, ret_dict))
        else:  # room id
            msg_handler = self.handlers.message_handler
            content = {"membership": Membership.JOIN}
            if requester.is_guest:
                content["kind"] = "guest"
            yield msg_handler.create_and_send_event(
                {
                    "type": EventTypes.Member,
                    "content": content,
                    "room_id": identifier.to_string(),
                    "sender": requester.user.to_string(),
                    "state_key": requester.user.to_string(),
                },
                token_id=requester.access_token_id,
                txn_id=txn_id,
                is_guest=requester.is_guest,
            )

            defer.returnValue((200, {"room_id": identifier.to_string()}))
开发者ID:Vutsuak16,项目名称:synapse,代码行数:46,代码来源:room.py


注:本文中的synapse.types.RoomAlias类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。