Use str.format()
This commit is contained in:
parent
d1fd32fd5b
commit
1cc86cc3c8
5 changed files with 26 additions and 26 deletions
|
|
@ -2199,14 +2199,14 @@ def convertColor(value):
|
|||
r = int(float(rgbpMatch.group(1)) * 255.0 / 100.0)
|
||||
g = int(float(rgbpMatch.group(2)) * 255.0 / 100.0)
|
||||
b = int(float(rgbpMatch.group(3)) * 255.0 / 100.0)
|
||||
s = '#%02x%02x%02x' % (r, g, b)
|
||||
s = '#{:02x}{:02x}{:02x}'.format(r, g, b)
|
||||
else:
|
||||
rgbMatch = rgb.match(s)
|
||||
if rgbMatch is not None:
|
||||
r = int(rgbMatch.group(1))
|
||||
g = int(rgbMatch.group(2))
|
||||
b = int(rgbMatch.group(3))
|
||||
s = '#%02x%02x%02x' % (r, g, b)
|
||||
s = '#{:02x}{:02x}{:02x}'.format(r, g, b)
|
||||
|
||||
if s[0] == '#':
|
||||
s = s.lower()
|
||||
|
|
@ -2988,8 +2988,8 @@ def scourUnitlessLength(length, renderer_workaround=False, is_control_point=Fals
|
|||
# Gather the non-scientific notation version of the coordinate.
|
||||
# Re-quantize from the initial value to prevent unnecessary loss of precision
|
||||
# (e.g. 123.4 should become 123, not 120 or even 100)
|
||||
nonsci = '{0:f}'.format(length)
|
||||
nonsci = '{0:f}'.format(initial_length.quantize(Decimal(nonsci)))
|
||||
nonsci = '{:f}'.format(length)
|
||||
nonsci = '{:f}'.format(initial_length.quantize(Decimal(nonsci)))
|
||||
if not renderer_workaround:
|
||||
if len(nonsci) > 2 and nonsci[:2] == '0.':
|
||||
nonsci = nonsci[1:] # remove the 0, leave the dot
|
||||
|
|
@ -3406,7 +3406,7 @@ def properlySizeDoc(docElement, options):
|
|||
pass
|
||||
|
||||
# at this point it's safe to set the viewBox and remove width/height
|
||||
docElement.setAttribute('viewBox', '0 0 %s %s' % (w.value, h.value))
|
||||
docElement.setAttribute('viewBox', '0 0 {} {}'.format(w.value, h.value))
|
||||
docElement.removeAttribute('width')
|
||||
docElement.removeAttribute('height')
|
||||
|
||||
|
|
@ -3899,7 +3899,7 @@ class HeaderedFormatter(optparse.IndentedHelpFormatter):
|
|||
"""
|
||||
|
||||
def format_usage(self, usage):
|
||||
return "%s %s\n%s\n%s" % (APP, VER, COPYRIGHT,
|
||||
return "{} {}\n{}\n{}".format(APP, VER, COPYRIGHT,
|
||||
optparse.IndentedHelpFormatter.format_usage(self, usage))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ class Lexer:
|
|||
self.lexicon = lexicon
|
||||
parts = []
|
||||
for name, regex in lexicon:
|
||||
parts.append('(?P<%s>%s)' % (name, regex))
|
||||
parts.append('(?P<{}>{})'.format(name, regex))
|
||||
self.regex_string = '|'.join(parts)
|
||||
self.regex = re.compile(self.regex_string)
|
||||
|
||||
|
|
@ -162,7 +162,7 @@ class SVGPathParser:
|
|||
commands = []
|
||||
while token[0] is not EOF:
|
||||
if token[0] != 'command':
|
||||
raise SyntaxError("expecting a command; got %r" % (token,))
|
||||
raise SyntaxError("expecting a command; got {!r}".format(token))
|
||||
rule = self.command_dispatch[token[1]]
|
||||
command_group, token = rule(next_val_fn, token)
|
||||
commands.append(command_group)
|
||||
|
|
@ -231,23 +231,23 @@ class SVGPathParser:
|
|||
while token[0] in self.number_tokens:
|
||||
rx = Decimal(token[1]) * 1
|
||||
if rx < Decimal("0.0"):
|
||||
raise SyntaxError("expecting a nonnegative number; got %r" % (token,))
|
||||
raise SyntaxError("expecting a nonnegative number; got {!r}".format(token))
|
||||
|
||||
token = next_val_fn()
|
||||
if token[0] not in self.number_tokens:
|
||||
raise SyntaxError("expecting a number; got %r" % (token,))
|
||||
raise SyntaxError("expecting a number; got {!r}".format(token))
|
||||
ry = Decimal(token[1]) * 1
|
||||
if ry < Decimal("0.0"):
|
||||
raise SyntaxError("expecting a nonnegative number; got %r" % (token,))
|
||||
raise SyntaxError("expecting a nonnegative number; got {!r}".format(token))
|
||||
|
||||
token = next_val_fn()
|
||||
if token[0] not in self.number_tokens:
|
||||
raise SyntaxError("expecting a number; got %r" % (token,))
|
||||
raise SyntaxError("expecting a number; got {!r}".format(token))
|
||||
axis_rotation = Decimal(token[1]) * 1
|
||||
|
||||
token = next_val_fn()
|
||||
if token[1][0] not in ('0', '1'):
|
||||
raise SyntaxError("expecting a boolean flag; got %r" % (token,))
|
||||
raise SyntaxError("expecting a boolean flag; got {!r}".format(token))
|
||||
large_arc_flag = Decimal(token[1][0]) * 1
|
||||
|
||||
if len(token[1]) > 1:
|
||||
|
|
@ -256,7 +256,7 @@ class SVGPathParser:
|
|||
else:
|
||||
token = next_val_fn()
|
||||
if token[1][0] not in ('0', '1'):
|
||||
raise SyntaxError("expecting a boolean flag; got %r" % (token,))
|
||||
raise SyntaxError("expecting a boolean flag; got {!r}".format(token))
|
||||
sweep_flag = Decimal(token[1][0]) * 1
|
||||
|
||||
if len(token[1]) > 1:
|
||||
|
|
@ -265,12 +265,12 @@ class SVGPathParser:
|
|||
else:
|
||||
token = next_val_fn()
|
||||
if token[0] not in self.number_tokens:
|
||||
raise SyntaxError("expecting a number; got %r" % (token,))
|
||||
raise SyntaxError("expecting a number; got {!r}".format(token))
|
||||
x = Decimal(token[1]) * 1
|
||||
|
||||
token = next_val_fn()
|
||||
if token[0] not in self.number_tokens:
|
||||
raise SyntaxError("expecting a number; got %r" % (token,))
|
||||
raise SyntaxError("expecting a number; got {!r}".format(token))
|
||||
y = Decimal(token[1]) * 1
|
||||
|
||||
token = next_val_fn()
|
||||
|
|
@ -280,7 +280,7 @@ class SVGPathParser:
|
|||
|
||||
def rule_coordinate(self, next_val_fn, token):
|
||||
if token[0] not in self.number_tokens:
|
||||
raise SyntaxError("expecting a number; got %r" % (token,))
|
||||
raise SyntaxError("expecting a number; got {!r}".format(token))
|
||||
x = getcontext().create_decimal(token[1])
|
||||
token = next_val_fn()
|
||||
return x, token
|
||||
|
|
@ -288,11 +288,11 @@ class SVGPathParser:
|
|||
def rule_coordinate_pair(self, next_val_fn, token):
|
||||
# Inline these since this rule is so common.
|
||||
if token[0] not in self.number_tokens:
|
||||
raise SyntaxError("expecting a number; got %r" % (token,))
|
||||
raise SyntaxError("expecting a number; got {!r}".format(token))
|
||||
x = getcontext().create_decimal(token[1])
|
||||
token = next_val_fn()
|
||||
if token[0] not in self.number_tokens:
|
||||
raise SyntaxError("expecting a number; got %r" % (token,))
|
||||
raise SyntaxError("expecting a number; got {!r}".format(token))
|
||||
y = getcontext().create_decimal(token[1])
|
||||
token = next_val_fn()
|
||||
return [x, y], token
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ class Lexer:
|
|||
self.lexicon = lexicon
|
||||
parts = []
|
||||
for name, regex in lexicon:
|
||||
parts.append('(?P<%s>%s)' % (name, regex))
|
||||
parts.append('(?P<{}>{})'.format(name, regex))
|
||||
self.regex_string = '|'.join(parts)
|
||||
self.regex = re.compile(self.regex_string)
|
||||
|
||||
|
|
@ -164,15 +164,15 @@ class SVGTransformationParser:
|
|||
|
||||
def rule_svg_transform(self, next_val_fn, token):
|
||||
if token[0] != 'command':
|
||||
raise SyntaxError("expecting a transformation type; got %r" % (token,))
|
||||
raise SyntaxError("expecting a transformation type; got {!r}".format(token))
|
||||
command = token[1]
|
||||
rule = self.command_dispatch[command]
|
||||
token = next_val_fn()
|
||||
if token[0] != 'coordstart':
|
||||
raise SyntaxError("expecting '('; got %r" % (token,))
|
||||
raise SyntaxError("expecting '('; got {!r}".format(token))
|
||||
numbers, token = rule(next_val_fn, token)
|
||||
if token[0] != 'coordend':
|
||||
raise SyntaxError("expecting ')'; got %r" % (token,))
|
||||
raise SyntaxError("expecting ')'; got {!r}".format(token))
|
||||
token = next_val_fn()
|
||||
return (command, numbers), token
|
||||
|
||||
|
|
@ -225,7 +225,7 @@ class SVGTransformationParser:
|
|||
|
||||
def rule_number(self, next_val_fn, token):
|
||||
if token[0] not in self.number_tokens:
|
||||
raise SyntaxError("expecting a number; got %r" % (token,))
|
||||
raise SyntaxError("expecting a number; got {!r}".format(token))
|
||||
x = Decimal(token[1]) * 1
|
||||
token = next_val_fn()
|
||||
return x, token
|
||||
|
|
|
|||
2
setup.py
2
setup.py
|
|
@ -50,7 +50,7 @@ mo = re.search(VSRE, verstrline, re.M)
|
|||
if mo:
|
||||
verstr = mo.group(1)
|
||||
else:
|
||||
raise RuntimeError("Unable to find version string in %s." % (VERSIONFILE,))
|
||||
raise RuntimeError("Unable to find version string in {}.".format(VERSIONFILE))
|
||||
|
||||
|
||||
setup(
|
||||
|
|
|
|||
|
|
@ -2228,7 +2228,7 @@ class PathCommandRewrites(unittest.TestCase):
|
|||
expected_path, message = expected_paths[i]
|
||||
self.assertEqual(actual_path,
|
||||
expected_path,
|
||||
'%s: "%s" != "%s"' % (message, actual_path, expected_path))
|
||||
'{}: "{}" != "{}"'.format(message, actual_path, expected_path))
|
||||
|
||||
|
||||
class DefaultsRemovalToplevel(unittest.TestCase):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue