<s> from pyramid . httpexceptions import HTTPTemporaryRedirect , HTTPNotFound <EOL> from pyramid . view import view_config <EOL> from sqlalchemy . orm . exc import NoResultFound <EOL> from warehouse . cache . origin import origin_cache <EOL> from warehouse . packaging . models import File <EOL> @ view_config ( <EOL> route_name = "<STR_LIT>" , <EOL> decorator = [ <EOL> origin_cache ( <EOL> <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> , <EOL> stale_while_revalidate = <NUM_LIT:1> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> , <EOL> stale_if_error = <NUM_LIT:5> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> , <EOL> ) , <EOL> ] , <EOL> ) <EOL> def file_redirect ( request ) : <EOL> pyversion , first , name , filename = request . matchdict [ "<STR_LIT:path>" ] . split ( "<STR_LIT:/>" ) <EOL> if first != name [ <NUM_LIT:0> ] : <EOL> return HTTPNotFound ( ) <EOL> if filename . endswith ( "<STR_LIT>" ) : <EOL> filename = filename [ : - <NUM_LIT:4> ] <EOL> signature = True <EOL> else : <EOL> signature = False <EOL> try : <EOL> file_ = ( <EOL> request . db . query ( File ) <EOL> . filter ( ( File . python_version == pyversion ) & <EOL> ( File . name == name ) & <EOL> ( File . filename == filename ) ) <EOL> . one ( ) <EOL> ) <EOL> except NoResultFound : <EOL> return HTTPNotFound ( ) <EOL> if signature : <EOL> if file_ . has_signature : <EOL> return HTTPTemporaryRedirect ( <EOL> request . route_path ( "<STR_LIT>" , path = file_ . pgp_path ) <EOL> ) <EOL> else : <EOL> return HTTPNotFound ( ) <EOL> return HTTPTemporaryRedirect ( <EOL> request . route_path ( "<STR_LIT>" , path = file_ . path ) <EOL> ) </s>
