<s> from tornado . gen import coroutine <EOL> from tornado . web import HTTPError <EOL> from pypi_server . db . packages import PackageVersion , Package , PackageFile <EOL> from pypi_server . handlers import route <EOL> from pypi_server . handlers . api import JSONHandler <EOL> from pypi_server . handlers . api . login import authorization_required <EOL> from pypi_server . handlers . base import threaded <EOL> from pypi_server . handlers . pypi . proxy . client import normalize_package_name <EOL> @ route ( '<STR_LIT>' ) <EOL> class PackageVersionHandler ( JSONHandler ) : <EOL> @ authorization_required ( ) <EOL> @ coroutine <EOL> def get ( self , package , version ) : <EOL> ver = yield self . get_version ( package , version ) <EOL> self . response ( ( yield self . version_info ( ver ) ) ) <EOL> @ coroutine <EOL> def put ( self , package , version ) : <EOL> ver = yield self . get_version ( package , version ) <EOL> ver . hidden = self . json . get ( '<STR_LIT>' , ver . hidden ) <EOL> if ver . is_dirty : <EOL> yield self . thread_pool . submit ( ver . save ) <EOL> self . response ( ( yield self . version_info ( ver ) ) ) <EOL> @ authorization_required ( is_admin = True ) <EOL> @ coroutine <EOL> def delete ( self , package , version ) : <EOL> ver = yield self . get_version ( package , version ) <EOL> yield self . thread_pool . submit ( ver . delete_instance , recursive = True ) <EOL> @ staticmethod <EOL> @ threaded <EOL> def get_version ( package , version ) : <EOL> package = normalize_package_name ( package ) <EOL> q = PackageVersion . select ( ) . join ( Package ) . join ( PackageFile ) . where ( <EOL> Package . lower_name == package , <EOL> PackageVersion . version == version , <EOL> ) . limit ( <NUM_LIT:1> ) <EOL> if not q . count ( ) : <EOL> raise HTTPError ( <NUM_LIT> ) <EOL> return q [ <NUM_LIT:0> ] <EOL> @ staticmethod <EOL> @ threaded <EOL> def version_info ( version ) : <EOL> return { <EOL> "<STR_LIT:version>" : str ( version . version ) , <EOL> "<STR_LIT>" : version . hidden , <EOL> "<STR_LIT>" : version . downloads , <EOL> "<STR_LIT>" : version . author , <EOL> "<STR_LIT>" : version . author_email , <EOL> "<STR_LIT>" : version . maintainer , <EOL> "<STR_LIT>" : version . maintainer_email , <EOL> "<STR_LIT>" : version . home_page , <EOL> "<STR_LIT>" : version . license , <EOL> "<STR_LIT>" : version . summary , <EOL> "<STR_LIT:description>" : version . description , <EOL> "<STR_LIT>" : version . keywords , <EOL> "<STR_LIT>" : version . platform , <EOL> "<STR_LIT>" : version . download_url , <EOL> "<STR_LIT>" : version . classifiers , <EOL> "<STR_LIT>" : version . requires , <EOL> "<STR_LIT>" : version . requires_dist , <EOL> "<STR_LIT>" : version . provides , <EOL> "<STR_LIT>" : version . provides_dist , <EOL> "<STR_LIT>" : version . requires_external , <EOL> "<STR_LIT>" : version . requires_python , <EOL> "<STR_LIT>" : version . obsoletes , <EOL> "<STR_LIT>" : version . obsoletes_dist , <EOL> "<STR_LIT>" : version . project_url , <EOL> "<STR_LIT>" : list ( map ( <EOL> lambda f : dict ( <EOL> name = f . basename , <EOL> url = "<STR_LIT>" . format ( version . package . lower_name , version . version , f . basename ) <EOL> ) , <EOL> version . packagefile_set <EOL> ) ) <EOL> } </s>
