<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> from ctypes import CDLL <EOL> from ctypes . util import find_library as _find_library <EOL> default_locations = dict ( <EOL> darwin = dict ( <EOL> paths = [ '<STR_LIT>' ] , <EOL> exts = [ '<STR_LIT>' ] , <EOL> ) , <EOL> win32 = dict ( <EOL> paths = [ os . path . dirname ( os . __file__ ) + '<STR_LIT>' ] , <EOL> exts = [ '<STR_LIT>' ] <EOL> ) , <EOL> other = dict ( <EOL> paths = [ ] , <EOL> exts = [ '<STR_LIT>' ] <EOL> ) , <EOL> ) <EOL> additional_lib_path = os . environ . get ( '<STR_LIT>' ) <EOL> if additional_lib_path : <EOL> additional_lib_path = additional_lib_path . split ( os . pathsep ) <EOL> additional_lib_path . reverse ( ) <EOL> for locs in default_locations . values ( ) : <EOL> for path in additional_lib_path : <EOL> locs [ '<STR_LIT>' ] . insert ( <NUM_LIT:0> , path ) <EOL> def load_library ( lib_names , locations_conf = default_locations ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( lib_names , basestring ) : <EOL> lib_names = [ lib_names ] <EOL> for lib_name in lib_names : <EOL> lib = load_library_ ( lib_name , locations_conf ) <EOL> if lib is not None : return lib <EOL> def load_library_ ( lib_name , locations_conf = default_locations ) : <EOL> lib_path = find_library ( lib_name ) <EOL> if lib_path : <EOL> return CDLL ( lib_path ) <EOL> if sys . platform in locations_conf : <EOL> paths = locations_conf [ sys . platform ] [ '<STR_LIT>' ] <EOL> exts = locations_conf [ sys . platform ] [ '<STR_LIT>' ] <EOL> lib_path = find_library ( lib_name , paths , exts ) <EOL> else : <EOL> paths = locations_conf [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> exts = locations_conf [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> lib_path = find_library ( lib_name , paths , exts ) <EOL> if lib_path : <EOL> return CDLL ( lib_path ) <EOL> def find_library ( lib_name , paths = None , exts = None ) : <EOL> """<STR_LIT>""" <EOL> if not paths or not exts : <EOL> lib = _find_library ( lib_name ) <EOL> if lib is None and lib_name . startswith ( '<STR_LIT>' ) : <EOL> lib = _find_library ( lib_name [ <NUM_LIT:3> : ] ) <EOL> return lib <EOL> for lib_name in [ lib_name ] + ( [ lib_name [ <NUM_LIT:3> : ] ] if lib_name . startswith ( '<STR_LIT>' ) else [ ] ) : <EOL> for path in paths : <EOL> for ext in exts : <EOL> lib_path = os . path . join ( path , lib_name + ext ) <EOL> if os . path . exists ( lib_path ) : <EOL> return lib_path <EOL> return None <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> print load_library ( sys . argv [ <NUM_LIT:1> ] ) </s>
