<s> """<STR_LIT>""" <EOL> from twisted . internet import defer <EOL> from . base import ClientV1RestServlet , client_path_patterns <EOL> from synapse . types import UserID <EOL> from synapse . http . servlet import parse_json_object_from_request <EOL> class ProfileDisplaynameRestServlet ( ClientV1RestServlet ) : <EOL> PATTERNS = client_path_patterns ( "<STR_LIT>" ) <EOL> @ defer . inlineCallbacks <EOL> def on_GET ( self , request , user_id ) : <EOL> user = UserID . from_string ( user_id ) <EOL> displayname = yield self . handlers . profile_handler . get_displayname ( <EOL> user , <EOL> ) <EOL> ret = { } <EOL> if displayname is not None : <EOL> ret [ "<STR_LIT>" ] = displayname <EOL> defer . returnValue ( ( <NUM_LIT:200> , ret ) ) <EOL> @ defer . inlineCallbacks <EOL> def on_PUT ( self , request , user_id ) : <EOL> requester = yield self . auth . get_user_by_req ( request , allow_guest = True ) <EOL> user = UserID . from_string ( user_id ) <EOL> content = parse_json_object_from_request ( request ) <EOL> try : <EOL> new_name = content [ "<STR_LIT>" ] <EOL> except : <EOL> defer . returnValue ( ( <NUM_LIT> , "<STR_LIT>" ) ) <EOL> yield self . handlers . profile_handler . set_displayname ( <EOL> user , requester , new_name ) <EOL> defer . returnValue ( ( <NUM_LIT:200> , { } ) ) <EOL> def on_OPTIONS ( self , request , user_id ) : <EOL> return ( <NUM_LIT:200> , { } ) <EOL> class ProfileAvatarURLRestServlet ( ClientV1RestServlet ) : <EOL> PATTERNS = client_path_patterns ( "<STR_LIT>" ) <EOL> @ defer . inlineCallbacks <EOL> def on_GET ( self , request , user_id ) : <EOL> user = UserID . from_string ( user_id ) <EOL> avatar_url = yield self . handlers . profile_handler . get_avatar_url ( <EOL> user , <EOL> ) <EOL> ret = { } <EOL> if avatar_url is not None : <EOL> ret [ "<STR_LIT>" ] = avatar_url <EOL> defer . returnValue ( ( <NUM_LIT:200> , ret ) ) <EOL> @ defer . inlineCallbacks <EOL> def on_PUT ( self , request , user_id ) : <EOL> requester = yield self . auth . get_user_by_req ( request ) <EOL> user = UserID . from_string ( user_id ) <EOL> content = parse_json_object_from_request ( request ) <EOL> try : <EOL> new_name = content [ "<STR_LIT>" ] <EOL> except : <EOL> defer . returnValue ( ( <NUM_LIT> , "<STR_LIT>" ) ) <EOL> yield self . handlers . profile_handler . set_avatar_url ( <EOL> user , requester , new_name ) <EOL> defer . returnValue ( ( <NUM_LIT:200> , { } ) ) <EOL> def on_OPTIONS ( self , request , user_id ) : <EOL> return ( <NUM_LIT:200> , { } ) <EOL> class ProfileRestServlet ( ClientV1RestServlet ) : <EOL> PATTERNS = client_path_patterns ( "<STR_LIT>" ) <EOL> @ defer . inlineCallbacks <EOL> def on_GET ( self , request , user_id ) : <EOL> user = UserID . from_string ( user_id ) <EOL> displayname = yield self . handlers . profile_handler . get_displayname ( <EOL> user , <EOL> ) <EOL> avatar_url = yield self . handlers . profile_handler . get_avatar_url ( <EOL> user , <EOL> ) <EOL> ret = { } <EOL> if displayname is not None : <EOL> ret [ "<STR_LIT>" ] = displayname <EOL> if avatar_url is not None : <EOL> ret [ "<STR_LIT>" ] = avatar_url <EOL> defer . returnValue ( ( <NUM_LIT:200> , ret ) ) <EOL> def register_servlets ( hs , http_server ) : <EOL> ProfileDisplaynameRestServlet ( hs ) . register ( http_server ) <EOL> ProfileAvatarURLRestServlet ( hs ) . register ( http_server ) <EOL> ProfileRestServlet ( hs ) . register ( http_server ) </s>
