def _convert_to_python(self, value, state):
        if not value:
            return u''
        if isinstance(value, six.text_type):
            return value
        if not isinstance(value, six.text_type):
            if hasattr(value, '__unicode__'):
                value = six.text_type(value)
                return value
            if not (six.text_type is str  # Python 3
                    and isinstance(value, bytes) and self.inputEncoding):
                value = str(value)
        if self.inputEncoding and not isinstance(value, six.text_type):
            try:
                value = six.text_type(value, self.inputEncoding)
            except UnicodeDecodeError:
                raise Invalid(self.message('badEncoding', state), value, state)
            except __HOLE__:
                raise Invalid(
                    self.message('badType', state,
                        type=type(value), value=value), value, state)
        return value
dataset/ETHPy150Open formencode/formencode/formencode/validators.py/UnicodeString._convert_to_python