gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 23:46:59 25 4
gpt4 key购买 nike

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

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

我想将该对象称为 webapp2.User,尽管从技术上讲它不是。这是因为还有其他名为 User 的对象,所以我可能会将具有此模型的 Users 命名为 webapp2_user 之类的名称,以区别于 fbuser(通过“使用 facebook 登录”来的 facebook 用户)和 google 用户。这似乎是一个很好的类(class),因为它允许将您的 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.
"""

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

最佳答案

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

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

关于python - 这样的进口合法还是不推荐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8545078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com