<s> """<STR_LIT>""" <EOL> import os <EOL> from framework import framework_info <EOL> from dylib import dylib_info <EOL> from itertools import * <EOL> __all__ = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ] <EOL> DEFAULT_FRAMEWORK_FALLBACK = [ <EOL> os . path . expanduser ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> DEFAULT_LIBRARY_FALLBACK = [ <EOL> os . path . expanduser ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> def ensure_utf8 ( s ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( s , unicode ) : <EOL> return s . encode ( '<STR_LIT:utf8>' ) <EOL> return s <EOL> def dyld_env ( env , var ) : <EOL> if env is None : <EOL> env = os . environ <EOL> rval = env . get ( var ) <EOL> if rval is None : <EOL> return [ ] <EOL> return rval . split ( '<STR_LIT::>' ) <EOL> def dyld_image_suffix ( env = None ) : <EOL> if env is None : <EOL> env = os . environ <EOL> return env . get ( '<STR_LIT>' ) <EOL> def dyld_framework_path ( env = None ) : <EOL> return dyld_env ( env , '<STR_LIT>' ) <EOL> def dyld_library_path ( env = None ) : <EOL> return dyld_env ( env , '<STR_LIT>' ) <EOL> def dyld_fallback_framework_path ( env = None ) : <EOL> return dyld_env ( env , '<STR_LIT>' ) <EOL> def dyld_fallback_library_path ( env = None ) : <EOL> return dyld_env ( env , '<STR_LIT>' ) <EOL> def dyld_image_suffix_search ( iterator , env = None ) : <EOL> """<STR_LIT>""" <EOL> suffix = dyld_image_suffix ( env ) <EOL> if suffix is None : <EOL> return iterator <EOL> def _inject ( iterator = iterator , suffix = suffix ) : <EOL> for path in iterator : <EOL> if path . endswith ( '<STR_LIT>' ) : <EOL> yield path [ : - len ( '<STR_LIT>' ) ] + suffix + '<STR_LIT>' <EOL> else : <EOL> yield path + suffix <EOL> yield path <EOL> return _inject ( ) <EOL> def dyld_override_search ( name , env = None ) : <EOL> framework = framework_info ( name ) <EOL> if framework is not None : <EOL> for path in dyld_framework_path ( env ) : <EOL> yield os . path . join ( path , framework [ '<STR_LIT:name>' ] ) <EOL> for path in dyld_library_path ( env ) : <EOL> yield os . path . join ( path , os . path . basename ( name ) ) <EOL> def dyld_executable_path_search ( name , executable_path = None ) : <EOL> if name . startswith ( '<STR_LIT>' ) and executable_path is not None : <EOL> yield os . path . join ( executable_path , name [ len ( '<STR_LIT>' ) : ] ) <EOL> def dyld_default_search ( name , env = None ) : <EOL> yield name <EOL> framework = framework_info ( name ) <EOL> if framework is not None : <EOL> fallback_framework_path = dyld_fallback_framework_path ( env ) <EOL> for path in fallback_framework_path : <EOL> yield os . path . join ( path , framework [ '<STR_LIT:name>' ] ) <EOL> fallback_library_path = dyld_fallback_library_path ( env ) <EOL> for path in fallback_library_path : <EOL> yield os . path . join ( path , os . path . basename ( name ) ) <EOL> if framework is not None and not fallback_framework_path : <EOL> for path in DEFAULT_FRAMEWORK_FALLBACK : <EOL> yield os . path . join ( path , framework [ '<STR_LIT:name>' ] ) <EOL> if not fallback_library_path : <EOL> for path in DEFAULT_LIBRARY_FALLBACK : <EOL> yield os . path . join ( path , os . path . basename ( name ) ) <EOL> def dyld_find ( name , executable_path = None , env = None ) : <EOL> """<STR_LIT>""" <EOL> name = ensure_utf8 ( name ) <EOL> executable_path = ensure_utf8 ( executable_path ) <EOL> for path in dyld_image_suffix_search ( chain ( <EOL> dyld_override_search ( name , env ) , <EOL> dyld_executable_path_search ( name , executable_path ) , <EOL> dyld_default_search ( name , env ) , <EOL> ) , env ) : <EOL> if os . path . isfile ( path ) : <EOL> return path <EOL> raise ValueError ( "<STR_LIT>" % ( name , ) ) <EOL> def framework_find ( fn , executable_path = None , env = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return dyld_find ( fn , executable_path = executable_path , env = env ) <EOL> except ValueError , e : <EOL> pass <EOL> fmwk_index = fn . rfind ( '<STR_LIT>' ) <EOL> if fmwk_index == - <NUM_LIT:1> : <EOL> fmwk_index = len ( fn ) <EOL> fn += '<STR_LIT>' <EOL> fn = os . path . join ( fn , os . path . basename ( fn [ : fmwk_index ] ) ) <EOL> try : <EOL> return dyld_find ( fn , executable_path = executable_path , env = env ) <EOL> except ValueError : <EOL> raise e <EOL> def test_dyld_find ( ) : <EOL> env = { } <EOL> assert dyld_find ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> assert dyld_find ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> test_dyld_find ( ) </s>
