<s> import json <EOL> from twisted . internet import defer <EOL> from twisted . web import client , error <EOL> from twisted . python import failure <EOL> client . HTTPClientFactory . noisy = False <EOL> class AuthException ( Exception ) : <EOL> pass <EOL> def join ( timeout , digest , access_token , uuid ) : <EOL> d0 = defer . Deferred ( ) <EOL> def _auth_ok ( data ) : <EOL> d0 . callback ( json . loads ( data . decode ( '<STR_LIT:ascii>' ) ) ) <EOL> def _auth_err ( err ) : <EOL> if isinstance ( err . value , error . Error ) and err . value . status == b"<STR_LIT>" : <EOL> d0 . callback ( None ) <EOL> else : <EOL> d0 . errback ( err ) <EOL> data = { <EOL> "<STR_LIT>" : access_token , <EOL> "<STR_LIT>" : uuid . to_hex ( with_dashes = False ) , <EOL> "<STR_LIT>" : digest <EOL> } <EOL> d1 = client . getPage ( <EOL> b"<STR_LIT>" , <EOL> headers = { b'<STR_LIT:Content-Type>' : b'<STR_LIT:application/json>' } , <EOL> method = b'<STR_LIT:POST>' , <EOL> postdata = json . dumps ( data ) . encode ( '<STR_LIT:ascii>' ) , <EOL> timeout = timeout ) <EOL> d1 . addCallbacks ( _auth_ok , _auth_err ) <EOL> return d0 <EOL> def has_joined ( timeout , digest , username ) : <EOL> d0 = defer . Deferred ( ) <EOL> def _auth_ok ( data ) : <EOL> d0 . callback ( json . loads ( data . decode ( '<STR_LIT:ascii>' ) ) ) <EOL> def _auth_err ( err ) : <EOL> if isinstance ( err . value , error . Error ) and err . value . status == b"<STR_LIT>" : <EOL> err = failure . Failure ( AuthException ( "<STR_LIT>" ) ) <EOL> d0 . errback ( err ) <EOL> d1 = client . getPage ( <EOL> b"<STR_LIT>" <EOL> b"<STR_LIT>" + username . encode ( '<STR_LIT:ascii>' ) + b"<STR_LIT>" + digest . encode ( '<STR_LIT:ascii>' ) , <EOL> timeout = timeout ) <EOL> d1 . addCallbacks ( _auth_ok , _auth_err ) <EOL> return d0 </s>
