typedargs/typeinfo.py
def format_value(self, value, type, format=None, **kwargs):
        """
        Convert value to type and format it as a string

        type must be a known type in the type system and format,
        if given, must specify a valid formatting option for the
        specified type.
        """

        typed_val = self.convert_to_type(value, type, **kwargs)
        typeobj = self.get_type(type)

        #Allow types to specify default formatting functions as 'default_formatter'
        #otherwise if not format is specified, just convert the value to a string
        if format is None:
            if hasattr(typeobj, 'default_formatter'):
                format_func = getattr(typeobj, 'default_formatter')
                return format_func(typed_val, **kwargs)

            return str(typed_val)

        formatter = "format_%s" % str(format)
        if not hasattr(typeobj, formatter):
            raise ArgumentError("Unknown format for type", type=type, format=format, formatter_function=formatter)

        format_func = getattr(typeobj, formatter)
        return format_func(typed_val, **kwargs)
def format_value(self, value, type, format=None, **kwargs):
        typed_val = self.convert_to_type(value, type, **kwargs)
        typeobj = self.get_type(type)

        #Allow types to specify default formatting functions as 'default_formatter'
        #otherwise if not format is specified, just convert the value to a string
        if format is None:
            if hasattr(typeobj, 'default_formatter'):
                format_func = getattr(typeobj, 'default_formatter')
                return format_func(typed_val, **kwargs)

            return str(typed_val)

        formatter = "format_%s" % str(format)
        if not hasattr(typeobj, formatter):
            raise ArgumentError("Unknown format for type", type=type, format=format, formatter_function=formatter)

        format_func = getattr(typeobj, formatter)
        return format_func(typed_val, **kwargs)
def format_value ( self , value , type , format = None , * * kwargs ) : typed_val = self . convert_to_type ( value , type , * * kwargs ) typeobj = self . get_type ( type ) #Allow types to specify default formatting functions as 'default_formatter' #otherwise if not format is specified, just convert the value to a string if format is None : if hasattr ( typeobj , 'default_formatter' ) : format_func = getattr ( typeobj , 'default_formatter' ) return format_func ( typed_val , * * kwargs ) return str ( typed_val ) formatter = "format_%s" % str ( format ) if not hasattr ( typeobj , formatter ) : raise ArgumentError ( "Unknown format for type" , type = type , format = format , formatter_function = formatter ) format_func = getattr ( typeobj , formatter ) return format_func ( typed_val , * * kwargs )
Convert value to type and format it as a string

        type must be a known type in the type system and format,
        if given, must specify a valid formatting option for the
        specified type.
Convert value to type and format it as a string