def format_unit(value, measurement_unit, length='long', format=None, locale=LC_NUMERIC):
 locale = Locale.parse(locale)
 q_unit = _find_unit_pattern(measurement_unit, locale=locale)
 if (not q_unit):
  raise UnknownUnitError(unit=measurement_unit, locale=locale)
 unit_patterns = locale._data['unit_patterns'][q_unit].get(length, {})
 if isinstance(value, string_types):
  formatted_value = value
  plural_form = 'one'
 else:
  formatted_value = format_decimal(value, format, locale)
  plural_form = locale.plural_form(value)
 if (plural_form in unit_patterns):
  return unit_patterns[plural_form].format(formatted_value)
 return ('%s %s' % (formatted_value, (get_unit_name(measurement_unit, length=length, locale=locale) or measurement_unit)))

def format_unit ( value , measurement_unit , length = 'long' , format = None , locale = LC_NUMERIC ) : locale = Locale . parse ( locale ) q_unit = _find_unit_pattern ( measurement_unit , locale = locale ) if ( not q_unit ) : raise UnknownUnitError ( unit = measurement_unit , locale = locale ) unit_patterns = locale . _data [ 'unit_patterns' ] [ q_unit ] . get ( length , { } ) if isinstance ( value , string_types ) : formatted_value = value plural_form = 'one' else : formatted_value = format_decimal ( value , format , locale ) plural_form = locale . plural_form ( value ) if ( plural_form in unit_patterns ) : return unit_patterns [ plural_form ] . format ( formatted_value ) return ( '%s %s' % ( formatted_value , ( get_unit_name ( measurement_unit , length = length , locale = locale ) or measurement_unit ) ) )
format a value of a given unit .