这样的进口合法还是不推荐?

发布于 2024-12-21 19:53:12 字数 1868 浏览 2 评论 0原文

像这样进行导入是否合法:

from webapp2_extras.appengine.auth.models import User as webapp2.User

我想将该对象称为 webapp2.User,即使从技术上讲它不是。这是因为还有其他名为 User 的对象,所以我可能会将具有此模型的 Users 命名为 webapp2_user 之类的名称,以区别于 fbuser(通过“使用 facebook 登录”来的 facebook 用户)和 google 用户。这似乎是一个很好的课程,因为它允许将您的谷歌或 Facebook 其他帐户与此模型连接:

class User(object):

    def get_id(self):
        """Returns this user's unique ID, which can be an integer or string."""

    @classmethod
    def get_by_auth_token(cls, user_id, token):
        """Returns a user object based on a user ID and token.

        :param user_id:
            The user_id of the requesting user.
        :param token:
            The token string to be verified.
        :returns:
            A tuple ``(User, timestamp)``, with a user object and
            the token timestamp, or ``(None, None)`` if both were not found.
        """

    @classmethod
    def get_by_auth_password(cls, auth_id, password):
        """Returns a user object, validating password.

        :param auth_id:
            Authentication id.
        :param password:
            Password to be checked.
        :returns:
            A user object, if found and password matches.
        :raises:
            ``auth.InvalidAuthIdError`` or ``auth.InvalidPasswordError``.
        """

    @classmethod
    def create_auth_token(cls, user_id):
        """Creates a new authorization token for a given user ID.

        :param user_id:
            User unique ID.
        :returns:
            A string with the authorization token.
        """

    @classmethod
    def delete_auth_token(cls, user_id, token):
        """Deletes a given authorization token.

        :param user_id:
            User unique ID.
        :param token:
            A string with the authorization token.
        """

感谢您对此的任何回答或评论

Is it legal to make an import like this:

from webapp2_extras.appengine.auth.models import User as webapp2.User

I'd like to refer to the object as webapp2.User even though it technically is not. This is because there are other object named User so I'd proabbly name Users with this model something like webapp2_user as distinct from fbuser (facebook user who comes via "login with facebook") and google users. It seems a good class since it admits connecting your google or facebook other account with this model:

class User(object):

    def get_id(self):
        """Returns this user's unique ID, which can be an integer or string."""

    @classmethod
    def get_by_auth_token(cls, user_id, token):
        """Returns a user object based on a user ID and token.

        :param user_id:
            The user_id of the requesting user.
        :param token:
            The token string to be verified.
        :returns:
            A tuple ``(User, timestamp)``, with a user object and
            the token timestamp, or ``(None, None)`` if both were not found.
        """

    @classmethod
    def get_by_auth_password(cls, auth_id, password):
        """Returns a user object, validating password.

        :param auth_id:
            Authentication id.
        :param password:
            Password to be checked.
        :returns:
            A user object, if found and password matches.
        :raises:
            ``auth.InvalidAuthIdError`` or ``auth.InvalidPasswordError``.
        """

    @classmethod
    def create_auth_token(cls, user_id):
        """Creates a new authorization token for a given user ID.

        :param user_id:
            User unique ID.
        :returns:
            A string with the authorization token.
        """

    @classmethod
    def delete_auth_token(cls, user_id, token):
        """Deletes a given authorization token.

        :param user_id:
            User unique ID.
        :param token:
            A string with the authorization token.
        """

Thank you for any answer or comment about this

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜是你 2024-12-28 19:53:12
from webapp2_extras.appengine.auth.models import User as webapp2.User

是无效语法,python 不允许您在 as webapp2.User 中使用 .,您应该使用 as webapp2_User 代替。

from webapp2_extras.appengine.auth.models import User as webapp2.User

is invalid syntax, python doesn't allow you to have a . in as webapp2.User you should use as webapp2_User instead.

一梦浮鱼 2024-12-28 19:53:12

这既是非法的,也是不推荐的。

如果您希望您的 User 基类在不同的应用程序中使用,您应该继承它并覆盖该应用程序中所需的部分。不要以这种方式导入。

It's both illegal and not recommended.

If you'd like your User base class to be used in different applications, you should inherit it and override needed parts in THAT app. Do not do importing this way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文