简体   繁体   English

如何在GAE上应用猴子补丁?

[英]How do I apply a monkeypatch to GAE?

Can you tell me how I apply this patch to google app engine as in where to put it? 您能告诉我如何将这个补丁应用到Google App Engine中吗? Thank you 谢谢

def _user_init(self, email=None, _auth_domain=None,
             _user_id=None, federated_identity=None, federated_provider=None):
  if not _auth_domain:
    _auth_domain = os.environ.get('AUTH_DOMAIN')
  assert _auth_domain

  if email is None and federated_identity is None:
    email = os.environ.get('USER_EMAIL', email)
    _user_id = os.environ.get('USER_ID', _user_id)
    federated_identity = os.environ.get('FEDERATED_IDENTITY',
                                        federated_identity)
    federated_provider = os.environ.get('FEDERATED_PROVIDER',
                                        federated_provider)

  if not email and not federated_identity:
    raise UserNotFoundError

  self.__email = email
  self.__federated_identity = federated_identity
  self.__federated_provider = federated_provider
  self.__auth_domain = _auth_domain
  self.__user_id = _user_id or None

users.User.__init__ = _user_init

Just use it as-is: Put that code in a module that gets imported before you use the relevant User module or datastore functionality. 只需按原样使用即可:在使用相关的用户模块或数据存储功能之前,将代码放在要导入的模块中。 I included the relevant line to patch the code (the last line) with the patch itself. 我包括了相关的行,以使用补丁本身对代码(最后一行)进行补丁。

I think, this belongs to some application as a grep within the appengine sdk, for 'federated_identity' does not result any clues. 我认为,这属于appengine sdk中的grep属于某个应用程序,因为“ federated_identity”不会产生任何线索。 BTW, you should be doing the same. 顺便说一句,您应该也这样做。 Grep (or WinGrep) for terms like 'federated' to see if this partial patch can be applied to any source. Grep(或WinGrep)中的“联​​合”之类的术语,以查看此部分补丁是否可以应用于任何来源。

Thanks for the updated link. 感谢您更新的链接。 The patch can be added to the file google/appengine/api/users.py 补丁可以添加到文件google / appengine / api / users.py

You might just need to add the last line: users.User.__init__ = _user_init 您可能只需要添加最后一行: users.User.__init__ = _user_init

I could figure this out after checking the latest code in the svn. 我可以在检查svn中的最新代码后弄清楚这一点。

Overriding the constructor like this is not safe. 这样覆盖构造函数并不安全。 If the internal implementation of the Users API changes in production, your application could break without warning. 如果用户API的内部实现在生产中发生更改,则您的应用程序可能会在没有警告的情况下中断。

What are you trying to accomplish here? 您想在这里完成什么? I don't see any custom logic; 我看不到任何自定义逻辑; it looks like you've just copied the constructor from the SDK verbatim. 看起来您刚刚从SDK逐字复制了构造函数。 If you need to add custom logic, try subclassing UserProperty and/or wrapping the users API calls instead. 如果需要添加自定义逻辑,请尝试将UserProperty子类化和/或包装用户API调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM