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


Python HomeServer.get_distributor方法代码示例

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


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

示例1: setUp

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

        hs = HomeServer("test",
                db_pool=None,
                http_client=None,
                datastore=Mock(spec=[
                    "get_profile_displayname",
                    "set_profile_displayname",
                    "get_profile_avatar_url",
                    "set_profile_avatar_url",
                ]),
                handlers=None,
                resource_for_federation=Mock(),
                replication_layer=self.mock_federation,
            )
        hs.handlers = ProfileHandlers(hs)

        self.datastore = hs.get_datastore()

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

        self.handler = hs.get_handlers().profile_handler

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

示例2: setUp

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

        hs = HomeServer("test",
                db_pool=db_pool,
                http_client=None,
                handlers=None,
                resource_for_federation=Mock(),
                replication_layer=self.mock_federation,
            )
        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:gitter-badger,项目名称:synapse,代码行数:36,代码来源:test_profile.py

示例3: setUp

# 需要导入模块: from synapse.server import HomeServer [as 别名]
# 或者: from synapse.server.HomeServer import get_distributor [as 别名]
 def setUp(self):
     self.mock_resource = MockHttpResource()
     self.mock_http_client = Mock(spec=[
         "get_json",
         "put_json",
     ])
     self.mock_persistence = Mock(spec=[
         "get_current_state_for_context",
         "get_pdu",
         "persist_event",
         "update_min_depth_for_context",
         "prep_send_transaction",
         "delivered_txn",
         "get_received_txn_response",
         "set_received_txn_response",
     ])
     self.mock_persistence.get_received_txn_response.return_value = (
             defer.succeed(None)
     )
     self.mock_config = Mock()
     self.mock_config.signing_key = [MockKey()]
     self.clock = MockClock()
     hs = HomeServer("test",
             resource_for_federation=self.mock_resource,
             http_client=self.mock_http_client,
             db_pool=None,
             datastore=self.mock_persistence,
             clock=self.clock,
             config=self.mock_config,
             keyring=Mock(),
     )
     self.federation = initialize_http_replication(hs)
     self.distributor = hs.get_distributor()
开发者ID:gitter-badger,项目名称:synapse,代码行数:35,代码来源:test_federation.py

示例4: setUp

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

示例5: setUp

# 需要导入模块: from synapse.server import HomeServer [as 别名]
# 或者: from synapse.server.HomeServer import get_distributor [as 别名]
 def setUp(self):
     self.mock_resource = MockHttpResource()
     self.mock_http_client = Mock(spec=[
         "get_json",
         "put_json",
     ])
     self.mock_persistence = Mock(spec=[
         "prep_send_transaction",
         "delivered_txn",
         "get_received_txn_response",
         "set_received_txn_response",
         "get_destination_retry_timings",
         "get_auth_chain",
     ])
     self.mock_persistence.get_received_txn_response.return_value = (
         defer.succeed(None)
     )
     self.mock_persistence.get_destination_retry_timings.return_value = (
         defer.succeed(DestinationsTable.EntryType("", 0, 0))
     )
     self.mock_persistence.get_auth_chain.return_value = []
     self.mock_config = Mock()
     self.mock_config.signing_key = [MockKey()]
     self.clock = MockClock()
     hs = HomeServer(
         "test",
         resource_for_federation=self.mock_resource,
         http_client=self.mock_http_client,
         db_pool=None,
         datastore=self.mock_persistence,
         clock=self.clock,
         config=self.mock_config,
         keyring=Mock(),
     )
     self.federation = initialize_http_replication(hs)
     self.distributor = hs.get_distributor()
开发者ID:alisheikh,项目名称:synapse,代码行数:38,代码来源:test_federation.py

示例6: setUp

# 需要导入模块: from synapse.server import HomeServer [as 别名]
# 或者: from synapse.server.HomeServer import get_distributor [as 别名]

#.........这里部分代码省略.........
                config=self.mock_config,
                keyring=Mock(),
            )
        hs.handlers = JustPresenceHandlers(hs)

        self.datastore = hs.get_datastore()

        def get_received_txn_response(*args):
            return defer.succeed(None)
        self.datastore.get_received_txn_response = get_received_txn_response

        self.handler = hs.get_handlers().presence_handler
        self.event_source = hs.get_event_sources().sources["presence"]

        # Mock the RoomMemberHandler
        hs.handlers.room_member_handler = Mock(spec=[
            "get_rooms_for_user",
            "get_room_members",
        ])
        self.room_member_handler = hs.handlers.room_member_handler

        self.room_members = []

        def get_rooms_for_user(user):
            if user in self.room_members:
                return defer.succeed(["a-room"])
            else:
                return defer.succeed([])
        self.room_member_handler.get_rooms_for_user = get_rooms_for_user

        def get_room_members(room_id):
            if room_id == "a-room":
                return defer.succeed(self.room_members)
            else:
                return defer.succeed([])
        self.room_member_handler.get_room_members = get_room_members

        def get_room_hosts(room_id):
            if room_id == "a-room":
                hosts = set([u.domain for u in self.room_members])
                return defer.succeed(hosts)
            else:
                return defer.succeed([])
        self.datastore.get_joined_hosts_for_room = get_room_hosts

        def user_rooms_intersect(userlist):
            room_member_ids = map(lambda u: u.to_string(), self.room_members)

            shared = all(map(lambda i: i in room_member_ids, userlist))
            return defer.succeed(shared)
        self.datastore.user_rooms_intersect = user_rooms_intersect

        @defer.inlineCallbacks
        def fetch_room_distributions_into(room_id, localusers=None,
                remotedomains=None, ignore_user=None):

            members = yield get_room_members(room_id)
            for member in members:
                if ignore_user is not None and member == ignore_user:
                    continue

                if member.is_mine:
                    if localusers is not None:
                        localusers.add(member)
                else:
                    if remotedomains is not None:
                        remotedomains.add(member.domain)
        self.room_member_handler.fetch_room_distributions_into = (
                fetch_room_distributions_into)

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

        def is_presence_visible(observer_userid, observed_localpart):
            if (observed_localpart == "clementine" and
                observer_userid == "@banana:test"):
                return False
            return False
        self.datastore.is_presence_visible = is_presence_visible

        self.distributor = hs.get_distributor()
        self.distributor.declare("user_joined_room")

        # 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")
        self.u_durian = hs.parse_userid("@durian:test")
        self.u_elderberry = hs.parse_userid("@elderberry:test")

        # Remote user
        self.u_onion = hs.parse_userid("@onion:farm")
        self.u_potato = hs.parse_userid("@potato:remote")
开发者ID:winsontan520,项目名称:synapse,代码行数:104,代码来源:test_presence.py


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