def get_format(format):
if isinstance(format, BaseFormat):<EOL><INDENT>return format<EOL><DEDENT>if isinstance(format, str):<EOL><INDENT>for name, formatclass in list(globals().items()):<EOL><INDENT>if name.lower() == format.lower():<EOL><INDENT>if not issubclass(formatclass, BaseFormat):<EOL><INDENT>raise ValueError('<STR_LIT>' % format)<EOL><DEDENT>return formatclass()<EOL><DEDENT><DEDENT><DEDENT>try:<EOL><INDENT>return format()<EOL><DEDENT>except:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>
Get a format object.

    If format is a format object, return unchanged. If it is a string 
    matching one of the BaseFormat subclasses in the tui.formats module
    (case insensitive), return an instance of that class. Otherwise assume 
    it'a factory function for Formats (such as a class) so call and return,
    and raise ValueError on error.