crls.py 文件源码

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

项目:cloak-server 作者: encryptme 项目源码 文件源码
def _fetch_crl(self, config, url, out, fmt):
        # type: (ConfigParser, str, str, str) -> bool
        updated = False

        url_hash = sha1(url.encode('utf-8')).hexdigest()
        headers = {}  # type: Dict[str, str]

        try:
            etag = config.get(CONFIG_SECTION, url_hash)
        except NoOptionError:
            pass
        else:
            headers = {'If-None-Match': etag}

        response = requests.get(url, headers=headers)

        if response.status_code == 200:
            crl_name = os.path.basename(urlsplit(url).path)
            crl_name, content = self._format_crl(crl_name, response.content, fmt)
            crl_path = os.path.join(out, crl_name)
            with open(crl_path, 'wb') as f:
                f.write(content)
            print(crl_path, file=self.stdout)
            updated = True

            if 'ETag' in response.headers:
                config.set(CONFIG_SECTION, url_hash, response.headers['ETag'])
        elif response.status_code == 304:
            pass
        else:
            print("Error {} downloading {}: {}".format(
                response.status_code, url, response.content
            ), file=self.stderr)

        return updated
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号