<s> """<STR_LIT>""" <EOL> class ThriftDiff : <EOL> def __init__ ( self , struct_a , struct_b ) : <EOL> self . _a = struct_a <EOL> self . _b = struct_b <EOL> self . _common_fields = [ ] <EOL> self . _fields_only_in_a = [ ] <EOL> self . _fields_only_in_b = [ ] <EOL> self . _fields_with_different_value = [ ] <EOL> self . _fields_with_same_value = [ ] <EOL> @ classmethod <EOL> def of_structs ( cls , a , b ) : <EOL> """<STR_LIT>""" <EOL> t_diff = ThriftDiff ( a , b ) <EOL> t_diff . _do_diff ( ) <EOL> return t_diff <EOL> @ classmethod <EOL> def of_messages ( cls , msg_a , msg_b ) : <EOL> """<STR_LIT>""" <EOL> ok_to_diff , reason = cls . can_diff ( msg_a , msg_b ) <EOL> if not ok_to_diff : <EOL> raise ValueError ( reason ) <EOL> return [ cls . of_structs ( x . value , y . value ) <EOL> for x , y in zip ( msg_a . args , msg_b . args ) <EOL> if x . field_type == '<STR_LIT>' ] <EOL> @ staticmethod <EOL> def can_diff ( msg_a , msg_b ) : <EOL> """<STR_LIT>""" <EOL> if msg_a . method != msg_b . method : <EOL> return False , '<STR_LIT>' <EOL> if len ( msg_a . args ) != len ( msg_b . args ) or not msg_a . args . is_isomorphic_to ( msg_b . args ) : <EOL> return False , '<STR_LIT>' <EOL> return True , None <EOL> def _do_diff ( self ) : <EOL> self . _common_fields = [ ( x , y ) <EOL> for x , y in zip ( self . _a . fields , self . _b . fields ) <EOL> if x . is_isomorphic_to ( y ) ] <EOL> self . _fields_only_in_a = self . _unique_fields ( self . _common_fields , <EOL> self . _a . fields ) <EOL> self . _fields_only_in_b = self . _unique_fields ( self . _common_fields , <EOL> self . _b . fields ) <EOL> for field_pair in self . _common_fields : <EOL> if field_pair [ <NUM_LIT:0> ] == field_pair [ <NUM_LIT:1> ] : <EOL> self . _fields_with_same_value . append ( field_pair [ <NUM_LIT:0> ] ) <EOL> else : <EOL> self . _fields_with_different_value . append ( field_pair ) <EOL> @ staticmethod <EOL> def _unique_fields ( common_fields , all_fields ) : <EOL> unique_fields = [ ] <EOL> for x in all_fields : <EOL> is_unique = True <EOL> for field_pair in common_fields : <EOL> if x . is_isomorphic_to ( field_pair [ <NUM_LIT:0> ] ) : <EOL> is_unique = False <EOL> break <EOL> if is_unique : <EOL> unique_fields . append ( x ) <EOL> return unique_fields <EOL> @ property <EOL> def common_fields ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _common_fields <EOL> @ property <EOL> def fields_only_in_a ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _fields_only_in_a <EOL> @ property <EOL> def fields_only_in_b ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _fields_only_in_b <EOL> @ property <EOL> def fields_with_same_value ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _fields_with_same_value <EOL> @ property <EOL> def field_with_different_value ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _fields_with_different_value </s>
