#NEWLINE# def __init__( self , tag = None , api_username = None , api_password = None , api_key = None , hostname = None , port = None , serial = None , use_http = False , use_get = False , timeout = None , ssl_context = None ) : #NEWLINE# #INDENT# self . _log = logging . getLogger ( __name__ ) . log #NEWLINE# self . tag = tag #NEWLINE# self . api_username = None #NEWLINE# self . api_password = None #NEWLINE# self . api_key = None #NEWLINE# self . hostname = None #NEWLINE# self . port = port #NEWLINE# self . serial = serial #NEWLINE# self . use_get = use_get #NEWLINE# self . timeout = timeout #NEWLINE# self . ssl_context = ssl_context #NEWLINE# self . _log ( DEBUG3 , 'Python version: %s' , sys . version ) #NEWLINE# self . _log ( DEBUG3 , 'xml.etree.ElementTree version: %s' , etree . VERSION ) #NEWLINE# self . _log ( DEBUG3 , 'pan-python version: %s' , __version__ ) #NEWLINE# if ( self . port is not None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . port = int ( self . port ) #NEWLINE# if ( ( self . port < 1 ) or ( self . port > 65535 ) ) : #NEWLINE# #INDENT# raise ValueError #NEWLINE# #UNINDENT# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise PanXapiError ( ( 'Invalid port: %s' % self . port ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( self . timeout is not None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . timeout = int ( self . timeout ) #NEWLINE# if ( not ( self . timeout > 0 ) ) : #NEWLINE# #INDENT# raise ValueError #NEWLINE# #UNINDENT# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise PanXapiError ( ( 'Invalid timeout: %s' % self . timeout ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( self . ssl_context is not None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ssl . SSLContext ( ssl . PROTOCOL_SSLv23 ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# raise PanXapiError ( 'SSL module has no SSLContext()' ) #NEWLINE# #UNINDENT# #UNINDENT# init_panrc = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if ( api_username is not None ) : #NEWLINE# #INDENT# init_panrc [ 'api_username' ] = api_username #NEWLINE# #UNINDENT# if ( api_password is not None ) : #NEWLINE# #INDENT# init_panrc [ 'api_password' ] = api_password #NEWLINE# #UNINDENT# if ( api_key is not None ) : #NEWLINE# #INDENT# init_panrc [ 'api_key' ] = api_key #NEWLINE# #UNINDENT# if ( hostname is not None ) : #NEWLINE# #INDENT# init_panrc [ 'hostname' ] = hostname #NEWLINE# #UNINDENT# if ( port is not None ) : #NEWLINE# #INDENT# init_panrc [ 'port' ] = port #NEWLINE# #UNINDENT# if ( serial is not None ) : #NEWLINE# #INDENT# init_panrc [ 'serial' ] = serial #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# panrc = pan . rc . PanRc ( tag = self . tag , init_panrc = init_panrc ) #NEWLINE# #UNINDENT# except pan . rc . PanRcError as msg : #NEWLINE# #INDENT# raise PanXapiError ( str ( msg ) ) #NEWLINE# #UNINDENT# if ( ( 'api_key' in panrc . panrc ) and ( api_username is not None ) and ( api_password is not None ) and ( api_key is None ) ) : #NEWLINE# #INDENT# del panrc . panrc [ 'api_key' ] #NEWLINE# self . _log ( DEBUG1 , 'ignoring .panrc inherited api_key' ) #NEWLINE# #UNINDENT# if ( 'api_username' in panrc . panrc ) : #NEWLINE# #INDENT# self . api_username = panrc . panrc [ 'api_username' ] #NEWLINE# #UNINDENT# if ( 'api_password' in panrc . panrc ) : #NEWLINE# #INDENT# self . api_password = panrc . panrc [ 'api_password' ] #NEWLINE# #UNINDENT# if ( 'api_key' in panrc . panrc ) : #NEWLINE# #INDENT# self . api_key = panrc . panrc [ 'api_key' ] #NEWLINE# #UNINDENT# if ( 'hostname' in panrc . panrc ) : #NEWLINE# #INDENT# self . hostname = panrc . panrc [ 'hostname' ] #NEWLINE# #UNINDENT# if ( 'port' in panrc . panrc ) : #NEWLINE# #INDENT# self . port = panrc . panrc [ 'port' ] #NEWLINE# try : #NEWLINE# #INDENT# self . port = int ( self . port ) #NEWLINE# if ( ( self . port < 1 ) or ( tag . port > 65535 ) ) : #NEWLINE# #INDENT# raise ValueError #NEWLINE# #UNINDENT# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise PanXapiError ( ( 'Invalid port from .panrc: %s' % self . port ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( 'serial' in panrc . panrc ) : #NEWLINE# #INDENT# self . serial = panrc . panrc [ 'serial' ] #NEWLINE# #UNINDENT# if ( self . hostname is None ) : #NEWLINE# #INDENT# raise PanXapiError ( 'hostname argument required' ) #NEWLINE# #UNINDENT# if ( ( self . api_key is None ) and ( ( self . api_username is None ) or ( self . api_password is None ) ) ) : #NEWLINE# #INDENT# raise PanXapiError ( ( 'api_key or api_username and ' + 'api_password arguments required' ) ) #NEWLINE# #UNINDENT# if use_http : #NEWLINE# #INDENT# scheme = 'http' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# scheme = 'https' #NEWLINE# #UNINDENT# self . uri = ( '%s://%s' % ( scheme , self . hostname ) ) #NEWLINE# if ( self . port is not None ) : #NEWLINE# #INDENT# self . uri += ( ':%s' % self . port ) #NEWLINE# #UNINDENT# self . uri += '/api/' #NEWLINE# if _legacy_urllib : #NEWLINE# #INDENT# self . _log ( DEBUG2 , 'using legacy urllib' )