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


Python types.RoomID类代码示例

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


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

示例1: update_group_summary_room

    def update_group_summary_room(self, group_id, requester_user_id,
                                  room_id, category_id, content):
        """Add/update a room to the group summary
        """
        yield self.check_group_is_ours(
            group_id,
            requester_user_id,
            and_exists=True,
            and_is_admin=requester_user_id,
        )

        RoomID.from_string(room_id)  # Ensure valid room id

        order = content.get("order", None)

        is_public = _parse_visibility_from_contents(content)

        yield self.store.add_room_to_summary(
            group_id=group_id,
            room_id=room_id,
            category_id=category_id,
            order=order,
            is_public=is_public,
        )

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

示例2: add_room_to_group

    def add_room_to_group(self, group_id, requester_user_id, room_id, content):
        """Add room to group
        """
        RoomID.from_string(room_id)  # Ensure valid room id

        yield self.check_group_is_ours(
            group_id, requester_user_id, and_exists=True, and_is_admin=requester_user_id
        )

        is_public = _parse_visibility_from_contents(content)

        yield self.store.add_room_to_group(group_id, room_id, is_public=is_public)

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

示例3: setUp

    def setUp(self):
        hs = yield setup_test_homeserver(resource_for_federation=Mock(), http_client=None)

        self.store = hs.get_datastore()
        self.event_builder_factory = hs.get_event_builder_factory()
        self.handlers = hs.get_handlers()
        self.message_handler = self.handlers.message_handler

        self.u_alice = UserID.from_string("@alice:test")
        self.u_bob = UserID.from_string("@bob:test")

        self.room1 = RoomID.from_string("!abc123:test")
        self.room2 = RoomID.from_string("!xyx987:test")

        self.depth = 1
开发者ID:rrix,项目名称:synapse,代码行数:15,代码来源:test_stream.py

示例4: lookup_room_alias

    def lookup_room_alias(self, room_alias):
        """
        Get the room ID associated with a room alias.

        Args:
            room_alias (RoomAlias): The alias to look up.
        Returns:
            A tuple of:
                The room ID as a RoomID object.
                Hosts likely to be participating in the room ([str]).
        Raises:
            SynapseError if room alias could not be found.
        """
        directory_handler = self.directory_handler
        mapping = yield directory_handler.get_association(room_alias)

        if not mapping:
            raise SynapseError(404, "No such room alias")

        room_id = mapping["room_id"]
        servers = mapping["servers"]

        # put the server which owns the alias at the front of the server list.
        if room_alias.domain in servers:
            servers.remove(room_alias.domain)
        servers.insert(0, room_alias.domain)

        defer.returnValue((RoomID.from_string(room_id), servers))
开发者ID:matrix-org,项目名称:synapse,代码行数:28,代码来源:room_member.py

示例5: 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

示例6: setUp

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

        self.store = DirectoryStore(hs)

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

示例7: _check_definition

    def _check_definition(self, definition):
        """Check if the provided definition is valid.

        This inspects not only the types but also the values to make sure they
        make sense.

        Args:
            definition(dict): The filter definition
        Raises:
            SynapseError: If there was a problem with this definition.
        """
        # NB: Filters are the complete json blobs. "Definitions" are an
        # individual top-level key e.g. public_user_data. Filters are made of
        # many definitions.
        if type(definition) != dict:
            raise SynapseError(
                400, "Expected JSON object, not %s" % (definition,)
            )

        # check rooms are valid room IDs
        room_id_keys = ["rooms", "not_rooms"]
        for key in room_id_keys:
            if key in definition:
                if type(definition[key]) != list:
                    raise SynapseError(400, "Expected %s to be a list." % key)
                for room_id in definition[key]:
                    RoomID.from_string(room_id)

        # check senders are valid user IDs
        user_id_keys = ["senders", "not_senders"]
        for key in user_id_keys:
            if key in definition:
                if type(definition[key]) != list:
                    raise SynapseError(400, "Expected %s to be a list." % key)
                for user_id in definition[key]:
                    UserID.from_string(user_id)

        # TODO: We don't limit event type values but we probably should...
        # check types are valid event types
        event_keys = ["types", "not_types"]
        for key in event_keys:
            if key in definition:
                if type(definition[key]) != list:
                    raise SynapseError(400, "Expected %s to be a list." % key)
                for event_type in definition[key]:
                    if not isinstance(event_type, basestring):
                        raise SynapseError(400, "Event type should be a string")
开发者ID:Xe,项目名称:synapse,代码行数:47,代码来源:filtering.py

示例8: _check_definition_room_lists

    def _check_definition_room_lists(self, definition):
        """Check that "rooms" and "not_rooms" are lists of room ids if they
        are present

        Args:
            definition(dict): The filter definition
        Raises:
            SynapseError: If there was a problem with this definition.
        """
        # check rooms are valid room IDs
        room_id_keys = ["rooms", "not_rooms"]
        for key in room_id_keys:
            if key in definition:
                if type(definition[key]) != list:
                    raise SynapseError(400, "Expected %s to be a list." % key)
                for room_id in definition[key]:
                    RoomID.from_string(room_id)
开发者ID:MorganBauer,项目名称:synapse,代码行数:17,代码来源:filtering.py

示例9: validate_builder

    def validate_builder(self, event):
        """Validates that the builder/event has roughly the right format. Only
        checks values that we expect a proto event to have, rather than all the
        fields an event would have

        Args:
            event (EventBuilder|FrozenEvent)
        """

        strings = [
            "room_id",
            "sender",
            "type",
        ]

        if hasattr(event, "state_key"):
            strings.append("state_key")

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

        RoomID.from_string(event.room_id)
        UserID.from_string(event.sender)

        if event.type == EventTypes.Message:
            strings = [
                "body",
                "msgtype",
            ]

            self._ensure_strings(event.content, strings)

        elif event.type == EventTypes.Topic:
            self._ensure_strings(event.content, ["topic"])

        elif event.type == EventTypes.Name:
            self._ensure_strings(event.content, ["name"])

        elif event.type == EventTypes.Member:
            if "membership" not in event.content:
                raise SynapseError(400, "Content has not membership key")

            if event.content["membership"] not in Membership.LIST:
                raise SynapseError(400, "Invalid membership key")
开发者ID:matrix-org,项目名称:synapse,代码行数:45,代码来源:validator.py

示例10: test_count_daily_messages

    def test_count_daily_messages(self):
        self.db_pool.runQuery("DELETE FROM stats_reporting")

        self.hs.clock.now = 100

        # Never reported before, and nothing which could be reported
        count = yield self.store.count_daily_messages()
        self.assertIsNone(count)
        count = yield self.db_pool.runQuery("SELECT COUNT(*) FROM stats_reporting")
        self.assertEqual([(0,)], count)

        # Create something to report
        room = RoomID.from_string("!abc123:test")
        user = UserID.from_string("@raccoonlover:test")
        yield self.event_injector.create_room(room)

        self.base_event = yield self._get_last_stream_token()

        yield self.event_injector.inject_message(room, user, "Raccoons are really cute")

        # Never reported before, something could be reported, but isn't because
        # it isn't old enough.
        count = yield self.store.count_daily_messages()
        self.assertIsNone(count)
        self._assert_stats_reporting(1, self.hs.clock.now)

        # Already reported yesterday, two new events from today.
        yield self.event_injector.inject_message(room, user, "Yeah they are!")
        yield self.event_injector.inject_message(room, user, "Incredibly!")
        self.hs.clock.now += 60 * 60 * 24
        count = yield self.store.count_daily_messages()
        self.assertEqual(2, count)  # 2 since yesterday
        self._assert_stats_reporting(3, self.hs.clock.now)  # 3 ever

        # Last reported too recently.
        yield self.event_injector.inject_message(room, user, "Who could disagree?")
        self.hs.clock.now += 60 * 60 * 22
        count = yield self.store.count_daily_messages()
        self.assertIsNone(count)
        self._assert_stats_reporting(4, self.hs.clock.now)

        # Last reported too long ago
        yield self.event_injector.inject_message(room, user, "No one.")
        self.hs.clock.now += 60 * 60 * 26
        count = yield self.store.count_daily_messages()
        self.assertIsNone(count)
        self._assert_stats_reporting(5, self.hs.clock.now)

        # And now let's actually report something
        yield self.event_injector.inject_message(room, user, "Indeed.")
        yield self.event_injector.inject_message(room, user, "Indeed.")
        yield self.event_injector.inject_message(room, user, "Indeed.")
        # A little over 24 hours is fine :)
        self.hs.clock.now += (60 * 60 * 24) + 50
        count = yield self.store.count_daily_messages()
        self.assertEqual(3, count)
        self._assert_stats_reporting(8, self.hs.clock.now)
开发者ID:Vutsuak16,项目名称:synapse,代码行数:57,代码来源:test_events.py

示例11: update_room_in_group

    def update_room_in_group(self, group_id, requester_user_id, room_id, config_key,
                             content):
        """Update room in group
        """
        RoomID.from_string(room_id)  # Ensure valid room id

        yield self.check_group_is_ours(
            group_id, requester_user_id, and_exists=True, and_is_admin=requester_user_id
        )

        if config_key == "m.visibility":
            is_public = _parse_visibility_dict(content)

            yield self.store.update_room_in_group_visibility(
                group_id, room_id,
                is_public=is_public,
            )
        else:
            raise SynapseError(400, "Uknown config option")

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

示例12: setUp

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

        # Room events need the full datastore, for persist_event() and
        # get_room_state()
        self.store = hs.get_datastore()
        self.event_factory = hs.get_event_factory()

        self.room = RoomID.from_string("!abcde:test")

        yield self.store.store_room(
            self.room.to_string(), room_creator_user_id="@creator:text", is_public=True
        )
开发者ID:DoubleMalt,项目名称:synapse,代码行数:13,代码来源:test_room.py

示例13: _generate_room_id

 def _generate_room_id(self, creator_id, is_public):
     # autogen room IDs and try to create it. We may clash, so just
     # try a few times till one goes through, giving up eventually.
     attempts = 0
     while attempts < 5:
         try:
             random_string = stringutils.random_string(18)
             gen_room_id = RoomID(
                 random_string,
                 self.hs.hostname,
             ).to_string()
             if isinstance(gen_room_id, bytes):
                 gen_room_id = gen_room_id.decode('utf-8')
             yield self.store.store_room(
                 room_id=gen_room_id,
                 room_creator_user_id=creator_id,
                 is_public=is_public,
             )
             defer.returnValue(gen_room_id)
         except StoreError:
             attempts += 1
     raise StoreError(500, "Couldn't generate a room ID.")
开发者ID:matrix-org,项目名称:synapse,代码行数:22,代码来源:room.py

示例14: validate

    def validate(self, event):
        EventID.from_string(event.event_id)
        RoomID.from_string(event.room_id)

        required = [
            # "auth_events",
            "content",
            # "hashes",
            "origin",
            # "prev_events",
            "sender",
            "type",
        ]

        for k in required:
            if not hasattr(event, k):
                raise SynapseError(400, "Event does not have key %s" % (k,))

        # Check that the following keys have string values
        strings = [
            "origin",
            "sender",
            "type",
        ]

        if hasattr(event, "state_key"):
            strings.append("state_key")

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

        if event.type == EventTypes.Member:
            if "membership" not in event.content:
                raise SynapseError(400, "Content has not membership key")

            if event.content["membership"] not in Membership.LIST:
                raise SynapseError(400, "Invalid membership key")
开发者ID:0-T-0,项目名称:synapse,代码行数:38,代码来源:validator.py

示例15: setUp

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

        self.store = hs.get_datastore()
        self.event_builder_factory = hs.get_event_builder_factory()
        self.event_creation_handler = hs.get_event_creation_handler()

        self.u_alice = UserID.from_string("@alice:test")
        self.u_bob = UserID.from_string("@bob:test")

        self.room = RoomID.from_string("!abc123:test")

        yield self.store.store_room(
            self.room.to_string(), room_creator_user_id="@creator:text", is_public=True
        )
开发者ID:matrix-org,项目名称:synapse,代码行数:15,代码来源:test_state.py


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