testing_support.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:codesearch-py 作者: chromium 项目源码 文件源码
def https_open(self, request):
    global disable_network
    if disable_network:
      raise URLError('Network access is disabled')

    url = request.get_full_url()
    data = GetRequestData(request)
    digest = DigestFromRequest(request)
    response_file_path = os.path.join(RESPONSE_DATA_DIR, digest)

    requests_seen.append(request)

    if os.path.exists(response_file_path):
      f = open(response_file_path, mode='rb')
      m = Message()
      m.add_header('Content-Type', 'application/json')
      resp = addinfourl(f, headers=m, url=url, code=200)
      resp.msg = 'Success'
      resp.code = 200
      return resp

    # The file was not there. Create a missing resource file.
    missing_response_file_path = os.path.join(RESPONSE_DATA_DIR,
                                              '{}.missing'.format(digest))
    with open(missing_response_file_path, mode='wb') as f:
      s = json.dumps({
          "url": url,
          "data": StringFromBytes(data),
          "digest": digest
      })
      f.write(s.encode('utf-8'))

    raise URLError(
        'URL is not cached. Created missing request record: {}.missing'.format(
            digest))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号