#NEWLINE# def LookupPublicKey( self , signer_uri = None ) : #NEWLINE# #INDENT# self . signer_uri = signer_uri #NEWLINE# user_remote = self . handler . models . users_remote . get ( local_username = self . local_user . username , profile_url = signer_uri ) [ 0 ] #NEWLINE# if ( not webfinger_doc ) : #NEWLINE# #INDENT# lrdd_link = users . get_lrdd_link ( signer_uri ) #NEWLINE# if ( not lrdd_link ) : #NEWLINE# #INDENT# raise tornado . web . HTTPError ( 400 ) #NEWLINE# #UNINDENT# webfinger_doc = users . get_webfinger ( lrdd_link , signer_uri ) #NEWLINE# magic_key = webfinger_doc . find ( 'link' , rel = 'magic-public-key' ) [ 'href' ] . replace ( 'data:application/magic-public-key,' , '' ) #NEWLINE# if ( not magic_key ) : #NEWLINE# #INDENT# raise tornado . web . HTTPError ( 400 ) #NEWLINE# #UNINDENT# new_user = self . handler . models . users_remote ( ) #NEWLINE# new_user . local_username = self . local_user . username #NEWLINE# new_user . profile_url = signer_uri #NEWLINE# new_user . magic_key = magic_key #NEWLINE# new_user . save ( ) #NEWLINE# return str ( magic_key ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return str ( user_remote . magic_key )