<s> from stormpath . client import Client <EOL> def get_resource ( coll , id_name , id_value ) : <EOL> """<STR_LIT>""" <EOL> if id_value . startswith ( Client . BASE_URL ) : <EOL> return coll . get ( id_value ) <EOL> coll = coll . query ( ** { id_name : id_value } ) <EOL> if len ( coll ) : <EOL> return coll [ <NUM_LIT:0> ] <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def get_resource_data ( resource ) : <EOL> """<STR_LIT>""" <EOL> data = resource . _store . get_resource ( resource . href ) <EOL> try : <EOL> data . pop ( '<STR_LIT>' ) <EOL> except : <EOL> pass <EOL> return data <EOL> def _get_context ( client , args ) : <EOL> """<STR_LIT>""" <EOL> a = args . get ( '<STR_LIT>' ) <EOL> d = args . get ( '<STR_LIT>' ) <EOL> if a and d : <EOL> return get_resource ( client . directories , '<STR_LIT:name>' , d ) <EOL> elif a : <EOL> return get_resource ( client . applications , '<STR_LIT:name>' , a ) <EOL> elif d : <EOL> return get_resource ( client . directories , '<STR_LIT:name>' , d ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def get_accounts ( client , args ) : <EOL> """<STR_LIT>""" <EOL> return _get_context ( client , args ) . accounts <EOL> def get_groups ( client , args ) : <EOL> """<STR_LIT>""" <EOL> return _get_context ( client , args ) . groups <EOL> def get_mappings ( client , args ) : <EOL> """<STR_LIT>""" <EOL> return _get_context ( client , args ) . account_store_mappings <EOL> AVAILABLE_RESOURCES = { <EOL> '<STR_LIT>' : lambda c , args : c . applications , <EOL> '<STR_LIT>' : lambda c , args : c . applications , <EOL> '<STR_LIT>' : lambda c , args : c . directories , <EOL> '<STR_LIT>' : lambda c , args : c . directories , <EOL> '<STR_LIT>' : get_accounts , <EOL> '<STR_LIT>' : get_accounts , <EOL> '<STR_LIT>' : get_groups , <EOL> '<STR_LIT>' : get_groups , <EOL> '<STR_LIT>' : get_mappings , <EOL> '<STR_LIT>' : get_mappings , <EOL> } </s>
