<s> import json <EOL> import uuid <EOL> from . base import GafferNotFound <EOL> class Keys ( object ) : <EOL> def __init__ ( self , server ) : <EOL> self . server = server <EOL> def all_keys ( self , include_keys = False ) : <EOL> path = "<STR_LIT>" <EOL> if include_keys : <EOL> path += "<STR_LIT>" <EOL> resp = self . server . request ( "<STR_LIT>" , path ) <EOL> return self . server . json_body ( resp ) [ "<STR_LIT>" ] <EOL> def create_key ( self , permissions , key = None , label = "<STR_LIT>" , parent = None ) : <EOL> key = key or uuid . uuid4 ( ) . hex <EOL> data = { "<STR_LIT>" : permissions } <EOL> if label and label is not None : <EOL> data [ '<STR_LIT:label>' ] = label <EOL> resp = self . set_key ( key , data , parent = parent ) <EOL> return self . server . json_body ( resp ) [ '<STR_LIT>' ] <EOL> def set_key ( self , key , data , parent = None ) : <EOL> obj = data . copy ( ) <EOL> obj [ "<STR_LIT:key>" ] = key <EOL> obj [ "<STR_LIT>" ] = parent <EOL> headers = { "<STR_LIT:Content-Type>" : "<STR_LIT:application/json>" } <EOL> body = json . dumps ( obj ) <EOL> return self . server . request ( "<STR_LIT>" , "<STR_LIT>" , headers = headers , body = body ) <EOL> def get_key ( self , key , include_keys = False ) : <EOL> path = "<STR_LIT>" % key <EOL> if include_keys : <EOL> path += "<STR_LIT>" <EOL> resp = self . server . request ( "<STR_LIT>" , path ) <EOL> return self . server . json_body ( resp ) <EOL> def delete_key ( self , key ) : <EOL> self . server . request ( "<STR_LIT>" , "<STR_LIT>" % key ) <EOL> def has_key ( self , key ) : <EOL> try : <EOL> self . server . request ( "<STR_LIT>" , "<STR_LIT>" % key ) <EOL> except GafferNotFound : <EOL> return False <EOL> return True </s>
