def clean(self):
        external_segment_dict = {}
        cleaned_data = super(UpdateL3PolicyForm, self).clean()
        if self.is_valid():
            ipversion = int(cleaned_data['ip_version'])
            subnet_prefix_length = int(cleaned_data['subnet_prefix_length'])
            msg = _("Subnet prefix out of range.")
            if ipversion == 4 and subnet_prefix_length not in range(2, 31):
                raise forms.ValidationError(msg)
            if ipversion == 6 and subnet_prefix_length not in range(2, 128):
                raise forms.ValidationError(msg)
            if cleaned_data['external_segments']:
                dic = {}
                for external_segment in cleaned_data['external_segments']:
                    values = [i.split(":")[1]
                        for i in external_segment.split(",")]
                    dic[values[0]] = [values[1]]
                    external_segment_dict.update(dic)
                cleaned_data['external_segments'] = external_segment_dict
            else:
                cleaned_data['external_segments'] = {}
            updated_data = {d: cleaned_data[d] for d in cleaned_data
                if d in self.changed_data}
            cleaned_data = updated_data
        return cleaned_data
dataset/ETHPy150Open openstack/group-based-policy-ui/gbpui/panels/network_policy/forms.py/UpdateL3PolicyForm.clean/original