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


Python FetchResponse.toMessage方法代码示例

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


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

示例1: Respond

# 需要导入模块: from openid.extensions.ax import FetchResponse [as 别名]
# 或者: from openid.extensions.ax.FetchResponse import toMessage [as 别名]
  def Respond(self, oidresponse):
    """Send an OpenID response.

    Args:
      oidresponse: OpenIDResponse
      The response to send, usually created by OpenIDRequest.answer().
    """
    logging.warning('Respond: oidresponse.request.mode ' + oidresponse.request.mode)

    if oidresponse.request.mode in ['checkid_immediate', 'checkid_setup']:
      # user = users.get_current_user()
      user = self.get_current_user()
      if user:
        from openid.extensions.sreg import SRegRequest,SRegResponse
        sreg_req = SRegRequest.fromOpenIDRequest(oidresponse.request)
        logging.info("sreg_req:%s",sreg_req.allRequestedFields())
        if sreg_req.wereFieldsRequested():
          user_data = {'nickname':user.nickname,
                       'email':user.email}
          sreg_resp = SRegResponse.extractResponse(sreg_req, user_data)
          sreg_resp.toMessage(oidresponse.fields)
        # add nickname, using the Simple Registration Extension:
        # http://www.openidenabled.com/openid/simple-registration-extension/
        #oidresponse.fields.setArg('http://openid.net/sreg/1.0', 'nickname', user.nickname)
        #oidresponse.fields.setArg('http://openid.net/sreg/1.0', 'email', user.email)
        #oidresponse.fields.setArg('http://openid.net/srv/ax/1.0', 'nickname', user.nickname)
        #oidresponse.fields.setArg('http://openid.net/srv/ax/1.0', 'email', user.email)
        from openid.extensions.ax import FetchRequest, FetchResponse	
        res ={'nickname':user.nickname,'email':user.email,'attr0':user.email,'attr1':user.nickname}
        ax_req = FetchRequest.fromOpenIDRequest(oidresponse.request)
        logging.info("ax_req:%s",ax_req.getRequiredAttrs())
        ax_res = FetchResponse()
        for x in ax_req.iterAttrs():
          ax_res.addValue(x.type_uri,res[x.alias] )
        ax_res.toMessage(oidresponse.fields)       
        pass
    logging.info('Using response: %s' % oidresponse)
    encoded_response = oidserver.encodeResponse(oidresponse)

    # update() would be nice, but wsgiref.headers.Headers doesn't implement it
    for header, value in encoded_response.headers.items():
      self.response.headers[header] = str(value)

    if encoded_response.code in (301, 302):
      self.redirect(self.response.headers['location'])
    else:
      self.response.set_status(encoded_response.code)

    if encoded_response.body:
      logging.debug('Sending response body: %s' % encoded_response.body)
      self.response.out.write(encoded_response.body)
    else:
      self.response.out.write('')
开发者ID:patou,项目名称:facebook-openid,代码行数:55,代码来源:provider.py


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