def clean_result_value(self, value): str = unicode #3-- if not isinstance(value, (str, bytes, bytearray)): try: ip, net = value value = '{}/{}'.format(as_unicode(ip), as_unicode(net)) except (ValueError, TypeError): raise FieldValueError(public_message=( self.error_msg_template.format(ascii_str(value)))) # returning a str return super(IPv4NetField, self).clean_result_value(value)
def public_message(self): """The aforementioned property.""" try: return self._public_message except AttributeError: # (in subclasses `default_public_message` can also be a @property) self._public_message = as_unicode(self.default_public_message) return self._public_message
def __init__(self, **kwargs): super(UnicodeEnumField, self).__init__(**kwargs) if self.enum_values is None: raise TypeError("'enum_values' not specified for {} " "(neither as a class attribute nor " "as a constructor argument)".format( self.__class__.__name__)) self.enum_values = tuple(as_unicode(v) for v in self.enum_values)
def __init__(self, **kwargs): super(UnicodeEnumField, self).__init__(**kwargs) if self.enum_values is None: raise TypeError("'enum_values' not specified for {} " "(neither as a class attribute nor " "as a constructor argument)" .format(self.__class__.__name__)) self.enum_values = tuple(as_unicode(v) for v in self.enum_values)
def clean_result_value(self, value): str = unicode #3-- if not isinstance(value, (str, bytes, bytearray)): try: ipv6_raw, prefixlen_raw = value value = '{}/{}'.format(as_unicode(ipv6_raw), as_unicode(prefixlen_raw)) except (ValueError, TypeError): raise FieldValueError(public_message=( self.error_msg_template.format(ascii_str(value)))) ipv6_obj, prefixlen = super(IPv6NetField, self).clean_result_value(value) assert isinstance(ipv6_obj, ipaddress.IPv6Address) ipv6 = str(ipv6_obj.compressed) #3: `str(`-- `)`-- assert isinstance(ipv6, str) assert isinstance(prefixlen, int) and 0 <= prefixlen <= 128, prefixlen # returning a str return str('{}/{}'.format(ipv6, prefixlen)) #3: `str(`-- `)`--
def __init__(self, *args, **kwargs): try: public_message = kwargs.pop( 'public_message' ) #3: better keyword-only arg `public_message`... except KeyError: pass else: self._public_message = as_unicode(public_message) super(_ErrorWithPublicMessageMixin, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): try: public_message = kwargs.pop('public_message') except KeyError: pass else: self._public_message = as_unicode(public_message) try: super(_ErrorWithPublicMessageMixin, self).__init__(*args, **kwargs) except TypeError: if kwargs: raise TypeError( 'illegal keyword arguments for {} constructor: {}'.format( self.__class__.__name__, ', '.join(sorted(map(repr, kwargs))))) else: raise
def __init__(self, *args, public_message=None, **kwargs): if public_message: self._public_message = as_unicode(public_message) super(_ErrorWithPublicMessageMixin, self).__init__(*args, **kwargs)