1- # -*- coding: utf-8 -*-
21"""
32babel.rbnf
43~~~~~~~~~~
3029# Original request for Hebrew (currently not used in Hebrew):
3130# http://bugs.icu-project.org/trac/ticket/4039
3231
33- from __future__ import unicode_literals
3432
3533import re
3634import math
@@ -187,7 +185,7 @@ def _parse_reference(string):
187185 return PUBLIC_REF , string [1 :]
188186 if string [0 ] in '0#' :
189187 return DECIMAL_REF , string
190- warnings .warn ('Reference parsing error: %s' % string , SyntaxWarning )
188+ warnings .warn (f 'Reference parsing error: { string } ' , SyntaxWarning )
191189 return INTERNAL_REF , "" # defaults to this
192190
193191
@@ -202,7 +200,7 @@ def compute_divisor(value, radix):
202200 return None
203201
204202
205- class RuleBasedNumberFormat ( object ) :
203+ class RuleBasedNumberFormat :
206204 """
207205 RuleBasedNumberFormat's behavior consists of one or more rule sets
208206
@@ -264,18 +262,15 @@ def match_ruleset(self, ruleset):
264262 elif ruleset == "ordinal" :
265263 ruleset , exact_match = self ._find_matching_ruleset ("spellout-ordinal" )
266264 if not ruleset :
267- raise RulesetNotFound ("No ordinal ruleset is available for %s" % (
268- self ._locale ,
269- ))
265+ raise RulesetNotFound (f"No ordinal ruleset is available for { self ._locale } " )
270266 if not exact_match :
271- warnings .warn ("Using non-specific ordinal ruleset %s" % ruleset , RulesetSubstitutionWarning )
267+ warnings .warn (f "Using non-specific ordinal ruleset { ruleset } " , RulesetSubstitutionWarning )
272268 ruleset_obj = self .get_ruleset (ruleset )
273269 if not ruleset_obj :
274- raise RulesetNotFound ("Ruleset %r is not one of the ones available for %s: %r" % (
275- ruleset ,
276- self ._locale ,
277- self .available_rulesets ,
278- ))
270+ raise RulesetNotFound (
271+ f"Ruleset { ruleset !r} is not one of the ones available for "
272+ f"{ self ._locale } : { self .available_rulesets !r} "
273+ )
279274 return ruleset_obj
280275
281276 def format (self , number , ruleset = None ):
@@ -302,11 +297,11 @@ def negotiate(cls, locale):
302297 """
303298 loc = Locale .negotiate ([str (Locale .parse (locale ))], get_global ('rbnf_locales' ))
304299 if not loc :
305- raise RulesetNotFound ("No RBNF rules available for %s" % locale )
300+ raise RulesetNotFound (f "No RBNF rules available for { locale } " )
306301 return cls (loc )
307302
308303
309- class Ruleset ( object ) :
304+ class Ruleset :
310305 """
311306 Each rule set consists of a name, a colon, and a list of rules.
312307 (in the ICU syntax, CLDR differs because of XML)
@@ -496,7 +491,7 @@ def apply(self, number, parent, fractional=False):
496491 if fractional :
497492 index = self .get_rule_fractional (remainder )
498493 if index is None :
499- raise RuleNotFound ("rule for fractional processing of %s" % remainder )
494+ raise RuleNotFound (f "rule for fractional processing of { remainder } " )
500495 rule = self .rules [index ]
501496 context [INTEGRAL_TOKEN ] = rule .value * remainder # here remainder == number
502497 context ['omit_optional' ] = rule .value * number == 1
@@ -506,7 +501,7 @@ def apply(self, number, parent, fractional=False):
506501 if number < 0 :
507502 rule = self .get_rule_special (NEGATIVE_NUMBER_RULE )
508503 if rule is None :
509- raise RuleNotFound ("negative number rule (%s)" % NEGATIVE_NUMBER_RULE )
504+ raise RuleNotFound (f "negative number rule ({ NEGATIVE_NUMBER_RULE } )" )
510505 context [REMAINDER_TOKEN ] = abs (number )
511506 return rule .apply (number , context )
512507
@@ -524,20 +519,20 @@ def apply(self, number, parent, fractional=False):
524519 if integral == 0 :
525520 rule = self .get_rule_special (PROPER_FRACTION_RULE )
526521 if rule is None :
527- raise RuleNotFound ("proper fraction rule (%s)" % PROPER_FRACTION_RULE )
522+ raise RuleNotFound (f "proper fraction rule ({ PROPER_FRACTION_RULE } )" )
528523
529524 else :
530525 rule = self .get_rule_special (IMPROPER_FRACTION_RULE )
531526 if rule is None :
532- raise RuleNotFound ("improper fraction rule (%s)" % IMPROPER_FRACTION_RULE )
527+ raise RuleNotFound (f "improper fraction rule ({ IMPROPER_FRACTION_RULE } )" )
533528 context ['omit_optional' ] = 0 < number < 1 # between 0 and 1
534529
535530 return rule .apply (number , context )
536531
537532 # normal rule
538533 index = self .get_rule_integral (integral )
539534 if index is None :
540- raise RuleNotFound ("normal rule for %s" % integral )
535+ raise RuleNotFound (f "normal rule for { integral } " )
541536 rule = self .rules [index ]
542537 i , r = divmod (integral , rule .divisor )
543538 context [REMAINDER_TOKEN ] = r
@@ -629,10 +624,11 @@ def get_rule_fractional(self, val):
629624 return bst
630625
631626 def __repr__ (self ):
632- return 'Ruleset %s %s\n %s\n ' % (self .name , self .private , '\n ' .join (['\t ' + str (r ) for r in self .rules ]))
627+ rules_str = '\n ' .join (['\t ' + str (r ) for r in self .rules ])
628+ return f'Ruleset { self .name } { self .private } \n { rules_str } \n '
633629
634630
635- class Rule ( object ) :
631+ class Rule :
636632 """
637633 base value, a divisor, rule text, and zero, one, or two substitutions.
638634 """
@@ -699,12 +695,10 @@ def apply(self, number, context):
699695 ))
700696
701697 else :
702- raise ValueError ('unknown token %s ' , t )
698+ raise ValueError (f 'unknown token { t } ' , t )
703699
704700 return '' .join (res )
705701
706702 def __repr__ (self ):
707- return 'Rule %s (%s) - %s\n %s\n ' % (
708- self .value , self .text ,
709- self .radix ,
710- '\n ' .join (['\t \t ' + str (t ) for t in self .tokens ]))
703+ tokens_str = '\n ' .join (['\t \t ' + str (t ) for t in self .tokens ])
704+ return f'Rule { self .value } ({ self .text } ) - { self .radix } \n { tokens_str } \n '
0 commit comments