<s> from six import text_type <EOL> from peewee import DoesNotExist <EOL> from tornado . web import HTTPError <EOL> from pypi_server . db . users import Users <EOL> from pypi_server . handlers import route <EOL> from pypi_server . handlers . base import threaded <EOL> from pypi_server . handlers . api import JSONHandler <EOL> from pypi_server . handlers . api . login import authorization_required <EOL> from pypi_server . handlers . api . users import LOGIN_EXP , EMAIL_EXP <EOL> @ route ( '<STR_LIT>' ) <EOL> class UserHandler ( JSONHandler ) : <EOL> @ authorization_required ( is_admin = True ) <EOL> @ threaded <EOL> def get ( self , uid ) : <EOL> try : <EOL> user = Users . get ( id = uid ) <EOL> except DoesNotExist : <EOL> raise HTTPError ( <NUM_LIT> ) <EOL> self . response ( dict ( <EOL> id = user . id , <EOL> login = user . login , <EOL> email = user . email , <EOL> is_admin = user . is_admin , <EOL> disabled = user . disabled , <EOL> packages = list ( <EOL> map ( <EOL> lambda x : x . name , <EOL> user . package_set <EOL> ) <EOL> ) <EOL> ) ) <EOL> @ authorization_required ( is_admin = True ) <EOL> @ threaded <EOL> def put ( self , uid ) : <EOL> try : <EOL> user = Users . get ( id = uid ) <EOL> except DoesNotExist : <EOL> raise HTTPError ( <NUM_LIT> ) <EOL> try : <EOL> user . login = self . json . get ( "<STR_LIT>" , user . login ) <EOL> user . email = self . json . get ( "<STR_LIT:email>" , user . email ) <EOL> user . is_admin = bool ( self . json . get ( "<STR_LIT>" , user . is_admin ) ) <EOL> user . password = self . json . get ( "<STR_LIT:password>" , user . password ) <EOL> if not all ( ( <EOL> isinstance ( user . login , text_type ) , <EOL> isinstance ( user . email , text_type ) , <EOL> LOGIN_EXP . match ( str ( user . login ) ) is not None , <EOL> user . password and len ( user . password ) > <NUM_LIT:3> , <EOL> EMAIL_EXP . match ( str ( user . email ) ) is not None , <EOL> ) ) : <EOL> raise HTTPError ( <NUM_LIT> ) <EOL> except : <EOL> raise HTTPError ( <NUM_LIT> ) <EOL> user . save ( ) <EOL> self . response ( { <EOL> '<STR_LIT:id>' : user . id , <EOL> '<STR_LIT>' : user . login , <EOL> '<STR_LIT:email>' : user . email , <EOL> '<STR_LIT>' : user . is_admin , <EOL> } ) <EOL> @ authorization_required ( is_admin = True ) <EOL> @ threaded <EOL> def delete ( self , uid ) : <EOL> try : <EOL> user = Users . get ( id = uid ) <EOL> user . disabled = True <EOL> except ( KeyError , AssertionError ) : <EOL> raise HTTPError ( <NUM_LIT> ) <EOL> except DoesNotExist : <EOL> raise HTTPError ( <NUM_LIT> ) <EOL> else : <EOL> user . save ( ) <EOL> self . set_status ( <NUM_LIT> ) </s>
