@@ -40,7 +40,7 @@ class Attribute(StringMixIn): | |||||
pad_before_eq="", pad_after_eq="", check_quotes=True): | pad_before_eq="", pad_after_eq="", check_quotes=True): | ||||
super(Attribute, self).__init__() | super(Attribute, self).__init__() | ||||
if check_quotes and not quotes and self._value_needs_quotes(value): | if check_quotes and not quotes and self._value_needs_quotes(value): | ||||
raise ValueError("given value {0!r} requires quotes".format(value)) | |||||
raise ValueError("given value {!r} requires quotes".format(value)) | |||||
self._name = name | self._name = name | ||||
self._value = value | self._value = value | ||||
self._quotes = quotes | self._quotes = quotes | ||||
@@ -79,7 +79,7 @@ class Attribute(StringMixIn): | |||||
"""Coerce a quote type into an acceptable value, or raise an error.""" | """Coerce a quote type into an acceptable value, or raise an error.""" | ||||
orig, quotes = quotes, str(quotes) if quotes else None | orig, quotes = quotes, str(quotes) if quotes else None | ||||
if quotes not in [None, '"', "'"]: | if quotes not in [None, '"', "'"]: | ||||
raise ValueError("{0!r} is not a valid quote type".format(orig)) | |||||
raise ValueError("{!r} is not a valid quote type".format(orig)) | |||||
return quotes | return quotes | ||||
@property | @property | ||||
@@ -41,7 +41,7 @@ class Parameter(StringMixIn): | |||||
def __init__(self, name, value, showkey=True): | def __init__(self, name, value, showkey=True): | ||||
super(Parameter, self).__init__() | super(Parameter, self).__init__() | ||||
if not showkey and not self.can_hide_key(name): | if not showkey and not self.can_hide_key(name): | ||||
raise ValueError("key {0!r} cannot be hidden".format(name)) | |||||
raise ValueError("key {!r} cannot be hidden".format(name)) | |||||
self._name = name | self._name = name | ||||
self._value = value | self._value = value | ||||
self._showkey = showkey | self._showkey = showkey | ||||
@@ -53,10 +53,10 @@ class HTMLEntity(Node): | |||||
def __unicode__(self): | def __unicode__(self): | ||||
if self.named: | if self.named: | ||||
return "&{0};".format(self.value) | |||||
return "&{};".format(self.value) | |||||
if self.hexadecimal: | if self.hexadecimal: | ||||
return "&#{0}{1};".format(self.hex_char, self.value) | |||||
return "&#{0};".format(self.value) | |||||
return "&#{}{};".format(self.hex_char, self.value) | |||||
return "&#{};".format(self.value) | |||||
def __strip__(self, **kwargs): | def __strip__(self, **kwargs): | ||||
if kwargs.get("normalize"): | if kwargs.get("normalize"): | ||||
@@ -35,7 +35,7 @@ class ParserError(Exception): | |||||
can happen. Its appearance indicates a bug. | can happen. Its appearance indicates a bug. | ||||
""" | """ | ||||
def __init__(self, extra): | def __init__(self, extra): | ||||
msg = "This is a bug and should be reported. Info: {0}.".format(extra) | |||||
msg = "This is a bug and should be reported. Info: {}.".format(extra) | |||||
super(ParserError, self).__init__(msg) | super(ParserError, self).__init__(msg) | ||||
@@ -44,7 +44,7 @@ class Token(dict): | |||||
args.append(key + "=" + repr(value[:97] + "...")) | args.append(key + "=" + repr(value[:97] + "...")) | ||||
else: | else: | ||||
args.append(key + "=" + repr(value)) | args.append(key + "=" + repr(value)) | ||||
return "{0}({1})".format(type(self).__name__, ", ".join(args)) | |||||
return "{}({})".format(type(self).__name__, ", ".join(args)) | |||||
def __eq__(self, other): | def __eq__(self, other): | ||||
return isinstance(other, type(self)) and dict.__eq__(self, other) | return isinstance(other, type(self)) and dict.__eq__(self, other) | ||||
@@ -109,7 +109,7 @@ class StringMixIn(object): | |||||
def __getattr__(self, attr): | def __getattr__(self, attr): | ||||
if not hasattr(str, attr): | if not hasattr(str, attr): | ||||
raise AttributeError("{0!r} object has no attribute {1!r}".format( | |||||
raise AttributeError("{!r} object has no attribute {!r}".format( | |||||
type(self).__name__, attr)) | type(self).__name__, attr)) | ||||
return getattr(self.__unicode__(), attr) | return getattr(self.__unicode__(), attr) | ||||
@@ -80,7 +80,7 @@ class MemoryTest(object): | |||||
raw = raw.encode("raw_unicode_escape") | raw = raw.encode("raw_unicode_escape") | ||||
data["input"] = raw.decode("unicode_escape") | data["input"] = raw.decode("unicode_escape") | ||||
number = str(counter).zfill(digits) | number = str(counter).zfill(digits) | ||||
fname = "test_{0}{1}_{2}".format(name, number, data["name"]) | |||||
fname = "test_{}{}_{}".format(name, number, data["name"]) | |||||
self._tests.append((fname, data["input"])) | self._tests.append((fname, data["input"])) | ||||
counter += 1 | counter += 1 | ||||
@@ -117,7 +117,7 @@ class MemoryTest(object): | |||||
tmpl = "{0}LEAKING{1}: {2:n} bytes, {3:.2%} inc ({4:n} bytes/loop)" | tmpl = "{0}LEAKING{1}: {2:n} bytes, {3:.2%} inc ({4:n} bytes/loop)" | ||||
sys.stdout.write(tmpl.format(Color.YELLOW, Color.RESET, d, p, bpt)) | sys.stdout.write(tmpl.format(Color.YELLOW, Color.RESET, d, p, bpt)) | ||||
else: | else: | ||||
sys.stdout.write("{0}OK{1}".format(Color.GREEN, Color.RESET)) | |||||
sys.stdout.write("{}OK{}".format(Color.GREEN, Color.RESET)) | |||||
def run(self): | def run(self): | ||||
"""Run the memory test suite.""" | """Run the memory test suite.""" | ||||
@@ -89,7 +89,7 @@ setup( | |||||
url = "https://github.com/earwig/mwparserfromhell", | url = "https://github.com/earwig/mwparserfromhell", | ||||
description = "MWParserFromHell is a parser for MediaWiki wikicode.", | description = "MWParserFromHell is a parser for MediaWiki wikicode.", | ||||
long_description = long_docs, | long_description = long_docs, | ||||
download_url = "https://github.com/earwig/mwparserfromhell/tarball/v{0}".format(__version__), | |||||
download_url = "https://github.com/earwig/mwparserfromhell/tarball/v{}".format(__version__), | |||||
keywords = "earwig mwparserfromhell wikipedia wiki mediawiki wikicode template parsing", | keywords = "earwig mwparserfromhell wikipedia wiki mediawiki wikicode template parsing", | ||||
license = "MIT License", | license = "MIT License", | ||||
classifiers = [ | classifiers = [ | ||||
@@ -118,7 +118,7 @@ class TokenizerTestCase(object): | |||||
if restrict and data["name"] != restrict: | if restrict and data["name"] != restrict: | ||||
continue | continue | ||||
fname = "test_{0}{1}_{2}".format(name, number, data["name"]) | |||||
fname = "test_{}{}_{}".format(name, number, data["name"]) | |||||
meth = cls._build_test_method(fname, data) | meth = cls._build_test_method(fname, data) | ||||
setattr(cls, fname, meth) | setattr(cls, fname, meth) | ||||