"""Named fixed PDF recipe, localonly. No automatic retry, upload, alternate version or mirror.""" import argparse,hashlib,urllib.request from pathlib import Path from io_helpers import PACKAGE,read_json class NoRedirect(urllib.request.HTTPRedirectHandler): def redirect_request(self,*args,**kwargs):return None def main(): parser=argparse.ArgumentParser();parser.add_argument('--cache-file',type=Path);parser.add_argument('--output',type=Path,default=Path('reader-private/hill-v2.pdf'));args=parser.parse_args() if args.output.exists():raise FileExistsError('Refuse overwriting local source') expected=next(row for row in read_json(PACKAGE/'source-identities.json')['sources']if row['file']=='hill-v2.pdf') if args.cache_file:body=args.cache_file.read_bytes();origin='explicitlocalcache;0HTTP' else: url='https://arxiv.org/pdf/1812.01486v2';request=urllib.request.Request(url,headers={'Accept-Encoding':'identity','User-Agent':'SandboxPhysics fixedHill source tutorial'}) with urllib.request.build_opener(NoRedirect).open(request,timeout=30)as response: if response.status!=200 or response.geturl()!=url:raise ValueError('Unexpected source status/URL') if int(response.headers.get('Content-Length',0))>1200000:raise ValueError('Declared source cap exceeded') body=response.read(1200001) origin='fixedupstreamsingleHTTP;noautomaticretry' if len(body)!=expected['bytes']or hashlib.sha256(body).hexdigest()!=expected['sha256']:raise ValueError('Sourcebytes/SHA changed; stop and review fixedversion') args.output.parent.mkdir(parents=True,exist_ok=True);args.output.write_bytes(body);print('PASS:'+origin+';PDF identity verified;original remains local') if __name__=='__main__':main()