<s> """<STR_LIT>""" <EOL> from __future__ import division , unicode_literals , print_function , absolute_import <EOL> import logging <EOL> import warnings <EOL> from pyvisa import constants , errors , highlevel , logger <EOL> from pyvisa . compat import integer_types , OrderedDict <EOL> from . cthelper import Library , find_library <EOL> from . import functions <EOL> logger = logging . LoggerAdapter ( logger , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def add_visa_methods ( aclass ) : <EOL> for method in functions . visa_functions : <EOL> setattr ( aclass , method , getattr ( functions , method ) ) <EOL> return aclass <EOL> def _args_to_str ( args ) : <EOL> out = [ ] <EOL> for arg in args : <EOL> try : <EOL> out . append ( str ( arg . _obj ) ) <EOL> except AttributeError : <EOL> out . append ( arg ) <EOL> return tuple ( out ) <EOL> @ add_visa_methods <EOL> class NIVisaLibrary ( highlevel . VisaLibraryBase ) : <EOL> """<STR_LIT>""" <EOL> @ staticmethod <EOL> def get_library_paths ( ) : <EOL> """<STR_LIT>""" <EOL> from . . util import LibraryPath , read_user_library_path <EOL> user_lib = read_user_library_path ( ) <EOL> tmp = [ find_library ( library_path ) <EOL> for library_path in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> tmp = [ LibraryPath ( library_path ) <EOL> for library_path in set ( tmp ) <EOL> if library_path is not None ] <EOL> logger . debug ( '<STR_LIT>' % tmp ) <EOL> if user_lib : <EOL> user_lib = LibraryPath ( user_lib , '<STR_LIT:user>' ) <EOL> try : <EOL> tmp . remove ( user_lib ) <EOL> except ValueError : <EOL> pass <EOL> tmp . insert ( <NUM_LIT:0> , user_lib ) <EOL> return tuple ( tmp ) <EOL> @ staticmethod <EOL> def get_debug_info ( ) : <EOL> """<STR_LIT>""" <EOL> from pyvisa import __version__ <EOL> d = OrderedDict ( ) <EOL> d [ '<STR_LIT>' ] = '<STR_LIT>' % __version__ <EOL> paths = NIVisaLibrary . get_library_paths ( ) <EOL> for ndx , visalib in enumerate ( paths , <NUM_LIT:1> ) : <EOL> nfo = OrderedDict ( ) <EOL> nfo [ '<STR_LIT>' ] = visalib . found_by <EOL> nfo [ '<STR_LIT>' ] = visalib . bitness <EOL> try : <EOL> lib = NIVisaLibrary ( visalib ) <EOL> sess , _ = lib . open_default_resource_manager ( ) <EOL> nfo [ '<STR_LIT>' ] = str ( lib . get_attribute ( sess , constants . VI_ATTR_RSRC_MANF_NAME ) [ <NUM_LIT:0> ] ) <EOL> nfo [ '<STR_LIT>' ] = str ( lib . get_attribute ( sess , constants . VI_ATTR_RSRC_IMPL_VERSION ) [ <NUM_LIT:0> ] ) <EOL> nfo [ '<STR_LIT>' ] = str ( lib . get_attribute ( sess , constants . VI_ATTR_RSRC_SPEC_VERSION ) [ <NUM_LIT:0> ] ) <EOL> lib . close ( sess ) <EOL> except Exception as e : <EOL> e = str ( e ) <EOL> if '<STR_LIT>' in e : <EOL> nfo [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> else : <EOL> nfo [ '<STR_LIT>' ] = str ( e ) . split ( '<STR_LIT:\n>' ) <EOL> d [ '<STR_LIT>' % ( ndx , visalib ) ] = nfo <EOL> if not paths : <EOL> d [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return d <EOL> def _init ( self ) : <EOL> try : <EOL> lib = Library ( self . library_path ) <EOL> except OSError as exc : <EOL> raise errors . LibraryError . from_exception ( exc , self . library_path ) <EOL> self . lib = lib <EOL> functions . set_signatures ( self . lib , errcheck = self . _return_handler ) <EOL> logger . debug ( '<STR_LIT>' , <EOL> len ( getattr ( self . lib , '<STR_LIT>' , [ ] ) ) , <EOL> len ( getattr ( self . lib , '<STR_LIT>' , [ ] ) ) ) <EOL> for method_name in getattr ( self . lib , '<STR_LIT>' , [ ] ) : <EOL> setattr ( self , method_name , getattr ( self . lib , method_name ) ) <EOL> def _return_handler ( self , ret_value , func , arguments ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( '<STR_LIT>' , <EOL> func . __name__ , _args_to_str ( arguments ) , ret_value , <EOL> extra = self . _logging_extra ) <EOL> try : <EOL> ret_value = constants . StatusCode ( ret_value ) <EOL> except ValueError : <EOL> pass <EOL> self . _last_status = ret_value <EOL> session = None <EOL> if func . __name__ not in ( '<STR_LIT>' , ) : <EOL> try : <EOL> session = arguments [ <NUM_LIT:0> ] <EOL> except KeyError : <EOL> raise Exception ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( func , len ( arguments ) ) ) <EOL> if func . __name__ in ( '<STR_LIT>' , ) : <EOL> session = session . _obj . value <EOL> if isinstance ( session , integer_types ) : <EOL> self . _last_status_in_session [ session ] = ret_value <EOL> else : <EOL> if func . __name__ not in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise Exception ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( func , type ( session ) ) ) <EOL> if ret_value < <NUM_LIT:0> : <EOL> raise errors . VisaIOError ( ret_value ) <EOL> if ret_value in self . issue_warning_on : <EOL> if session and ret_value not in self . _ignore_warning_in_session [ session ] : <EOL> warnings . warn ( errors . VisaIOWarning ( ret_value ) , stacklevel = <NUM_LIT:2> ) <EOL> return ret_value <EOL> def list_resources ( self , session , query = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> resources = [ ] <EOL> try : <EOL> find_list , return_counter , instrument_description , err = self . find_resources ( session , query ) <EOL> except errors . VisaIOError as e : <EOL> if e . error_code == constants . StatusCode . error_resource_not_found : <EOL> return tuple ( ) <EOL> raise e <EOL> resources . append ( instrument_description ) <EOL> for i in range ( return_counter - <NUM_LIT:1> ) : <EOL> resources . append ( self . find_next ( find_list ) [ <NUM_LIT:0> ] ) <EOL> self . close ( find_list ) <EOL> return tuple ( resource for resource in resources ) </s>
