<s> """<STR_LIT>""" <EOL> import os <EOL> PATH_ENV_VAR = '<STR_LIT>' <EOL> PATH_EXTENSIONS_ENV_VAR = '<STR_LIT>' <EOL> def which ( name , flags = os . X_OK ) : <EOL> """<STR_LIT>""" <EOL> result = [ ] <EOL> path_extension = os . getenv ( PATH_EXTENSIONS_ENV_VAR , '<STR_LIT>' ) <EOL> valid_extensions = [ extension <EOL> for extension in path_extension . split ( os . pathsep ) <EOL> if extension ] <EOL> path = os . getenv ( PATH_ENV_VAR ) <EOL> if path is None : <EOL> return <EOL> for directory_on_path in path . split ( os . pathsep ) : <EOL> potential_match = os . path . join ( directory_on_path , name ) <EOL> if os . access ( potential_match , flags ) : <EOL> return potential_match <EOL> for extension in valid_extensions : <EOL> potential_match_with_ext = potential_match + extension <EOL> if os . access ( potential_match_with_ext , flags ) : <EOL> return potential_match_with_ext <EOL> return result </s>
