#NEWLINE# def __init__( self , host = None , port = None , **kwargs ) : #NEWLINE# #INDENT# 'Initialize a connection to the network socket.\n\n        Kwargs:\n            host - optionally override the default network host (default is local machine)\n            port - optionally override the default network port (default is 50001)\n            log_mode - optionally record or print logs from the network source\n\n        Raises:\n            DataSourceError if the socket connection cannot be opened.\n        ' #NEWLINE# super ( NetworkDataSource , self ) . __init__ ( ** kwargs ) #NEWLINE# self . host = ( host or socket . gethostbyname ( socket . gethostname ( ) ) ) #NEWLINE# self . port = ( port or self . DEFAULT_PORT ) #NEWLINE# self . port = int ( self . port ) #NEWLINE# try : #NEWLINE# #INDENT# self . socket = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) #NEWLINE# self . socket . connect ( ( self . host , self . port ) ) #NEWLINE# #UNINDENT# except ( OSError , socket . error ) as e : #NEWLINE# #INDENT# raise DataSourceError ( ( 'Unable to open socket connection at  %s:%s: %s' % ( self . host , self . port , e ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# LOG . debug ( 'Opened socket connection at %s:%s' , self . host , self . port )