<s> import json <EOL> from . webwait import command , follow_events , get_field , EOFError <EOL> def invite ( so , stdout , stderr , offer_mailbox = False , accept_mailbox = False ) : <EOL> args = { "<STR_LIT>" : so . get ( "<STR_LIT>" ) , <EOL> "<STR_LIT:code>" : so . get ( "<STR_LIT:code>" ) } <EOL> if offer_mailbox : <EOL> args [ "<STR_LIT>" ] = True <EOL> if accept_mailbox : <EOL> args [ "<STR_LIT>" ] = True <EOL> ok , result = command ( so [ "<STR_LIT>" ] , "<STR_LIT>" , args , stderr ) <EOL> if not ok : <EOL> print >> stderr , result [ "<STR_LIT>" ] <EOL> return <NUM_LIT:1> <EOL> cid = result [ "<STR_LIT>" ] <EOL> if so . get ( "<STR_LIT:code>" ) is not None : <EOL> stdout . write ( "<STR_LIT>" % so [ "<STR_LIT:code>" ] ) <EOL> stdout . flush ( ) <EOL> return <NUM_LIT:0> <EOL> try : <EOL> resp = follow_events ( so [ "<STR_LIT>" ] , "<STR_LIT>" , catchup = True ) <EOL> if resp . status != <NUM_LIT:200> : <EOL> print >> stderr , "<STR_LIT>" , resp . status , resp . reason <EOL> return <NUM_LIT:1> <EOL> while True : <EOL> fieldname , value = get_field ( resp ) <EOL> if fieldname == "<STR_LIT:data>" : <EOL> data = json . loads ( value ) <EOL> if ( data [ "<STR_LIT:type>" ] == "<STR_LIT>" <EOL> and data [ "<STR_LIT>" ] [ "<STR_LIT:id>" ] == cid ) : <EOL> code = data [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> stdout . write ( "<STR_LIT>" % code ) <EOL> stdout . flush ( ) <EOL> return <NUM_LIT:0> <EOL> except ( KeyboardInterrupt , EOFError ) : <EOL> return <NUM_LIT:0> </s>
