Format the instance to a common string format.

        :param fmt: The name of the string format
        :type fmt: string

        :param locale: The locale to use
        :type locale: str or None

        :rtype: str
162723
def _to_string(self, fmt, locale=None):
        
        if fmt not in self._FORMATS:
            raise ValueError("Format [{}] is not supported".format(fmt))

        fmt = self._FORMATS[fmt]
        if callable(fmt):
            return fmt(self)

        return self.format(fmt, locale=locale)
933267
String format(FormatCase fc, FormatAction fa, FormatWhen fw,
                    FormatResolve fr, FormatUnresolved fu, FormatErrors fe,
                    String name, String type, String value, String unresolved, List<String> errorLines) {
            return format("display", fc, fa, fw, fr, fu, fe,
                name, type, value, unresolved, errorLines);
        }
1353575
public static String format(String format, Object... args) {
    return String.format(Locale.US, format, args);
  }
611943
public void setLocale(Locale locale) {
		if (locale == getLocale() || ignoreDatePatternChange) {
			return;
		}

		super.setLocale(locale);
		dateFormatter = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
		setToolTipText(dateFormatter.toPattern());

		setDate(date, false);
		doLayout();
	}
675126
def format_label(sl, fmt=None):
    
    if isinstance(sl, str):
        # Already is a string.
        return sl

    if fmt:
        return fmt.format(*sl)

    return ' '.join(str(s) for s in sl)
1154884
public void format(StringBuffer fmt, Set done, Set todo, int indent) {
    formatName(fmt, indent);
    fmt.append("*(\n");
    itemType.format(fmt, done, todo, indent + 2);
    fmt.append("\n");
    indent(fmt, indent);
    fmt.append(")*");
  }
1073372
public void format(StringBuffer fmt, Set done, Set todo, int indent) {
    formatName(fmt, indent);
    fmt.append(typeNames[typeCode]);
  }
772002
def _set_format_scope(self, fmt):
        
        self._prev_fmt = QtGui.QTextCharFormat(fmt)
        self._prev_fmt_closed = False
390979
function sn_format_fmt() {
	if ( !arguments.length ) {
		return;
	}
	var i = 0,
		formatted = arguments[i],
		regexp,
		replaceValue;
	for ( i = 1; i < arguments.length; i += 1 ) {
		regexp = new RegExp('\\{'+(i-1)+'\\}', 'gi');
		replaceValue = arguments[i];
		if ( replaceValue instanceof Date ) {
			replaceValue = (replaceValue.getUTCHours() === 0 && replaceValue.getMinutes() === 0 
				? sn.format.dateFormat(replaceValue) : sn.format.dateTimeFormatURL(replaceValue));
		}
		formatted = formatted.replace(regexp, replaceValue);
	}
	return formatted;
}
506688
private String format( Object[] arguments )
    {
        Locale l = Locale.getDefault();
        if ( locale != null )
        {
            String[] parts = locale.split( "_", 3 );
            if ( parts.length <= 1 )
            {
                l = new Locale( locale );
            }
            else if ( parts.length == 2 )
            {
                l = new Locale( parts[0], parts[1] );
            }
            else
            {
                l = new Locale( parts[0], parts[1], parts[2] );
            }
        }

        return new MessageFormat( format, l ).format( arguments );
    }
863897
def floatformat(fmt_string):
    
    fmt_defaults = scientificformat.__defaults__
    scientificformat.__defaults__ = (fmt_string,) + fmt_defaults[1:]
    try:
        yield
    finally:
        scientificformat.__defaults__ = fmt_defaults
717920
def format_field(self, value, format_spec):
        
        if format_spec:
            spec, arg = format_spec[0], format_spec[1:]
            arg = arg or None
        else:
            spec = arg = None
        return self._format_field(spec, arg, value, self.numeric_locale)
298098
def format_value(self, value):
        
        if value == '' or value is None:
            return None
        return formats.localize_input(value, self.format)
1122585
def fmt_datetime(d, fmt='', local=True):
    
    if not d:
        return ''
    if local:
        from django.templatetags.tz import localtime
        d = localtime(d)
    if not fmt:
        fmt = '%Y-%m-%d %H-%M'
    return d.strftime(fmt)
226592
def set_format_options(fmt, format_options):
    """"""
    if not format_options:
        return

    for opt in format_options:
        try:
            key, value = opt.split('=')
        except ValueError:
            raise ValueError("Format options are expected to be of the form key=value, not '{}'".format(opt))

        if key not in _VALID_FORMAT_OPTIONS:
            raise ValueError("'{}' is not a valid format option. Expected one of '{}'"
                             .format(key, "', '".join(_VALID_FORMAT_OPTIONS)))

        if key in _BINARY_FORMAT_OPTIONS:
            value = str2bool(value)

        fmt[key] = value
134380
def _wrap_locale_formatter(fn, locale_type):
    """"""

    def wrapped_locale_formatter(*args, **kwargs):
        """A Babel formatting function, wrapped to automatically use the
        currently installed language.

        The wrapped function will not throw any exceptions for unknown locales,
        if Babel doesn't recognise the locale, we will simply fall back to
        the default language.

        The locale used by the wrapped function can be overriden by passing it a `locale` keyword.
        To learn more about this function, check the documentation of Babel for the function of
        the same name.
        """
        # Get the current locale from the class
        kwargs_ = {'locale': getattr(InstalledLocale, locale_type)}
        # By creating a dict then updating it, we allow locale to be overridden
        kwargs_.update(kwargs)
        try:
            formatted = fn(*args, **kwargs_)
        except UnknownLocaleError:
            log.warning(
                """Can\'t do formatting for language code {locale},
                           falling back to default {default}""".format(
                    locale=kwargs_['locale'],
                    default=settings.DEFAULT_LANG)
            )
            kwargs_['locale'] = settings.DEFAULT_LANG
            formatted = fn(*args, **kwargs_)
        return formatted

    return wrapped_locale_formatter
583248
private static DateFormatSymbols getCachedInstance(Locale locale) {
        SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale);
        DateFormatSymbols dfs = null;
        if (ref == null || (dfs = ref.get()) == null) {
            dfs = new DateFormatSymbols(locale);
            ref = new SoftReference<DateFormatSymbols>(dfs);
            SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref);
            if (x != null) {
                DateFormatSymbols y = x.get();
                if (y != null) {
                    dfs = y;
                } else {
                    // Replace the empty SoftReference with ref.
                    cachedInstances.put(locale, ref);
                }
            }
        }
        return dfs;
    }