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


Python UserID.from_string方法代码示例

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


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

示例1: on_POST

# 需要导入模块: from synapse.types import UserID [as 别名]
# 或者: from synapse.types.UserID import from_string [as 别名]
    def on_POST(self, request, target_user_id):
        body = parse_json_object_from_request(request, allow_empty_body=True)
        erase = body.get("erase", False)
        if not isinstance(erase, bool):
            raise SynapseError(
                http_client.BAD_REQUEST,
                "Param 'erase' must be a boolean, if given",
                Codes.BAD_JSON,
            )

        UserID.from_string(target_user_id)
        requester = yield self.auth.get_user_by_req(request)
        is_admin = yield self.auth.is_server_admin(requester.user)

        if not is_admin:
            raise AuthError(403, "You are not a server admin")

        result = yield self._deactivate_account_handler.deactivate_account(
            target_user_id, erase,
        )
        if result:
            id_server_unbind_result = "success"
        else:
            id_server_unbind_result = "no-support"

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

示例2: create_and_send_event

# 需要导入模块: from synapse.types import UserID [as 别名]
# 或者: from synapse.types.UserID import from_string [as 别名]
    def create_and_send_event(self, event_dict, ratelimit=True,
                              token_id=None, txn_id=None, is_guest=False):
        """ Given a dict from a client, create and handle a new event.

        Creates an FrozenEvent object, filling out auth_events, prev_events,
        etc.

        Adds display names to Join membership events.

        Persists and notifies local clients and federation.

        Args:
            event_dict (dict): An entire event
        """
        builder = self.event_builder_factory.new(event_dict)

        self.validator.validate_new(builder)

        if ratelimit:
            self.ratelimit(builder.user_id)
        # TODO(paul): Why does 'event' not have a 'user' object?
        user = UserID.from_string(builder.user_id)
        assert self.hs.is_mine(user), "User must be our own: %s" % (user,)

        if builder.type == EventTypes.Member:
            membership = builder.content.get("membership", None)
            if membership == Membership.JOIN:
                joinee = UserID.from_string(builder.state_key)
                # If event doesn't include a display name, add one.
                yield self.distributor.fire(
                    "collect_presencelike_data",
                    joinee,
                    builder.content
                )

        if token_id is not None:
            builder.internal_metadata.token_id = token_id

        if txn_id is not None:
            builder.internal_metadata.txn_id = txn_id

        event, context = yield self._create_new_client_event(
            builder=builder,
        )

        if event.type == EventTypes.Member:
            member_handler = self.hs.get_handlers().room_member_handler
            yield member_handler.change_membership(event, context, is_guest=is_guest)
        else:
            yield self.handle_new_client_event(
                event=event,
                context=context,
            )

        if event.type == EventTypes.Message:
            presence = self.hs.get_handlers().presence_handler
            with PreserveLoggingContext():
                presence.bump_presence_active_time(user)

        defer.returnValue(event)
开发者ID:Xe,项目名称:synapse,代码行数:62,代码来源:message.py

示例3: on_POST

# 需要导入模块: from synapse.types import UserID [as 别名]
# 或者: from synapse.types.UserID import from_string [as 别名]
    def on_POST(self, request, target_user_id):
        """Post request to get specific number of users from Synapse..
        This needs user to have administrator access in Synapse.
        Example:
            http://localhost:8008/_synapse/admin/v1/users_paginate/
            @admin:user?access_token=admin_access_token
        JsonBodyToSend:
            {
                "start": "0",
                "limit": "10
            }
        Returns:
            200 OK with json object {list[dict[str, Any]], count} or empty object.
        """
        yield assert_requester_is_admin(self.auth, request)
        UserID.from_string(target_user_id)

        order = "name"  # order by name in user table
        params = parse_json_object_from_request(request)
        assert_params_in_dict(params, ["limit", "start"])
        limit = params['limit']
        start = params['start']
        logger.info("limit: %s, start: %s", limit, start)

        ret = yield self.handlers.admin_handler.get_users_paginate(
            order, start, limit
        )
        defer.returnValue((200, ret))
开发者ID:matrix-org,项目名称:synapse,代码行数:30,代码来源:__init__.py

示例4: on_POST

# 需要导入模块: from synapse.types import UserID [as 别名]
# 或者: from synapse.types.UserID import from_string [as 别名]
    def on_POST(self, request, room_id, membership_action, txn_id=None):
        user, client = yield self.auth.get_user_by_req(request)

        content = _parse_json(request)

        # target user is you unless it is an invite
        state_key = user.to_string()
        if membership_action in ["invite", "ban", "kick"]:
            if "user_id" not in content:
                raise SynapseError(400, "Missing user_id key.")
            state_key = content["user_id"]
            # make sure it looks like a user ID; it'll throw if it's invalid.
            UserID.from_string(state_key)

            if membership_action == "kick":
                membership_action = "leave"

        msg_handler = self.handlers.message_handler
        yield msg_handler.create_and_send_event(
            {
                "type": EventTypes.Member,
                "content": {"membership": unicode(membership_action)},
                "room_id": room_id,
                "sender": user.to_string(),
                "state_key": state_key,
            },
            client=client,
            txn_id=txn_id,
        )

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

示例5: test_compare

# 需要导入模块: from synapse.types import UserID [as 别名]
# 或者: from synapse.types.UserID import from_string [as 别名]
    def test_compare(self):
        userA = UserID.from_string("@userA:my.domain")
        userAagain = UserID.from_string("@userA:my.domain")
        userB = UserID.from_string("@userB:my.domain")

        self.assertTrue(userA == userAagain)
        self.assertTrue(userA != userB)
开发者ID:heavenlyhash,项目名称:synapse,代码行数:9,代码来源:test_types.py

示例6: test_compare

# 需要导入模块: from synapse.types import UserID [as 别名]
# 或者: from synapse.types.UserID import from_string [as 别名]
    def test_compare(self):
        userA = UserID.from_string("@userA:my.domain", hs=mock_homeserver)
        userAagain = UserID.from_string("@userA:my.domain", hs=mock_homeserver)
        userB = UserID.from_string("@userB:my.domain", hs=mock_homeserver)

        self.assertTrue(userA == userAagain)
        self.assertTrue(userA != userB)
开发者ID:martindale,项目名称:synapse,代码行数:9,代码来源:test_types.py

示例7: setUp

# 需要导入模块: from synapse.types import UserID [as 别名]
# 或者: from synapse.types.UserID import from_string [as 别名]
    def setUp(self):
        self.mock_federation = Mock()
        self.mock_registry = Mock()

        self.query_handlers = {}

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

        self.mock_registry.register_query_handler = register_query_handler

        hs = yield setup_test_homeserver(
            self.addCleanup,
            http_client=None,
            handlers=None,
            resource_for_federation=Mock(),
            federation_client=self.mock_federation,
            federation_server=Mock(),
            federation_registry=self.mock_registry,
            ratelimiter=NonCallableMock(spec_set=["can_do_action"]),
        )

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

        self.store = hs.get_datastore()

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

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

        self.handler = hs.get_profile_handler()
开发者ID:matrix-org,项目名称:synapse,代码行数:36,代码来源:test_profile.py

示例8: setUp

# 需要导入模块: from synapse.types import UserID [as 别名]
# 或者: from synapse.types.UserID import from_string [as 别名]
    def setUp(self):
        hs = yield setup_test_homeserver(clock=MockClock())

        self.store = PresenceStore(hs)

        self.u_apple = UserID.from_string("@apple:test")
        self.u_banana = UserID.from_string("@banana:test")
开发者ID:Vutsuak16,项目名称:synapse,代码行数:9,代码来源:test_presence.py

示例9: on_POST

# 需要导入模块: from synapse.types import UserID [as 别名]
# 或者: from synapse.types.UserID import from_string [as 别名]
    def on_POST(self, request, room_id, membership_action, txn_id=None):
        user, token_id, is_guest = yield self.auth.get_user_by_req(
            request,
            allow_guest=True
        )

        if is_guest and membership_action not in {Membership.JOIN, Membership.LEAVE}:
            raise AuthError(403, "Guest access not allowed")

        content = _parse_json(request)

        # target user is you unless it is an invite
        state_key = user.to_string()

        if membership_action == "invite" and self._has_3pid_invite_keys(content):
            yield self.handlers.room_member_handler.do_3pid_invite(
                room_id,
                user,
                content["medium"],
                content["address"],
                content["id_server"],
                token_id,
                txn_id
            )
            defer.returnValue((200, {}))
            return
        elif membership_action in ["invite", "ban", "kick"]:
            if "user_id" in content:
                state_key = content["user_id"]
            else:
                raise SynapseError(400, "Missing user_id key.")

            # make sure it looks like a user ID; it'll throw if it's invalid.
            UserID.from_string(state_key)

            if membership_action == "kick":
                membership_action = "leave"

        msg_handler = self.handlers.message_handler

        content = {"membership": unicode(membership_action)}
        if is_guest:
            content["kind"] = "guest"

        yield msg_handler.create_and_send_event(
            {
                "type": EventTypes.Member,
                "content": content,
                "room_id": room_id,
                "sender": user.to_string(),
                "state_key": state_key,
            },
            token_id=token_id,
            txn_id=txn_id,
            is_guest=is_guest,
        )

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

示例10: handle_new_client_event

# 需要导入模块: from synapse.types import UserID [as 别名]
# 或者: from synapse.types.UserID import from_string [as 别名]
    def handle_new_client_event(self, event, context, extra_destinations=[],
                                extra_users=[], suppress_auth=False):
        yield run_on_reactor()

        # We now need to go and hit out to wherever we need to hit out to.

        if not suppress_auth:
            self.auth.check(event, auth_events=context.current_state)

        yield self.store.persist_event(event, context=context)

        federation_handler = self.hs.get_handlers().federation_handler

        if event.type == EventTypes.Member:
            if event.content["membership"] == Membership.INVITE:
                invitee = UserID.from_string(event.state_key)
                if not self.hs.is_mine(invitee):
                    # TODO: Can we add signature from remote server in a nicer
                    # way? If we have been invited by a remote server, we need
                    # to get them to sign the event.
                    returned_invite = yield federation_handler.send_invite(
                        invitee.domain,
                        event,
                    )

                    # TODO: Make sure the signatures actually are correct.
                    event.signatures.update(
                        returned_invite.signatures
                    )

        destinations = set(extra_destinations)
        for k, s in context.current_state.items():
            try:
                if k[0] == EventTypes.Member:
                    if s.content["membership"] == Membership.JOIN:
                        destinations.add(
                            UserID.from_string(s.state_key).domain
                        )
            except SynapseError:
                logger.warn(
                    "Failed to get destination from event %s", s.event_id
                )

        # Don't block waiting on waking up all the listeners.
        d = self.notifier.on_new_room_event(event, extra_users=extra_users)

        def log_failure(f):
            logger.warn(
                "Failed to notify about %s: %s",
                event.event_id, f.value
            )

        d.addErrback(log_failure)

        yield federation_handler.handle_new_event(
            event, destinations=destinations,
        )
开发者ID:cryptoempathy,项目名称:synapse,代码行数:59,代码来源:_base.py

示例11: setUp

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

        hs = yield setup_test_homeserver(
            datastore=Mock(spec=[
                "has_presence_state",
                "get_presence_state",
                "allow_presence_visible",
                "is_presence_visible",
                "add_presence_list_pending",
                "set_presence_list_accepted",
                "del_presence_list",
                "get_presence_list",
                "insert_client_ip",
            ]),
            http_client=None,
            resource_for_client=self.mock_resource,
            resource_for_federation=self.mock_resource,
        )
        hs.handlers = JustPresenceHandlers(hs)

        self.datastore = hs.get_datastore()
        self.datastore.get_app_service_by_token = Mock(return_value=None)

        def has_presence_state(user_localpart):
            return defer.succeed(
                user_localpart in ("apple", "banana",)
            )
        self.datastore.has_presence_state = has_presence_state

        def _get_user_by_token(token=None):
            return {
                "user": UserID.from_string(myid),
                "admin": False,
                "device_id": None,
                "token_id": 1,
            }

        hs.handlers.room_member_handler = Mock(
            spec=[
                "get_joined_rooms_for_user",
            ]
        )

        hs.get_v1auth().get_user_by_token = _get_user_by_token

        presence.register_servlets(hs, self.mock_resource)

        self.u_apple = UserID.from_string("@apple:test")
        self.u_banana = UserID.from_string("@banana:test")
开发者ID:heavenlyhash,项目名称:synapse,代码行数:52,代码来源:test_presence.py

示例12: setUp

# 需要导入模块: from synapse.types import UserID [as 别名]
# 或者: from synapse.types.UserID import from_string [as 别名]
    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,代码行数:17,代码来源:test_state.py

示例13: on_POST

# 需要导入模块: from synapse.types import UserID [as 别名]
# 或者: from synapse.types.UserID import from_string [as 别名]
    def on_POST(self, request, target_user_id):
        UserID.from_string(target_user_id)
        requester = yield self.auth.get_user_by_req(request)
        is_admin = yield self.auth.is_server_admin(requester.user)

        if not is_admin:
            raise AuthError(403, "You are not a server admin")

        # FIXME: Theoretically there is a race here wherein user resets password
        # using threepid.
        yield self.store.user_delete_access_tokens(target_user_id)
        yield self.store.user_delete_threepids(target_user_id)
        yield self.store.user_set_password_hash(target_user_id, None)

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

示例14: _recv_edu

# 需要导入模块: from synapse.types import UserID [as 别名]
# 或者: from synapse.types.UserID import from_string [as 别名]
    def _recv_edu(self, origin, content):
        room_id = content["room_id"]
        user_id = content["user_id"]

        # Check that the string is a valid user id
        UserID.from_string(user_id)

        domains = yield self.store.get_joined_hosts_for_room(room_id)

        if self.server_name in domains:
            self._push_update_local(
                room_id=room_id,
                user_id=user_id,
                typing=content["typing"]
            )
开发者ID:0-T-0,项目名称:synapse,代码行数:17,代码来源:typing.py

示例15: setUp

# 需要导入模块: from synapse.types import UserID [as 别名]
# 或者: from synapse.types.UserID import from_string [as 别名]
    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,代码行数:17,代码来源:test_stream.py


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