#NEWLINE# def _card_connect( self , options , terminate ) : #NEWLINE# #INDENT# timeout = options . get ( 'timeout' , 1.0 ) #NEWLINE# for target in options . get ( 'targets' ) : #NEWLINE# #INDENT# activated = self . listen ( target , timeout ) #NEWLINE# if activated : #NEWLINE# #INDENT# ( target , command ) = activated #NEWLINE# log . debug ( 'activated as target {0}' . format ( target ) ) #NEWLINE# tag = nfc . tag . emulate ( self , target ) #NEWLINE# if ( tag is not None ) : #NEWLINE# #INDENT# log . debug ( 'connected as {0}' . format ( tag ) ) #NEWLINE# callback = options [ 'on-connect' ] #NEWLINE# if ( callback and callback ( tag , command ) ) : #NEWLINE# #INDENT# while ( not terminate ( ) ) : #NEWLINE# #INDENT# response = ( tag . process_command ( command ) if ( command is not None ) else None ) #NEWLINE# try : #NEWLINE# #INDENT# command = tag . send_response ( response , timeout = 1 ) #NEWLINE# #UNINDENT# except nfc . clf . TimeoutError : #NEWLINE# #INDENT# command = None #NEWLINE# #UNINDENT# except nfc . clf . DigitalProtocolError as error : #NEWLINE# #INDENT# log . error ( error ) #NEWLINE# break #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( command is None ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# callback = options . get ( 'on-release' , ( lambda tag : True ) ) #NEWLINE# return callback ( tag = tag ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return tag