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
评论列表
文章目录