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


Python User.get_by_key_name方法代码示例

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


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

示例1: bind

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get_by_key_name [as 别名]
 def bind(self, verifier):
   s = Session.get_by_key_name(self._jid)
   if s:
     token = oauth.OAuthToken.from_string(s.data)
     consumer = oauth.OAuthConsumer(config.OAUTH_CONSUMER_KEY, config.OAUTH_CONSUMER_SECRET)
     oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, token=token, verifier=verifier,
                                                                http_url=config.ACCESS_TOKEN_URL)
     signature_method_hmac_sha1 = oauth.OAuthSignatureMethod_HMAC_SHA1()
     oauth_request.sign_request(signature_method_hmac_sha1, consumer, token)
     try:
       result = urlfetch.fetch(oauth_request.to_url(), method=oauth_request.http_method)
     except urlfetch.Error:
       return 'Network Error!'
     try:
       token = oauth.OAuthToken.from_string(result.content)
     except BaseException:
       return 'Wrong verifier!'
     u = User.get_by_key_name(self._jid)
     if u:
       u.access_key = token.key
       u.access_secret = token.secret
       u.put()
     else:
       User(key_name=self._jid, access_key=token.key, access_secret=token.secret).put()
     s.data = None
     s.put()
     return 'Successfully bind your account.'
开发者ID:ayanamist,项目名称:Gmail-to-GTalk,代码行数:29,代码来源:xmpp.py

示例2: post

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get_by_key_name [as 别名]
 def post(self):
   jid = self.request.get('from').split('/')[0]
   u = User.get_by_key_name(jid)
   if u and u.enabled:
     try:
       Session(key_name=jid).put()
     except db.BadKeyError:
       pass
开发者ID:ayanamist,项目名称:Gmail-to-GTalk,代码行数:10,代码来源:xmpp.py

示例3: pause

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get_by_key_name [as 别名]
 def pause(self):
   u = User.get_by_key_name(self._jid)
   if u:
     u.enabled = False
     u.put()
     s = Session.get_by_key_name(self._jid)
     if s:
       s.delete()
     return 'Gmail notification is paused.'
开发者ID:ayanamist,项目名称:Gmail-to-GTalk,代码行数:11,代码来源:xmpp.py

示例4: remove

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get_by_key_name [as 别名]
 def remove(self):
   u = User.get_by_key_name(self._jid)
   if u:
     u.access_key = None
     u.access_secret = None
     u.enabled = False
     u.put()
     s = Session.get_by_key_name(self._jid)
     if s:
       s.delete()
     return 'Successfully remove your account.'
开发者ID:ayanamist,项目名称:Gmail-to-GTalk,代码行数:13,代码来源:xmpp.py

示例5: resume

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get_by_key_name [as 别名]
 def resume(self):
   u = User.get_by_key_name(self._jid)
   if u:
     u.enabled = True
     u.put()
     try:
       presence = xmpp.get_presence(self._jid)
     except xmpp.Error:
       presence = False
     if presence:
       try:
         Session(key_name=self._jid).put()
       except db.BadKeyError:
         pass
     return 'Gmail notification is resumed.'
开发者ID:ayanamist,项目名称:Gmail-to-GTalk,代码行数:17,代码来源:xmpp.py

示例6: get

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get_by_key_name [as 别名]
  def get(self):
    def handle_result(rpc):
      try:
        result = rpc.get_result()
      except urlfetch.Error:
        return
      else:
        jid = self.jids[id(rpc)]
        emails_map = parse(result.content)
        emails = list()
        for email in emails_map:
          if not Mail.get_by_key_name(email['id']):
            if Mail(key_name=email['id']).put():
              str = 'From: %(author)s\nTitle: %(title)s\nSummary: %(summary)s\nTime: %(time)s\n%(url)s' % email
              emails.insert(0, str)
        if emails:
          while CapabilitySet('xmpp').is_enabled():
            try:
              xmpp.send_message(jid, '\n\n'.join(emails))
            except xmpp.Error:
              pass
            else:
              break

    def create_callback(rpc):
      return lambda: handle_result(rpc)

    if not db.WRITE_CAPABILITY:
      return
    rpcs = []
    self.jids = {}
    for u in Session.all().filter('data =', None):
      jid = u.key().name()
      u = User.get_by_key_name(jid)
      token = oauth.OAuthToken(u.access_key, u.access_secret)
      consumer = oauth.OAuthConsumer(config.OAUTH_CONSUMER_KEY, config.OAUTH_CONSUMER_SECRET)
      oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, token=token, http_url=config.RESOURCE_URL)
      signature_method_hmac_sha1 = oauth.OAuthSignatureMethod_HMAC_SHA1()
      oauth_request.sign_request(signature_method_hmac_sha1, consumer, token)
      rpc = urlfetch.create_rpc()
      rpc.callback = create_callback(rpc)
      urlfetch.make_fetch_call(rpc, oauth_request.http_url, headers=oauth_request.to_header())
      rpcs.append(rpc)
      self.jids[id(rpc)] = jid
    for rpc in rpcs:
      rpc.wait()
开发者ID:ayanamist,项目名称:Gmail-to-GTalk,代码行数:48,代码来源:cron.py

示例7: check

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get_by_key_name [as 别名]
 def check(self):
   u = User.get_by_key_name(self._jid)
   if not u:
     return 'Please bind your account first.'
   token = oauth.OAuthToken(u.access_key, u.access_secret)
   consumer = oauth.OAuthConsumer(config.OAUTH_CONSUMER_KEY, config.OAUTH_CONSUMER_SECRET)
   oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, token=token, http_url=config.RESOURCE_URL)
   signature_method_hmac_sha1 = oauth.OAuthSignatureMethod_HMAC_SHA1()
   oauth_request.sign_request(signature_method_hmac_sha1, consumer, token)
   result = urlfetch.fetch(oauth_request.http_url, headers=oauth_request.to_header())
   emails_map = parse(result.content)
   emails = list()
   for email in emails_map:
     str = 'From: %(author)s\nTitle: %(title)s\nSummary: %(summary)s\nTime: %(time)s\n%(url)s' % email
     emails.insert(0, str)
     if db.WRITE_CAPABILITY:
       try:
         Mail(key_name=email['id']).put()
       except db.BadKeyError:
         pass
   if emails:
     return '\n\n'.join(emails)
   else:
     return 'No new emails.'
开发者ID:ayanamist,项目名称:Gmail-to-GTalk,代码行数:26,代码来源:xmpp.py


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