<s> from piston . handler import BaseHandler , rc <EOL> from systems . models import System , SystemRack , SystemStatus , NetworkAdapter , KeyValue <EOL> from truth . models import Truth , KeyValue as TruthKeyValue <EOL> from dhcp . DHCP import DHCP as DHCPInterface <EOL> from dhcp . models import DHCP <EOL> from MacroExpansion import MacroExpansion <EOL> from KeyValueTree import KeyValueTree <EOL> import re <EOL> try : <EOL> import json <EOL> except : <EOL> from django . utils import simplejson as json <EOL> from django . test . client import Client <EOL> from MozInvAuthorization . KeyValueACL import KeyValueACL <EOL> from settings import API_ACCESS <EOL> class KeyValueHandler ( BaseHandler ) : <EOL> allowed_methods = API_ACCESS <EOL> def create ( self , request , key_value_id = None ) : <EOL> if '<STR_LIT>' in request . POST : <EOL> post_key = request . POST . get ( '<STR_LIT:key>' ) <EOL> post_value = request . POST . get ( '<STR_LIT:value>' ) <EOL> system_id = request . POST . get ( '<STR_LIT>' ) <EOL> n = KeyValue ( ) <EOL> system = System . objects . get ( id = system_id ) <EOL> if re . search ( '<STR_LIT>' , str ( post_key ) . strip ( ) ) : <EOL> try : <EOL> acl = KeyValueACL ( request ) <EOL> acl . check_ip_not_exist_other_system ( system , post_value ) <EOL> except Exception , e : <EOL> resp = rc . FORBIDDEN <EOL> resp . write ( e ) <EOL> return resp <EOL> try : <EOL> n . obj = system <EOL> if '<STR_LIT:key>' in request . POST : <EOL> n . key = request . POST [ '<STR_LIT:key>' ] <EOL> if '<STR_LIT:value>' in request . POST : <EOL> n . value = request . POST [ '<STR_LIT:value>' ] <EOL> n . save ( ) <EOL> resp = rc . ALL_OK <EOL> resp . write ( '<STR_LIT>' % ( n . id ) ) <EOL> except : <EOL> resp = rc . NOT_FOUND <EOL> resp . write ( '<STR_LIT>' ) <EOL> return resp <EOL> elif '<STR_LIT>' in request . POST : <EOL> n = TruthKeyValue ( ) <EOL> truth = Truth . objects . get ( name = request . POST [ '<STR_LIT>' ] ) <EOL> n . truth = truth <EOL> if '<STR_LIT:key>' in request . POST : <EOL> n . key = request . POST [ '<STR_LIT:key>' ] <EOL> if '<STR_LIT:value>' in request . POST : <EOL> n . value = request . POST [ '<STR_LIT:value>' ] <EOL> try : <EOL> n . save ( ) <EOL> resp = rc . ALL_OK <EOL> resp . write ( '<STR_LIT>' % ( n . id ) ) <EOL> except : <EOL> resp = rc . NOT_FOUND <EOL> resp . write ( '<STR_LIT>' ) <EOL> return resp <EOL> else : <EOL> resp = rc . NOT_FOUND <EOL> resp . write ( '<STR_LIT>' ) <EOL> def build_validation_array ( self ) : <EOL> input_regex_array = [ ] <EOL> output_regex_array = [ ] <EOL> error_message_array = [ ] <EOL> ipv4_regex = re . compile ( r'<STR_LIT>' ) <EOL> true_false_regex = re . compile ( '<STR_LIT>' ) <EOL> input_regex_array . append ( re . compile ( '<STR_LIT>' ) ) <EOL> output_regex_array . append ( ipv4_regex ) <EOL> error_message_array . append ( '<STR_LIT>' ) <EOL> input_regex_array . append ( re . compile ( '<STR_LIT>' ) ) <EOL> output_regex_array . append ( ipv4_regex ) <EOL> error_message_array . append ( '<STR_LIT>' ) <EOL> input_regex_array . append ( re . compile ( '<STR_LIT>' ) ) <EOL> output_regex_array . append ( re . compile ( true_false_regex ) ) <EOL> error_message_array . append ( '<STR_LIT>' ) <EOL> input_regex_array . append ( re . compile ( '<STR_LIT>' ) ) <EOL> output_regex_array . append ( re . compile ( ipv4_regex ) ) <EOL> error_message_array . append ( '<STR_LIT>' ) <EOL> input_regex_array . append ( re . compile ( '<STR_LIT>' ) ) <EOL> output_regex_array . append ( re . compile ( ipv4_regex ) ) <EOL> error_message_array . append ( '<STR_LIT>' ) <EOL> input_regex_array . append ( re . compile ( '<STR_LIT>' ) ) <EOL> output_regex_array . append ( re . compile ( ipv4_regex ) ) <EOL> error_message_array . append ( '<STR_LIT>' ) <EOL> input_regex_array . append ( re . compile ( '<STR_LIT>' ) ) <EOL> output_regex_array . append ( re . compile ( ipv4_regex ) ) <EOL> error_message_array . append ( '<STR_LIT>' ) <EOL> input_regex_array . append ( re . compile ( '<STR_LIT>' ) ) <EOL> output_regex_array . append ( re . compile ( ipv4_regex ) ) <EOL> error_message_array . append ( '<STR_LIT>' ) <EOL> input_regex_array . append ( re . compile ( '<STR_LIT>' ) ) <EOL> output_regex_array . append ( re . compile ( ipv4_regex ) ) <EOL> error_message_array . append ( '<STR_LIT>' ) <EOL> input_regex_array . append ( re . compile ( '<STR_LIT>' ) ) <EOL> output_regex_array . append ( re . compile ( ipv4_regex ) ) <EOL> error_message_array . append ( '<STR_LIT>' ) <EOL> input_regex_array . append ( re . compile ( '<STR_LIT>' ) ) <EOL> output_regex_array . append ( re . compile ( ipv4_regex ) ) <EOL> error_message_array . append ( '<STR_LIT>' ) <EOL> input_regex_array . append ( re . compile ( '<STR_LIT>' ) ) <EOL> output_regex_array . append ( re . compile ( true_false_regex ) ) <EOL> error_message_array . append ( '<STR_LIT>' ) <EOL> input_regex_array . append ( re . compile ( '<STR_LIT>' ) ) <EOL> output_regex_array . append ( re . compile ( true_false_regex ) ) <EOL> error_message_array . append ( '<STR_LIT>' ) <EOL> input_regex_array . append ( re . compile ( '<STR_LIT>' ) ) <EOL> output_regex_array . append ( re . compile ( '<STR_LIT>' , re . I ) ) <EOL> error_message_array . append ( '<STR_LIT>' ) <EOL> return input_regex_array , output_regex_array , error_message_array <EOL> def validate ( self , key , passed_value ) : <EOL> error_message = None <EOL> return_regex = None <EOL> return_bool = True <EOL> input_regex_array , output_regex_array , error_message_array = self . build_validation_array ( ) <EOL> for i in range ( <NUM_LIT:0> , len ( input_regex_array ) ) : <EOL> if input_regex_array [ i ] . match ( key ) : <EOL> return_regex = output_regex_array [ i ] <EOL> error_message = error_message_array [ i ] ; <EOL> continue <EOL> if return_regex is not None : <EOL> if return_regex . match ( passed_value ) is None : <EOL> return_bool = False <EOL> else : <EOL> error_message = None <EOL> return return_bool , error_message <EOL> def update ( self , request , key_value_id = None ) : <EOL> if '<STR_LIT>' in request . POST : <EOL> n = None <EOL> found = False <EOL> post_key = request . POST . get ( '<STR_LIT:key>' ) <EOL> post_value = request . POST . get ( '<STR_LIT:value>' ) <EOL> system_id = request . POST . get ( '<STR_LIT>' ) <EOL> key_validated , validation_error_string = self . validate ( post_key , post_value ) <EOL> if re . search ( '<STR_LIT>' , str ( post_key ) . strip ( ) ) : <EOL> try : <EOL> acl = KeyValueACL ( request ) <EOL> system = System . objects . get ( id = system_id ) <EOL> acl . check_ip_not_exist_other_system ( system , post_value ) <EOL> except Exception , e : <EOL> resp = rc . FORBIDDEN <EOL> resp . write ( e ) <EOL> return resp <EOL> if key_validated is False : <EOL> resp = rc . FORBIDDEN <EOL> resp . write ( '<STR_LIT>' % ( request . POST [ '<STR_LIT:key>' ] , validation_error_string ) ) <EOL> return resp <EOL> try : <EOL> n = KeyValue . objects . get ( id = key_value_id , key = request . POST [ '<STR_LIT:key>' ] ) <EOL> system = System . objects . get ( id = request . POST [ '<STR_LIT>' ] ) <EOL> found = True <EOL> except Exception , e : <EOL> found = False <EOL> if found is False : <EOL> try : <EOL> system = System . objects . get ( id = request . POST [ '<STR_LIT>' ] ) <EOL> n = KeyValue . objects . get ( obj = system , key = request . POST [ '<STR_LIT:key>' ] ) <EOL> found = True <EOL> except : <EOL> found = False <EOL> if found is False : <EOL> resp = rc . NOT_FOUND <EOL> resp . write ( '<STR_LIT>' ) <EOL> return resp <EOL> if n is not None : <EOL> n . obj = system <EOL> if '<STR_LIT:value>' in request . POST and n is not None : <EOL> n . value = request . POST [ '<STR_LIT:value>' ] <EOL> if n is not None : <EOL> try : <EOL> n . save ( ) <EOL> resp = rc . ALL_OK <EOL> resp . write ( '<STR_LIT>' % ( n . id ) ) <EOL> except : <EOL> resp = rc . NOT_FOUND <EOL> resp . write ( '<STR_LIT>' ) <EOL> return resp <EOL> elif '<STR_LIT>' in request . POST or '<STR_LIT>' in request . PUT : <EOL> try : <EOL> truth = Truth . objects . get ( name = key_value_id ) <EOL> n = TruthKeyValue . objects . get ( truth = truth , key = request . POST [ '<STR_LIT:key>' ] ) <EOL> if '<STR_LIT:value>' in request . POST : <EOL> n . value = request . POST [ '<STR_LIT:value>' ] <EOL> except : <EOL> pass <EOL> try : <EOL> n . save ( ) <EOL> resp = rc . ALL_OK <EOL> resp . write ( '<STR_LIT>' % ( n . id ) ) <EOL> except Exception , e : <EOL> resp = rc . NOT_FOUND <EOL> resp . write ( '<STR_LIT>' % e ) <EOL> return resp <EOL> else : <EOL> resp = rc . NOT_FOUND <EOL> resp . write ( '<STR_LIT>' ) <EOL> return resp <EOL> def read ( self , request , key_value_id = None ) : <EOL> if '<STR_LIT>' in request . GET : <EOL> if '<STR_LIT:key>' in request . GET : <EOL> base = KeyValue . objects . filter ( key = request . GET [ '<STR_LIT>' ] ) . filter ( keyvalue_set__contains = request . GET [ '<STR_LIT:key>' ] ) <EOL> tmp_list = [ ] <EOL> for row in base : <EOL> matches = re . match ( "<STR_LIT>" , row . value ) <EOL> if matches is not None : <EOL> m = MacroExpansion ( matches . group ( <NUM_LIT:1> ) ) <EOL> row . value = m . output ( ) <EOL> for r in base : <EOL> key_name = '<STR_LIT>' % ( r . obj . hostname , r . key ) <EOL> tmp_list [ key_name ] = r . value <EOL> if '<STR_LIT:key>' not in request . GET : <EOL> tree = KeyValueTree ( request . GET [ '<STR_LIT>' ] ) . final <EOL> return tree <EOL> elif '<STR_LIT>' in request . GET : <EOL> key_type = request . GET [ '<STR_LIT>' ] <EOL> tmp_list = [ ] <EOL> if key_type == '<STR_LIT>' : <EOL> base = TruthKeyValue . objects . filter ( key = '<STR_LIT>' , value = '<STR_LIT:True>' ) <EOL> for row in base : <EOL> keyvalue = TruthKeyValue . objects . filter ( truth = row . truth ) <EOL> tmp_dict = { } <EOL> for kv in keyvalue : <EOL> tmp_dict [ kv . key ] = kv . value <EOL> tmp_list . append ( tmp_dict ) <EOL> return tmp_list <EOL> if key_type == '<STR_LIT>' : <EOL> keyvalue_pairs = KeyValue . objects . filter ( key__contains = '<STR_LIT>' , value = request . GET [ '<STR_LIT>' ] ) . filter ( key__startswith = '<STR_LIT>' ) <EOL> tmp_list = [ ] <EOL> for row in keyvalue_pairs : <EOL> keyvalue = KeyValue . objects . filter ( obj = row . obj ) <EOL> tmp_dict = { } <EOL> for kv in keyvalue : <EOL> tmp_dict [ kv . key ] = kv . value <EOL> tmp_dict [ '<STR_LIT>' ] = row . obj . hostname <EOL> appendable = True <EOL> for the_items in tmp_list : <EOL> if '<STR_LIT>' not in the_items : <EOL> appendable = True <EOL> elif the_items [ '<STR_LIT>' ] == row . obj . hostname : <EOL> appendable = False <EOL> if appendable is True : <EOL> tmp_list . append ( tmp_dict ) <EOL> return tmp_list <EOL> if key_type == '<STR_LIT>' : <EOL> keyvalue_pairs = KeyValue . objects . filter ( key__contains = '<STR_LIT>' , value = request . GET [ '<STR_LIT>' ] ) . filter ( key__startswith = '<STR_LIT>' ) <EOL> tmp_list = [ ] <EOL> for row in keyvalue_pairs : <EOL> keyvalue = KeyValue . objects . filter ( obj = row . obj ) <EOL> tmp_dict = { } <EOL> for kv in keyvalue : <EOL> tmp_dict [ kv . key ] = kv . value <EOL> tmp_dict [ '<STR_LIT>' ] = row . obj . hostname <EOL> appendable = True <EOL> for the_items in tmp_list : <EOL> if '<STR_LIT>' not in the_items : <EOL> appendable = True <EOL> elif the_items [ '<STR_LIT>' ] == row . obj . hostname : <EOL> appendable = False <EOL> if appendable is True : <EOL> tmp_list . append ( tmp_dict ) <EOL> return tmp_list <EOL> if key_type == '<STR_LIT>' : <EOL> system = None <EOL> try : <EOL> system = System . objects . get ( hostname = request . GET [ '<STR_LIT>' ] ) <EOL> except : <EOL> system = None <EOL> if not system : <EOL> try : <EOL> system = System . objects . get ( id = request . GET [ '<STR_LIT>' ] ) <EOL> except : <EOL> system = None <EOL> if not system : <EOL> resp = rc . NOT_FOUND <EOL> resp . write ( '<STR_LIT>' ) <EOL> return resp <EOL> keyvalue_pairs = KeyValue . objects . filter ( key__startswith = '<STR_LIT>' ) . filter ( obj = system ) . order_by ( '<STR_LIT:key>' ) <EOL> tmp_dict = { } <EOL> adapter_ids = [ ] <EOL> final_list = [ ] <EOL> for kv in keyvalue_pairs : <EOL> tmp_dict [ kv . key ] = kv . value <EOL> for k in tmp_dict . iterkeys ( ) : <EOL> matches = re . match ( '<STR_LIT>' , k ) <EOL> if matches . group is not None : <EOL> if matches . group ( <NUM_LIT:1> ) not in adapter_ids : <EOL> adapter_ids . append ( matches . group ( <NUM_LIT:1> ) ) <EOL> adapter_ids . sort ( ) <EOL> for a in adapter_ids : <EOL> adapter_name = '<STR_LIT>' <EOL> mac_address = '<STR_LIT>' <EOL> dhcp_hostname = '<STR_LIT>' <EOL> dhcp_scope = '<STR_LIT>' <EOL> dhcp_filename = '<STR_LIT>' <EOL> ipv4_address = '<STR_LIT>' <EOL> dhcp_domain_name_servers = '<STR_LIT>' <EOL> option_hostname = "<STR_LIT>" <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> ipv4_address = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> adapter_name = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> mac_address = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> option_hostname = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> dhcp_scope = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> dhcp_filename = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> dhcp_domain_name_servers = tmp_dict [ '<STR_LIT>' % a ] <EOL> try : <EOL> final_list . append ( { <EOL> '<STR_LIT>' : system . hostname , <EOL> '<STR_LIT>' : ipv4_address , <EOL> '<STR_LIT>' : adapter_name , <EOL> '<STR_LIT>' : mac_address , <EOL> '<STR_LIT>' : option_hostname , <EOL> '<STR_LIT>' : dhcp_scope , <EOL> '<STR_LIT>' : dhcp_filename , <EOL> '<STR_LIT>' : dhcp_domain_name_servers , <EOL> } <EOL> ) <EOL> except Exception , e : <EOL> pass <EOL> return final_list <EOL> if key_type == '<STR_LIT>' : <EOL> zone = request . GET [ '<STR_LIT>' ] <EOL> system = System . objects . get ( hostname = request . GET [ '<STR_LIT>' ] ) <EOL> keyvalue_pairs = KeyValue . objects . filter ( key__startswith = '<STR_LIT>' ) . filter ( obj = system ) . order_by ( '<STR_LIT:key>' ) <EOL> tmp_dict = { } <EOL> adapter_ids = [ ] <EOL> final_list = [ ] <EOL> for kv in keyvalue_pairs : <EOL> tmp_dict [ kv . key ] = kv . value <EOL> for k in tmp_dict . iterkeys ( ) : <EOL> matches = re . match ( '<STR_LIT>' , k ) <EOL> if matches . group is not None : <EOL> dhcp_scope_match = '<STR_LIT>' % matches . group ( <NUM_LIT:1> ) <EOL> if matches . group ( <NUM_LIT:1> ) not in adapter_ids and dhcp_scope_match in tmp_dict and tmp_dict [ dhcp_scope_match ] == zone : <EOL> adapter_ids . append ( matches . group ( <NUM_LIT:1> ) ) <EOL> adapter_ids . sort ( ) <EOL> for a in adapter_ids : <EOL> adapter_name = '<STR_LIT>' <EOL> mac_address = '<STR_LIT>' <EOL> dhcp_hostname = '<STR_LIT>' <EOL> dhcp_filename = '<STR_LIT>' <EOL> dhcp_domain_name = '<STR_LIT>' <EOL> ipv4_address = '<STR_LIT>' <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> ipv4_address = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> adapter_name = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> mac_address = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> dhcp_hostname = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> dhcp_filename = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> dhcp_domain_name = tmp_dict [ '<STR_LIT>' % a ] <EOL> final_list . append ( { '<STR_LIT>' : system . hostname , '<STR_LIT>' : ipv4_address } ) <EOL> return final_list <EOL> if '<STR_LIT>' in request . GET and request . GET [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> try : <EOL> hostname = request . GET . get ( '<STR_LIT>' ) <EOL> key = request . GET . get ( '<STR_LIT:key>' ) <EOL> system = System . objects . get ( hostname = hostname ) <EOL> objects = KeyValue . objects . filter ( key = key , obj = system ) <EOL> tmp = [ ] <EOL> for obj in objects : <EOL> tmp . append ( { '<STR_LIT:key>' : obj . key , '<STR_LIT:value>' : obj . value } ) <EOL> resp = rc . ALL_OK <EOL> resp . write ( "<STR_LIT>" % json . dumps ( tmp ) ) <EOL> except : <EOL> resp = rc . NOT_FOUND <EOL> resp . write ( '<STR_LIT>' ) <EOL> return resp <EOL> if key_type == '<STR_LIT>' : <EOL> dhcp_scope = request . GET [ '<STR_LIT>' ] <EOL> system = System . objects . get ( hostname = request . GET [ '<STR_LIT>' ] ) <EOL> keyvalue_pairs = KeyValue . objects . filter ( key__startswith = '<STR_LIT>' ) . filter ( obj = system ) . order_by ( '<STR_LIT:key>' ) <EOL> tmp_dict = { } <EOL> adapter_ids = [ ] <EOL> final_list = [ ] <EOL> for kv in keyvalue_pairs : <EOL> tmp_dict [ kv . key ] = kv . value <EOL> for k in tmp_dict . iterkeys ( ) : <EOL> matches = re . match ( '<STR_LIT>' , k ) <EOL> if matches . group is not None : <EOL> dhcp_scope_match = '<STR_LIT>' % matches . group ( <NUM_LIT:1> ) <EOL> ip_address_match = '<STR_LIT>' % matches . group ( <NUM_LIT:1> ) <EOL> if matches . group ( <NUM_LIT:1> ) not in adapter_ids and ip_address_match in tmp_dict and dhcp_scope_match in tmp_dict and tmp_dict [ dhcp_scope_match ] == dhcp_scope : <EOL> adapter_ids . append ( matches . group ( <NUM_LIT:1> ) ) <EOL> adapter_ids . sort ( ) <EOL> for a in adapter_ids : <EOL> adapter_name = '<STR_LIT>' <EOL> mac_address = '<STR_LIT>' <EOL> dhcp_hostname = '<STR_LIT>' <EOL> dhcp_filename = '<STR_LIT>' <EOL> dhcp_domain_name = '<STR_LIT>' <EOL> ipv4_address = '<STR_LIT>' <EOL> dhcp_domain_name_servers = '<STR_LIT>' <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> ipv4_address = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> adapter_name = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> mac_address = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict and '<STR_LIT>' % a not in tmp_dict : <EOL> dhcp_hostname = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> dhcp_hostname = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> dhcp_filename = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> dhcp_domain_name = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> dhcp_domain_name_servers = tmp_dict [ '<STR_LIT>' % a ] <EOL> final_list . append ( { '<STR_LIT>' : system . hostname , '<STR_LIT>' : ipv4_address , '<STR_LIT>' : adapter_name , '<STR_LIT>' : mac_address , '<STR_LIT>' : dhcp_hostname , '<STR_LIT>' : dhcp_hostname , '<STR_LIT>' : dhcp_filename , '<STR_LIT>' : dhcp_domain_name , '<STR_LIT>' : dhcp_domain_name_servers } ) <EOL> return final_list <EOL> elif '<STR_LIT:key>' in request . GET and request . GET [ '<STR_LIT:key>' ] > '<STR_LIT>' : <EOL> tmp_list = { } <EOL> try : <EOL> base = KeyValue . objects . filter ( key = request . GET [ '<STR_LIT:key>' ] ) <EOL> for row in base : <EOL> matches = re . match ( "<STR_LIT>" , row . value ) <EOL> if matches is not None : <EOL> m = MacroExpansion ( matches . group ( <NUM_LIT:1> ) ) <EOL> row . value = m . output ( ) <EOL> for r in base : <EOL> key_name = '<STR_LIT>' % ( r . obj . hostname , r . key ) <EOL> tmp_list [ key_name ] = r . value <EOL> except Exception , e : <EOL> pass <EOL> try : <EOL> base = TruthKeyValue . objects . filter ( key = request . GET [ '<STR_LIT:key>' ] ) <EOL> for row in base : <EOL> matches = re . match ( "<STR_LIT>" , row . value ) <EOL> if matches is not None : <EOL> m = MacroExpansion ( matches . group ( <NUM_LIT:1> ) ) <EOL> row . value = m . output ( ) <EOL> for r in base : <EOL> key_name = '<STR_LIT>' % ( r . truth . name , r . key ) <EOL> tmp_list [ key_name ] = r . value <EOL> except Exception , e : <EOL> pass <EOL> return tmp_list <EOL> elif '<STR_LIT:value>' in request . GET : <EOL> tmp_list = { } <EOL> try : <EOL> base = KeyValue . objects . filter ( value = request . GET [ '<STR_LIT:value>' ] ) <EOL> for row in base : <EOL> matches = re . match ( "<STR_LIT>" , row . value ) <EOL> if matches is not None : <EOL> m = MacroExpansion ( matches . group ( <NUM_LIT:1> ) ) <EOL> row . value = m . output ( ) <EOL> for r in base : <EOL> key_name = '<STR_LIT>' % ( r . obj . hostname , r . key ) <EOL> tmp_list [ key_name ] = r . value <EOL> except Exception , e : <EOL> pass <EOL> try : <EOL> base = TruthKeyValue . objects . filter ( value = request . GET [ '<STR_LIT:value>' ] ) <EOL> for row in base : <EOL> matches = re . match ( "<STR_LIT>" , row . value ) <EOL> if matches is not None : <EOL> m = MacroExpansion ( matches . group ( <NUM_LIT:1> ) ) <EOL> row . value = m . output ( ) <EOL> for r in base : <EOL> key_name = '<STR_LIT>' % ( r . truth . name , r . key ) <EOL> tmp_list [ key_name ] = r . value <EOL> except Exception , e : <EOL> pass <EOL> return tmp_list <EOL> def delete ( self , request , key_value_id = None ) : <EOL> if '<STR_LIT>' in request . GET and request . GET [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> try : <EOL> system_hostname = request . GET [ '<STR_LIT>' ] <EOL> system = System . objects . get ( hostname = system_hostname ) <EOL> KeyValue . objects . filter ( key__startswith = '<STR_LIT>' , obj = system ) . delete ( ) <EOL> resp = rc . ALL_OK <EOL> resp . write ( '<STR_LIT>' ) <EOL> except : <EOL> resp = rc . NOT_FOUND <EOL> resp . write ( '<STR_LIT>' ) <EOL> return resp <EOL> if '<STR_LIT>' in request . GET and request . GET [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> try : <EOL> adapter_number = request . GET [ '<STR_LIT>' ] <EOL> system_hostname = request . GET [ '<STR_LIT>' ] <EOL> system = System . objects . get ( hostname = system_hostname ) <EOL> KeyValue . objects . filter ( key__startswith = '<STR_LIT>' % adapter_number , obj = system ) . delete ( ) <EOL> resp = rc . ALL_OK <EOL> resp . write ( '<STR_LIT>' ) <EOL> except : <EOL> resp = rc . NOT_FOUND <EOL> resp . write ( '<STR_LIT>' ) <EOL> return resp <EOL> if '<STR_LIT>' in request . GET and request . GET [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> try : <EOL> system_hostname = request . GET . get ( '<STR_LIT>' ) <EOL> key = request . GET . get ( '<STR_LIT:key>' ) <EOL> system = System . objects . get ( hostname = system_hostname ) <EOL> KeyValue . objects . filter ( key = key , obj = system ) . delete ( ) <EOL> resp = rc . ALL_OK <EOL> resp . write ( '<STR_LIT>' ) <EOL> except : <EOL> resp = rc . NOT_FOUND <EOL> resp . write ( '<STR_LIT>' ) <EOL> return resp <EOL> if '<STR_LIT>' not in request . GET : <EOL> if '<STR_LIT>' in request . GET : <EOL> try : <EOL> n = KeyValue . objects . get ( id = key_value_id ) <EOL> n . delete ( ) <EOL> resp = rc . ALL_OK <EOL> resp . write ( '<STR_LIT>' % str ( key_value_id ) ) <EOL> except : <EOL> resp = rc . NOT_FOUND <EOL> return resp <EOL> if '<STR_LIT>' in request . GET : <EOL> try : <EOL> n = TruthKeyValue . objects . get ( id = key_value_id ) <EOL> n . delete ( ) <EOL> resp = rc . ALL_OK <EOL> resp . write ( '<STR_LIT>' % str ( key_value_id ) ) <EOL> except : <EOL> resp = rc . NOT_FOUND <EOL> return resp <EOL> resp = rc . ALL_OK <EOL> resp . write ( '<STR_LIT>' ) <EOL> return resp </s>
