<s> import xmlrpclib <EOL> from foam . sfa . util . faults import MissingDelegateBit , ChildRightsNotSubsetOfParent <EOL> from foam . sfa . trust . certificate import Certificate <EOL> from foam . sfa . trust . gid import GID <EOL> class CredentialLegacy ( Certificate ) : <EOL> gidCaller = None <EOL> gidObject = None <EOL> lifeTime = None <EOL> privileges = None <EOL> delegate = False <EOL> def __init__ ( self , create = False , subject = None , string = None , filename = None ) : <EOL> Certificate . __init__ ( self , create , subject , string , filename ) <EOL> def set_gid_caller ( self , gid ) : <EOL> self . gidCaller = gid <EOL> self . gidOriginCaller = gid <EOL> def get_gid_caller ( self ) : <EOL> if not self . gidCaller : <EOL> self . decode ( ) <EOL> return self . gidCaller <EOL> def set_gid_object ( self , gid ) : <EOL> self . gidObject = gid <EOL> def get_gid_object ( self ) : <EOL> if not self . gidObject : <EOL> self . decode ( ) <EOL> return self . gidObject <EOL> def set_lifetime ( self , lifeTime ) : <EOL> self . lifeTime = lifeTime <EOL> def get_lifetime ( self ) : <EOL> if not self . lifeTime : <EOL> self . decode ( ) <EOL> return self . lifeTime <EOL> def set_delegate ( self , delegate ) : <EOL> self . delegate = delegate <EOL> def get_delegate ( self ) : <EOL> if not self . delegate : <EOL> self . decode ( ) <EOL> return self . delegate <EOL> def set_privileges ( self , privs ) : <EOL> if isinstance ( privs , str ) : <EOL> self . privileges = Rights ( string = privs ) <EOL> else : <EOL> self . privileges = privs <EOL> def get_privileges ( self ) : <EOL> if not self . privileges : <EOL> self . decode ( ) <EOL> return self . privileges <EOL> def can_perform ( self , op_name ) : <EOL> rights = self . get_privileges ( ) <EOL> if not rights : <EOL> return False <EOL> return rights . can_perform ( op_name ) <EOL> def encode ( self ) : <EOL> dict = { "<STR_LIT>" : None , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : self . lifeTime , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : self . delegate } <EOL> if self . gidCaller : <EOL> dict [ "<STR_LIT>" ] = self . gidCaller . save_to_string ( save_parents = True ) <EOL> if self . gidObject : <EOL> dict [ "<STR_LIT>" ] = self . gidObject . save_to_string ( save_parents = True ) <EOL> if self . privileges : <EOL> dict [ "<STR_LIT>" ] = self . privileges . save_to_string ( ) <EOL> str = xmlrpclib . dumps ( ( dict , ) , allow_none = True ) <EOL> self . set_data ( '<STR_LIT>' + str ) <EOL> def decode ( self ) : <EOL> data = self . get_data ( ) . lstrip ( '<STR_LIT>' ) <EOL> if data : <EOL> dict = xmlrpclib . loads ( data ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> else : <EOL> dict = { } <EOL> self . lifeTime = dict . get ( "<STR_LIT>" , None ) <EOL> self . delegate = dict . get ( "<STR_LIT>" , None ) <EOL> privStr = dict . get ( "<STR_LIT>" , None ) <EOL> if privStr : <EOL> self . privileges = Rights ( string = privStr ) <EOL> else : <EOL> self . privileges = None <EOL> gidCallerStr = dict . get ( "<STR_LIT>" , None ) <EOL> if gidCallerStr : <EOL> self . gidCaller = GID ( string = gidCallerStr ) <EOL> else : <EOL> self . gidCaller = None <EOL> gidObjectStr = dict . get ( "<STR_LIT>" , None ) <EOL> if gidObjectStr : <EOL> self . gidObject = GID ( string = gidObjectStr ) <EOL> else : <EOL> self . gidObject = None <EOL> def verify_chain ( self , trusted_certs = None ) : <EOL> Certificate . verify_chain ( self , trusted_certs ) <EOL> if self . parent : <EOL> if not self . parent . get_delegate ( ) : <EOL> raise MissingDelegateBit ( self . parent . get_subject ( ) ) <EOL> if not self . parent . get_privileges ( ) . is_superset ( self . get_privileges ( ) ) : <EOL> raise ChildRightsNotSubsetOfParent ( self . get_subject ( ) <EOL> + "<STR_LIT:U+0020>" + self . parent . get_privileges ( ) . save_to_string ( ) <EOL> + "<STR_LIT:U+0020>" + self . get_privileges ( ) . save_to_string ( ) ) <EOL> return <EOL> def dump ( self , * args , ** kwargs ) : <EOL> print self . dump_string ( * args , ** kwargs ) <EOL> def dump_string ( self , dump_parents = False ) : <EOL> result = "<STR_LIT>" <EOL> result += "<STR_LIT>" % self . get_subject ( ) <EOL> result += "<STR_LIT>" % self . get_privileges ( ) . save_to_string ( ) <EOL> gidCaller = self . get_gid_caller ( ) <EOL> if gidCaller : <EOL> result += "<STR_LIT>" <EOL> gidCaller . dump ( <NUM_LIT:8> , dump_parents ) <EOL> gidObject = self . get_gid_object ( ) <EOL> if gidObject : <EOL> result += "<STR_LIT>" <EOL> result += gidObject . dump_string ( <NUM_LIT:8> , dump_parents ) <EOL> result += "<STR_LIT>" % self . get_delegate ( ) <EOL> if self . parent and dump_parents : <EOL> result += "<STR_LIT>" <EOL> result += self . parent . dump_string ( dump_parents ) <EOL> return result </s>
