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


Python HomeServer.get_ratelimiter方法代码示例

本文整理汇总了Python中synapse.server.HomeServer.get_ratelimiter方法的典型用法代码示例。如果您正苦于以下问题:Python HomeServer.get_ratelimiter方法的具体用法?Python HomeServer.get_ratelimiter怎么用?Python HomeServer.get_ratelimiter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在synapse.server.HomeServer的用法示例。


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

示例1: setUp

# 需要导入模块: from synapse.server import HomeServer [as 别名]
# 或者: from synapse.server.HomeServer import get_ratelimiter [as 别名]
    def setUp(self):
        self.mock_resource = MockHttpResource(prefix=PATH_PREFIX)
        self.auth_user_id = self.user_id

        state_handler = Mock(spec=["handle_new_event"])
        state_handler.handle_new_event.return_value = True

        persistence_service = Mock(spec=["get_latest_pdus_in_context"])
        persistence_service.get_latest_pdus_in_context.return_value = []

        hs = HomeServer(
            "red",
            db_pool=None,
            http_client=None,
            datastore=MemoryDataStore(),
            replication_layer=Mock(),
            state_handler=state_handler,
            persistence_service=persistence_service,
            ratelimiter=NonCallableMock(spec_set=[
                "send_message",
            ]),
            config=NonCallableMock(),
        )
        self.ratelimiter = hs.get_ratelimiter()
        self.ratelimiter.send_message.return_value = (True, 0)

        hs.get_handlers().federation_handler = Mock()

        def _get_user_by_token(token=None):
            return hs.parse_userid(self.auth_user_id)
        hs.get_auth().get_user_by_token = _get_user_by_token

        synapse.rest.room.register_servlets(hs, self.mock_resource)

        self.room_id = yield self.create_room_as(self.user_id)
开发者ID:martindale,项目名称:synapse,代码行数:37,代码来源:test_rooms.py

示例2: setUp

# 需要导入模块: from synapse.server import HomeServer [as 别名]
# 或者: from synapse.server.HomeServer import get_ratelimiter [as 别名]
    def setUp(self):
        self.mock_config = NonCallableMock()
        self.mock_config.signing_key = [MockKey()]
        self.hostname = "red"
        hs = HomeServer(
            self.hostname,
            db_pool=None,
            ratelimiter=NonCallableMock(spec_set=[
                "send_message",
            ]),
            datastore=NonCallableMock(spec_set=[
                "persist_event",
                "get_joined_hosts_for_room",
                "get_room_member",
                "get_room",
                "store_room",
                "snapshot_room",
            ]),
            resource_for_federation=NonCallableMock(),
            http_client=NonCallableMock(spec_set=[]),
            notifier=NonCallableMock(spec_set=["on_new_room_event"]),
            handlers=NonCallableMock(spec_set=[
                "room_member_handler",
                "profile_handler",
                "federation_handler",
            ]),
            auth=NonCallableMock(spec_set=["check"]),
            state_handler=NonCallableMock(spec_set=["handle_new_event"]),
            config=self.mock_config,
        )

        self.federation = NonCallableMock(spec_set=[
            "handle_new_event",
            "get_state_for_room",
        ])

        self.datastore = hs.get_datastore()
        self.handlers = hs.get_handlers()
        self.notifier = hs.get_notifier()
        self.state_handler = hs.get_state_handler()
        self.distributor = hs.get_distributor()
        self.hs = hs

        self.handlers.federation_handler = self.federation

        self.distributor.declare("collect_presencelike_data")

        self.handlers.room_member_handler = RoomMemberHandler(self.hs)
        self.handlers.profile_handler = ProfileHandler(self.hs)
        self.room_member_handler = self.handlers.room_member_handler

        self.snapshot = Mock()
        self.datastore.snapshot_room.return_value = self.snapshot

        self.ratelimiter = hs.get_ratelimiter()
        self.ratelimiter.send_message.return_value = (True, 0)
开发者ID:gitter-badger,项目名称:synapse,代码行数:58,代码来源:test_room.py

示例3: setUp

# 需要导入模块: from synapse.server import HomeServer [as 别名]
# 或者: from synapse.server.HomeServer import get_ratelimiter [as 别名]
    def setUp(self):
        self.mock_resource = MockHttpResource(prefix=PATH_PREFIX)

        persistence_service = Mock(spec=["get_latest_pdus_in_context"])
        persistence_service.get_latest_pdus_in_context.return_value = []

        self.mock_config = NonCallableMock()
        self.mock_config.signing_key = [MockKey()]

        db_pool = SQLiteMemoryDbPool()
        yield db_pool.prepare()

        hs = HomeServer(
            "test",
            db_pool=db_pool,
            http_client=None,
            replication_layer=Mock(),
            persistence_service=persistence_service,
            clock=Mock(spec=[
                "call_later",
                "cancel_call_later",
                "time_msec",
                "time"
            ]),
            ratelimiter=NonCallableMock(spec_set=[
                "send_message",
            ]),
            config=self.mock_config,
        )
        self.ratelimiter = hs.get_ratelimiter()
        self.ratelimiter.send_message.return_value = (True, 0)
        hs.config.enable_registration_captcha = False

        hs.get_handlers().federation_handler = Mock()

        hs.get_clock().time_msec.return_value = 1000000
        hs.get_clock().time.return_value = 1000

        synapse.rest.register.register_servlets(hs, self.mock_resource)
        synapse.rest.events.register_servlets(hs, self.mock_resource)
        synapse.rest.room.register_servlets(hs, self.mock_resource)

        # register an account
        self.user_id = "sid1"
        response = yield self.register(self.user_id)
        self.token = response["access_token"]
        self.user_id = response["user_id"]

        # register a 2nd account
        self.other_user = "other1"
        response = yield self.register(self.other_user)
        self.other_token = response["access_token"]
        self.other_user = response["user_id"]
开发者ID:esaul,项目名称:synapse,代码行数:55,代码来源:test_events.py

示例4: setUp

# 需要导入模块: from synapse.server import HomeServer [as 别名]
# 或者: from synapse.server.HomeServer import get_ratelimiter [as 别名]
    def setUp(self):
        self.mock_resource = MockHttpResource(prefix=PATH_PREFIX)
        self.auth_user_id = self.user_id

        self.mock_config = NonCallableMock()
        self.mock_config.signing_key = [MockKey()]

        db_pool = SQLiteMemoryDbPool()
        yield db_pool.prepare()

        hs = HomeServer(
            "red",
            db_pool=db_pool,
            http_client=None,
            replication_layer=Mock(),
            ratelimiter=NonCallableMock(spec_set=[
                "send_message",
            ]),
            config=self.mock_config,
        )
        self.ratelimiter = hs.get_ratelimiter()
        self.ratelimiter.send_message.return_value = (True, 0)

        hs.get_handlers().federation_handler = Mock()

        def _get_user_by_token(token=None):
            return {
                "user": hs.parse_userid(self.auth_user_id),
                "admin": False,
                "device_id": None,
            }
        hs.get_auth().get_user_by_token = _get_user_by_token

        def _insert_client_ip(*args, **kwargs):
            return defer.succeed(None)
        hs.get_datastore().insert_client_ip = _insert_client_ip

        synapse.rest.room.register_servlets(hs, self.mock_resource)

        # Since I'm getting my own presence I need to exist as far as presence
        # is concerned.
        hs.get_handlers().presence_handler.registered_user(
            hs.parse_userid(self.user_id)
        )

        # create the room
        self.room_id = yield self.create_room_as(self.user_id)
开发者ID:alisheikh,项目名称:synapse,代码行数:49,代码来源:test_rooms.py

示例5: setUp

# 需要导入模块: from synapse.server import HomeServer [as 别名]
# 或者: from synapse.server.HomeServer import get_ratelimiter [as 别名]
    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

        db_pool = SQLiteMemoryDbPool()
        yield db_pool.prepare()

        self.mock_config = Mock()
        self.mock_config.signing_key = [MockKey()]

        hs = HomeServer("test",
                db_pool=db_pool,
                http_client=None,
                handlers=None,
                resource_for_federation=Mock(),
                replication_layer=self.mock_federation,
                config=self.mock_config,
                ratelimiter=NonCallableMock(spec_set=[
                    "send_message",
                ])
            )

        self.ratelimiter = hs.get_ratelimiter()
        self.ratelimiter.send_message.return_value = (True, 0)

        hs.handlers = ProfileHandlers(hs)

        self.store = hs.get_datastore()

        self.frank = hs.parse_userid("@1234ABCD:test")
        self.bob   = hs.parse_userid("@4567:test")
        self.alice = hs.parse_userid("@alice:remote")

        yield self.store.create_profile(self.frank.localpart)

        self.handler = hs.get_handlers().profile_handler

        # TODO(paul): Icky signal declarings.. booo
        hs.get_distributor().declare("changed_presencelike_data")
开发者ID:alisheikh,项目名称:synapse,代码行数:47,代码来源:test_profile.py

示例6: setUp

# 需要导入模块: from synapse.server import HomeServer [as 别名]
# 或者: from synapse.server.HomeServer import get_ratelimiter [as 别名]
    def setUp(self):
        self.hostname = "red"

        self.mock_config = NonCallableMock()
        self.mock_config.signing_key = [MockKey()]

        hs = HomeServer(
            self.hostname,
            db_pool=None,
            datastore=NonCallableMock(spec_set=[
                "store_room",
                "snapshot_room",
                "persist_event",
                "get_joined_hosts_for_room",
            ]),
            http_client=NonCallableMock(spec_set=[]),
            notifier=NonCallableMock(spec_set=["on_new_room_event"]),
            handlers=NonCallableMock(spec_set=[
                "room_creation_handler",
                "message_handler",
            ]),
            auth=NonCallableMock(spec_set=["check", "add_auth_events"]),
            ratelimiter=NonCallableMock(spec_set=[
                "send_message",
            ]),
            config=self.mock_config,
        )

        self.federation = NonCallableMock(spec_set=[
            "handle_new_event",
        ])

        self.handlers = hs.get_handlers()

        self.handlers.room_creation_handler = RoomCreationHandler(hs)
        self.room_creation_handler = self.handlers.room_creation_handler

        self.message_handler = self.handlers.message_handler

        self.ratelimiter = hs.get_ratelimiter()
        self.ratelimiter.send_message.return_value = (True, 0)
开发者ID:alisheikh,项目名称:synapse,代码行数:43,代码来源:test_room.py

示例7: setUp

# 需要导入模块: from synapse.server import HomeServer [as 别名]
# 或者: from synapse.server.HomeServer import get_ratelimiter [as 别名]
    def setUp(self):
        self.mock_resource = MockHttpResource(prefix=PATH_PREFIX)

        state_handler = Mock(spec=["handle_new_event"])
        state_handler.handle_new_event.return_value = True

        persistence_service = Mock(spec=["get_latest_pdus_in_context"])
        persistence_service.get_latest_pdus_in_context.return_value = []

        hs = HomeServer(
            "red",
            db_pool=None,
            http_client=None,
            datastore=MemoryDataStore(),
            replication_layer=Mock(),
            state_handler=state_handler,
            persistence_service=persistence_service,
            ratelimiter=NonCallableMock(spec_set=[
                "send_message",
            ]),
            config=NonCallableMock(),
        )
        self.ratelimiter = hs.get_ratelimiter()
        self.ratelimiter.send_message.return_value = (True, 0)

        hs.get_handlers().federation_handler = Mock()

        def _get_user_by_token(token=None):
            return {
                "user": hs.parse_userid(self.auth_user_id),
                "admin": False,
                "device_id": None,
            }
        hs.get_auth().get_user_by_token = _get_user_by_token

        self.auth_user_id = self.rmcreator_id

        synapse.rest.room.register_servlets(hs, self.mock_resource)

        self.auth = hs.get_auth()

        # create some rooms under the name rmcreator_id
        self.uncreated_rmid = "!aa:test"

        self.created_rmid = yield self.create_room_as(self.rmcreator_id,
                                                      is_public=False)

        self.created_public_rmid = yield self.create_room_as(self.rmcreator_id,
                                                             is_public=True)

        # send a message in one of the rooms
        self.created_rmid_msg_path = ("/rooms/%s/send/m.room.message/a1" %
                                (self.created_rmid))
        (code, response) = yield self.mock_resource.trigger(
                           "PUT",
                           self.created_rmid_msg_path,
                           '{"msgtype":"m.text","body":"test msg"}')
        self.assertEquals(200, code, msg=str(response))

        # set topic for public room
        (code, response) = yield self.mock_resource.trigger(
                           "PUT",
                           "/rooms/%s/state/m.room.topic" % self.created_public_rmid,
                           '{"topic":"Public Room Topic"}')
        self.assertEquals(200, code, msg=str(response))

        # auth as user_id now
        self.auth_user_id = self.user_id
开发者ID:gitter-badger,项目名称:synapse,代码行数:70,代码来源:test_rooms.py

示例8: setUp

# 需要导入模块: from synapse.server import HomeServer [as 别名]
# 或者: from synapse.server.HomeServer import get_ratelimiter [as 别名]
    def setUp(self):
        self.mock_config = Mock()
        self.mock_config.signing_key = [MockKey()]

        hs = HomeServer("test",
                clock=MockClock(),
                db_pool=None,
                datastore=Mock(spec=[
                    "set_presence_state",
                    "is_presence_visible",

                    "set_profile_displayname",

                    "get_rooms_for_user_where_membership_is",
                ]),
                handlers=None,
                resource_for_federation=Mock(),
                http_client=None,
                replication_layer=MockReplication(),
                ratelimiter=NonCallableMock(spec_set=[
                "send_message",
                ]),
                config=self.mock_config
        )
        self.ratelimiter = hs.get_ratelimiter()
        self.ratelimiter.send_message.return_value = (True, 0)
        hs.handlers = PresenceAndProfileHandlers(hs)

        self.datastore = hs.get_datastore()

        self.replication = hs.get_replication_layer()
        self.replication.send_edu = Mock()

        def send_edu(*args, **kwargs):
            # print "send_edu: %s, %s" % (args, kwargs)
            return defer.succeed((200, "OK"))
        self.replication.send_edu.side_effect = send_edu

        def get_profile_displayname(user_localpart):
            return defer.succeed("Frank")
        self.datastore.get_profile_displayname = get_profile_displayname

        def is_presence_visible(*args, **kwargs):
            return defer.succeed(False)
        self.datastore.is_presence_visible = is_presence_visible

        def get_profile_avatar_url(user_localpart):
            return defer.succeed("http://foo")
        self.datastore.get_profile_avatar_url = get_profile_avatar_url

        self.presence_list = [
            {"observed_user_id": "@banana:test"},
            {"observed_user_id": "@clementine:test"},
        ]
        def get_presence_list(user_localpart, accepted=None):
            return defer.succeed(self.presence_list)
        self.datastore.get_presence_list = get_presence_list

        def user_rooms_intersect(userlist):
            return defer.succeed(False)
        self.datastore.user_rooms_intersect = user_rooms_intersect

        self.handlers = hs.get_handlers()

        self.mock_update_client = Mock()
        def update(*args, **kwargs):
            # print "mock_update_client: %s, %s" %(args, kwargs)
            return defer.succeed(None)
        self.mock_update_client.side_effect = update

        self.handlers.presence_handler.push_update_to_clients = (
                self.mock_update_client)

        hs.handlers.room_member_handler = Mock(spec=[
            "get_rooms_for_user",
        ])
        hs.handlers.room_member_handler.get_rooms_for_user = (
                lambda u: defer.succeed([]))

        # Some local users to test with
        self.u_apple = hs.parse_userid("@apple:test")
        self.u_banana = hs.parse_userid("@banana:test")
        self.u_clementine = hs.parse_userid("@clementine:test")

        # Remote user
        self.u_potato = hs.parse_userid("@potato:remote")

        self.mock_get_joined = (
            self.datastore.get_rooms_for_user_where_membership_is
        )
开发者ID:alisheikh,项目名称:synapse,代码行数:92,代码来源:test_presencelike.py


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