def _convert(self, value): """Returns a Encryption object from the given string. PasswordHash instances or None values will return unchanged. Strings will be hashed and the resulting PasswordHash returned. Any other input will result in a TypeError. """ if isinstance(value, Encryption): return value elif isinstance(value, basestring): return Encryption.new(value, self.cipher_key) elif value is not None: raise TypeError( 'Cannot convert {} to a EncryptedValue'.format(type(value)))