#NEWLINE# def format_compound_unit( numerator_value , numerator_unit = None , denominator_value = 1 , denominator_unit = None , length = 'long' , format = None , locale = LC_NUMERIC ) : #NEWLINE# #INDENT# '\n    Format a compound number value, i.e. "kilometers per hour" or similar.\n\n    Both unit specifiers are optional to allow for formatting of arbitrary values still according\n    to the locale\'s general "per" formatting specifier.\n\n    >>> format_compound_unit(7, denominator_value=11, length="short", locale="pt")\n    \'7/11\'\n\n    >>> format_compound_unit(150, "kilometer", denominator_unit="hour", locale="sv")\n    \'150 kilometer per timme\'\n\n    >>> format_compound_unit(150, "kilowatt", denominator_unit="year", locale="fi")\n    \'150 kilowattia vuodessa\'\n\n    >>> format_compound_unit(32.5, "ton", 15, denominator_unit="hour", locale="en")\n    \'32.5 tons per 15 hours\'\n\n    >>> format_compound_unit(160, denominator_unit="square-meter", locale="fr")\n    \'160 par m\\xe8tre carr\\xe9\'\n\n    >>> format_compound_unit(4, "meter", "ratakisko", length="short", locale="fi")\n    \'4 m/ratakisko\'\n\n    >>> format_compound_unit(35, "minute", denominator_unit="fathom", locale="sv")\n    \'35 minuter per famn\'\n\n    >>> from babel.numbers import format_currency\n    >>> format_compound_unit(format_currency(35, "JPY", locale="de"), denominator_unit="liter", locale="de")\n    \'35\\xa0\\xa5 pro Liter\'\n\n    See http://www.unicode.org/reports/tr35/tr35-general.html#perUnitPatterns\n\n    :param numerator_value: The numerator value. This may be a string,\n                            in which case it is considered preformatted and the unit is ignored.\n    :param numerator_unit: The numerator unit. See `format_unit`.\n    :param denominator_value: The denominator value. This may be a string,\n                              in which case it is considered preformatted and the unit is ignored.\n    :param denominator_unit: The denominator unit. See `format_unit`.\n    :param length: The formatting length. "short", "long" or "narrow"\n    :param format: An optional format, as accepted by `format_decimal`.\n    :param locale: the `Locale` object or locale identifier\n    :return: A formatted compound value.\n    ' #NEWLINE# locale = Locale . parse ( locale ) #NEWLINE# if ( numerator_unit and denominator_unit and ( denominator_value == 1 ) ) : #NEWLINE# #INDENT# compound_unit = _find_compound_unit ( numerator_unit , denominator_unit , locale = locale ) #NEWLINE# if compound_unit : #NEWLINE# #INDENT# return format_unit ( numerator_value , compound_unit , length = length , format = format , locale = locale ) #NEWLINE# #UNINDENT# #UNINDENT# if isinstance ( numerator_value , string_types ) : #NEWLINE# #INDENT# formatted_numerator = numerator_value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if numerator_unit : #NEWLINE# #INDENT# formatted_numerator = format_unit ( numerator_value , numerator_unit , length = length , format = format , locale = locale ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# formatted_numerator = format_decimal ( numerator_value , format = format , locale = locale ) #NEWLINE# #UNINDENT# #UNINDENT# if isinstance ( denominator_value , string_types ) : #NEWLINE# #INDENT# formatted_denominator = denominator_value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if denominator_unit : #NEWLINE# #INDENT# if ( denominator_value == 1 ) : #NEWLINE# #INDENT# denominator_unit = _find_unit_pattern ( denominator_unit , locale = locale ) #NEWLINE# per_pattern = locale . _data [ 'unit_patterns' ] . get ( denominator_unit , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) . get ( length , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) . get ( 'per' ) #NEWLINE# if per_pattern : #NEWLINE# #INDENT# return per_pattern . format ( formatted_numerator ) #NEWLINE# #UNINDENT# denominator_value = '' #NEWLINE# #UNINDENT# formatted_denominator = format_unit ( denominator_value , denominator_unit , length = length , format = format , locale = locale ) . strip ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# formatted_denominator = format_decimal ( denominator_value , format = format , locale = locale ) #NEWLINE# #UNINDENT# #UNINDENT# per_pattern = locale . _data [ 'compound_unit_patterns' ] . get ( 'per' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) . get ( length , '{0}/{1}' ) #NEWLINE# return per_pattern . format ( formatted_numerator , formatted_denominator )