def calculate_legal_entity_fields(obj, sess, county_by_code, state_code_list, country_list):
    " calculate values that aren't in any feed (or haven't been provided properly) for legal entity "
    if (obj['legal_entity_country_code'] in country_code_map):
        if (obj['legal_entity_country_code'] != 'USA'):
            obj['legal_entity_state_code'] = country_code_map[obj['legal_entity_country_code']]
            if (obj['legal_entity_state_code'] in state_code_list):
                obj['legal_entity_state_descrip'] = state_code_list[obj['legal_entity_state_code']]
            obj['legal_entity_country_code'] = 'USA'
            obj['legal_entity_country_name'] = 'UNITED STATES'
        if (obj['legal_entity_state_code'] and (not obj['legal_entity_state_descrip']) and (obj['legal_entity_state_code'] in state_code_list)):
            obj['legal_entity_state_descrip'] = state_code_list[obj['legal_entity_state_code']]
        if (obj['legal_entity_zip4'] and is_valid_zip(obj['legal_entity_zip4'])):
            obj['legal_entity_county_code'] = get_county_by_zip(sess, obj['legal_entity_zip4'])
            if (obj['legal_entity_county_code'] and obj['legal_entity_state_code']):
                county_code = obj['legal_entity_county_code']
                state = obj['legal_entity_state_code']
                if ((state in county_by_code) and (county_code in county_by_code[state])):
                    obj['legal_entity_county_name'] = county_by_code[state][county_code]
            obj['legal_entity_zip5'] = obj['legal_entity_zip4'][:5]
            if (len(obj['legal_entity_zip4']) > 5):
                obj['legal_entity_zip_last4'] = obj['legal_entity_zip4'][(- 4):]
    if ((not obj['legal_entity_country_name']) and (obj['legal_entity_country_code'] in country_list)):
        obj['legal_entity_country_name'] = country_list[obj['legal_entity_country_code']]
calculate values that aren't in any feed (or haven't been provided properly) for legal entity
def calculate_legal_entity_fields(obj, sess, county_by_code, state_code_list, country_list):
    "  "
    if (obj['legal_entity_country_code'] in country_code_map):
        if (obj['legal_entity_country_code'] != 'USA'):
            obj['legal_entity_state_code'] = country_code_map[obj['legal_entity_country_code']]
            if (obj['legal_entity_state_code'] in state_code_list):
                obj['legal_entity_state_descrip'] = state_code_list[obj['legal_entity_state_code']]
            obj['legal_entity_country_code'] = 'USA'
            obj['legal_entity_country_name'] = 'UNITED STATES'
        if (obj['legal_entity_state_code'] and (not obj['legal_entity_state_descrip']) and (obj['legal_entity_state_code'] in state_code_list)):
            obj['legal_entity_state_descrip'] = state_code_list[obj['legal_entity_state_code']]
        if (obj['legal_entity_zip4'] and is_valid_zip(obj['legal_entity_zip4'])):
            obj['legal_entity_county_code'] = get_county_by_zip(sess, obj['legal_entity_zip4'])
            if (obj['legal_entity_county_code'] and obj['legal_entity_state_code']):
                county_code = obj['legal_entity_county_code']
                state = obj['legal_entity_state_code']
                if ((state in county_by_code) and (county_code in county_by_code[state])):
                    obj['legal_entity_county_name'] = county_by_code[state][county_code]
            obj['legal_entity_zip5'] = obj['legal_entity_zip4'][:5]
            if (len(obj['legal_entity_zip4']) > 5):
                obj['legal_entity_zip_last4'] = obj['legal_entity_zip4'][(- 4):]
    if ((not obj['legal_entity_country_name']) and (obj['legal_entity_country_code'] in country_list)):
        obj['legal_entity_country_name'] = country_list[obj['legal_entity_country_code']]