forked from github/pelican
Convert super() calls to py3 style
This commit is contained in:
parent
3cc430b418
commit
16968834ce
11 changed files with 38 additions and 56 deletions
|
|
@ -80,9 +80,7 @@ class FileStampDataCacher(FileDataCacher):
|
|||
and base path for filestamping operations
|
||||
"""
|
||||
|
||||
super(FileStampDataCacher, self).__init__(settings, cache_name,
|
||||
caching_policy,
|
||||
load_policy)
|
||||
super().__init__(settings, cache_name, caching_policy, load_policy)
|
||||
|
||||
method = self.settings['CHECK_MODIFIED_METHOD']
|
||||
if method == 'mtime':
|
||||
|
|
@ -104,7 +102,7 @@ class FileStampDataCacher(FileDataCacher):
|
|||
def cache_data(self, filename, data):
|
||||
"""Cache stamp and data for the given file"""
|
||||
stamp = self._get_file_stamp(filename)
|
||||
super(FileStampDataCacher, self).cache_data(filename, (stamp, data))
|
||||
super().cache_data(filename, (stamp, data))
|
||||
|
||||
def _get_file_stamp(self, filename):
|
||||
"""Check if the given file has been modified
|
||||
|
|
@ -132,8 +130,7 @@ class FileStampDataCacher(FileDataCacher):
|
|||
and current file stamp.
|
||||
"""
|
||||
|
||||
stamp, data = super(FileStampDataCacher, self).get_cached_data(
|
||||
filename, (None, default))
|
||||
stamp, data = super().get_cached_data(filename, (None, default))
|
||||
if stamp != self._get_file_stamp(filename):
|
||||
return default
|
||||
return data
|
||||
|
|
|
|||
|
|
@ -488,7 +488,7 @@ class Page(Content):
|
|||
|
||||
def _expand_settings(self, key):
|
||||
klass = 'draft_page' if self.status == 'draft' else None
|
||||
return super(Page, self)._expand_settings(key, klass)
|
||||
return super()._expand_settings(key, klass)
|
||||
|
||||
|
||||
class Article(Content):
|
||||
|
|
@ -498,7 +498,7 @@ class Article(Content):
|
|||
default_template = 'article'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Article, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# handle WITH_FUTURE_DATES (designate article to draft based on date)
|
||||
if not self.settings['WITH_FUTURE_DATES'] and hasattr(self, 'date'):
|
||||
|
|
@ -515,7 +515,7 @@ class Article(Content):
|
|||
|
||||
def _expand_settings(self, key):
|
||||
klass = 'draft' if self.status == 'draft' else 'article'
|
||||
return super(Article, self)._expand_settings(key, klass)
|
||||
return super()._expand_settings(key, klass)
|
||||
|
||||
|
||||
class Static(Content):
|
||||
|
|
@ -524,7 +524,7 @@ class Static(Content):
|
|||
default_template = None
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Static, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
self._output_location_referenced = False
|
||||
|
||||
@deprecated_attribute(old='filepath', new='source_path', since=(3, 2, 0))
|
||||
|
|
@ -543,13 +543,13 @@ class Static(Content):
|
|||
def url(self):
|
||||
# Note when url has been referenced, so we can avoid overriding it.
|
||||
self._output_location_referenced = True
|
||||
return super(Static, self).url
|
||||
return super().url
|
||||
|
||||
@property
|
||||
def save_as(self):
|
||||
# Note when save_as has been referenced, so we can avoid overriding it.
|
||||
self._output_location_referenced = True
|
||||
return super(Static, self).save_as
|
||||
return super().save_as
|
||||
|
||||
def attach_to(self, content):
|
||||
"""Override our output directory with that of the given content object.
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ class CachingGenerator(Generator, FileStampDataCacher):
|
|||
def _get_file_stamp(self, filename):
|
||||
'''Get filestamp for path relative to generator.path'''
|
||||
filename = os.path.join(self.path, filename)
|
||||
return super(CachingGenerator, self)._get_file_stamp(filename)
|
||||
return super()._get_file_stamp(filename)
|
||||
|
||||
|
||||
class _FileLoader(BaseLoader):
|
||||
|
|
@ -288,7 +288,7 @@ class ArticlesGenerator(CachingGenerator):
|
|||
self.authors = defaultdict(list)
|
||||
self.drafts = [] # only drafts in default language
|
||||
self.drafts_translations = []
|
||||
super(ArticlesGenerator, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
signals.article_generator_init.send(self)
|
||||
|
||||
def generate_feeds(self, writer):
|
||||
|
|
@ -699,7 +699,7 @@ class PagesGenerator(CachingGenerator):
|
|||
self.hidden_translations = []
|
||||
self.draft_pages = []
|
||||
self.draft_translations = []
|
||||
super(PagesGenerator, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
signals.page_generator_init.send(self)
|
||||
|
||||
def generate_context(self):
|
||||
|
|
@ -785,7 +785,7 @@ class StaticGenerator(Generator):
|
|||
to output"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(StaticGenerator, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fallback_to_symlinks = False
|
||||
signals.static_generator_init.send(self)
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ __all__ = [
|
|||
class BaseFormatter(logging.Formatter):
|
||||
def __init__(self, fmt=None, datefmt=None):
|
||||
FORMAT = '%(customlevelname)s %(message)s'
|
||||
super(BaseFormatter, self).__init__(fmt=FORMAT, datefmt=datefmt)
|
||||
super().__init__(fmt=FORMAT, datefmt=datefmt)
|
||||
|
||||
def format(self, record):
|
||||
customlevel = self._get_levelname(record.levelname)
|
||||
|
|
@ -23,11 +23,11 @@ class BaseFormatter(logging.Formatter):
|
|||
record.args = tuple(arg.replace('\n', '\n | ') if
|
||||
isinstance(arg, str) else
|
||||
arg for arg in record.args)
|
||||
return super(BaseFormatter, self).format(record)
|
||||
return super().format(record)
|
||||
|
||||
def formatException(self, ei):
|
||||
''' prefix traceback info for better representation '''
|
||||
s = super(BaseFormatter, self).formatException(ei)
|
||||
s = super().formatException(ei)
|
||||
# fancy format traceback
|
||||
s = '\n'.join(' | ' + line for line in s.splitlines())
|
||||
# separate the traceback from the preceding lines
|
||||
|
|
@ -137,7 +137,7 @@ class LimitLogger(logging.Logger):
|
|||
limit_filter = LimitFilter()
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(LimitLogger, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
self.enable_filter()
|
||||
|
||||
def disable_filter(self):
|
||||
|
|
@ -152,12 +152,12 @@ class FatalLogger(LimitLogger):
|
|||
errors_fatal = False
|
||||
|
||||
def warning(self, *args, **kwargs):
|
||||
super(FatalLogger, self).warning(*args, **kwargs)
|
||||
super().warning(*args, **kwargs)
|
||||
if FatalLogger.warnings_fatal:
|
||||
raise RuntimeError('Warning encountered')
|
||||
|
||||
def error(self, *args, **kwargs):
|
||||
super(FatalLogger, self).error(*args, **kwargs)
|
||||
super().error(*args, **kwargs)
|
||||
if FatalLogger.errors_fatal:
|
||||
raise RuntimeError('Error encountered')
|
||||
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ class BaseReader(object):
|
|||
class _FieldBodyTranslator(HTMLTranslator):
|
||||
|
||||
def __init__(self, document):
|
||||
HTMLTranslator.__init__(self, document)
|
||||
super().__init__(document)
|
||||
self.compact_p = None
|
||||
|
||||
def astext(self):
|
||||
|
|
@ -158,7 +158,7 @@ def render_node_to_html(document, node, field_body_translator_class):
|
|||
class PelicanHTMLWriter(Writer):
|
||||
|
||||
def __init__(self):
|
||||
Writer.__init__(self)
|
||||
super().__init__()
|
||||
self.translator_class = PelicanHTMLTranslator
|
||||
|
||||
|
||||
|
|
@ -202,7 +202,7 @@ class RstReader(BaseReader):
|
|||
field_body_translator_class = _FieldBodyTranslator
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(RstReader, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
lang_code = self.settings.get('DEFAULT_LANG', 'en')
|
||||
if get_docutils_lang(lang_code):
|
||||
|
|
@ -287,7 +287,7 @@ class MarkdownReader(BaseReader):
|
|||
file_extensions = ['md', 'markdown', 'mkd', 'mdown']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(MarkdownReader, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
settings = self.settings['MARKDOWN']
|
||||
settings.setdefault('extension_configs', {})
|
||||
settings.setdefault('extensions', [])
|
||||
|
|
@ -350,11 +350,7 @@ class HTMLReader(BaseReader):
|
|||
|
||||
class _HTMLParser(HTMLParser):
|
||||
def __init__(self, settings, filename):
|
||||
try:
|
||||
# Python 3.5+
|
||||
HTMLParser.__init__(self, convert_charrefs=False)
|
||||
except TypeError:
|
||||
HTMLParser.__init__(self)
|
||||
super().__init__(convert_charrefs=False)
|
||||
self.body = ''
|
||||
self.metadata = {}
|
||||
self.settings = settings
|
||||
|
|
@ -527,9 +523,7 @@ class Readers(FileStampDataCacher):
|
|||
self.settings['CONTENT_CACHING_LAYER'] == 'reader')
|
||||
caching_policy = cache_this_level and self.settings['CACHE_CONTENT']
|
||||
load_policy = cache_this_level and self.settings['LOAD_CONTENT_CACHE']
|
||||
super(Readers, self).__init__(settings, cache_name,
|
||||
caching_policy, load_policy,
|
||||
)
|
||||
super().__init__(settings, cache_name, caching_policy, load_policy)
|
||||
|
||||
@property
|
||||
def extensions(self):
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ class LogCountHandler(BufferingHandler):
|
|||
"""Capturing and counting logged messages."""
|
||||
|
||||
def __init__(self, capacity=1000):
|
||||
super(LogCountHandler, self).__init__(capacity)
|
||||
super().__init__(capacity)
|
||||
|
||||
def count_logs(self, msg=None, level=None):
|
||||
return len([
|
||||
|
|
@ -202,13 +202,13 @@ class LoggedTestCase(unittest.TestCase):
|
|||
"""A test case that captures log messages."""
|
||||
|
||||
def setUp(self):
|
||||
super(LoggedTestCase, self).setUp()
|
||||
super().setUp()
|
||||
self._logcount_handler = LogCountHandler()
|
||||
logging.getLogger().addHandler(self._logcount_handler)
|
||||
|
||||
def tearDown(self):
|
||||
logging.getLogger().removeHandler(self._logcount_handler)
|
||||
super(LoggedTestCase, self).tearDown()
|
||||
super().tearDown()
|
||||
|
||||
def assertLogCountEqual(self, count=None, msg=None, **kwargs):
|
||||
actual = self._logcount_handler.count_logs(msg=msg, **kwargs)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ TEST_SUMMARY = generate_lorem_ipsum(n=1, html=False)
|
|||
class TestPage(LoggedTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPage, self).setUp()
|
||||
super().setUp()
|
||||
self.old_locale = locale.setlocale(locale.LC_ALL)
|
||||
locale.setlocale(locale.LC_ALL, str('C'))
|
||||
self.page_kwargs = {
|
||||
|
|
@ -657,7 +657,7 @@ class TestArticle(TestPage):
|
|||
class TestStatic(LoggedTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestStatic, self).setUp()
|
||||
super().setUp()
|
||||
self.settings = get_settings(
|
||||
STATIC_SAVE_AS='{path}',
|
||||
STATIC_URL='{path}',
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ TEST_SUMMARY = generate_lorem_ipsum(n=1, html=False)
|
|||
|
||||
class TestPage(unittest.TestCase):
|
||||
def setUp(self):
|
||||
super(TestPage, self).setUp()
|
||||
super().setUp()
|
||||
self.old_locale = locale.setlocale(locale.LC_ALL)
|
||||
locale.setlocale(locale.LC_ALL, str('C'))
|
||||
self.page_kwargs = {
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class TestPelican(LoggedTestCase):
|
|||
# to run pelican in different situations and see how it behaves
|
||||
|
||||
def setUp(self):
|
||||
super(TestPelican, self).setUp()
|
||||
super().setUp()
|
||||
self.temp_path = mkdtemp(prefix='pelicantests.')
|
||||
self.temp_cache = mkdtemp(prefix='pelican_cache.')
|
||||
self.maxDiff = None
|
||||
|
|
@ -53,7 +53,7 @@ class TestPelican(LoggedTestCase):
|
|||
rmtree(self.temp_path)
|
||||
rmtree(self.temp_cache)
|
||||
locale.setlocale(locale.LC_ALL, self.old_locale)
|
||||
super(TestPelican, self).tearDown()
|
||||
super().tearDown()
|
||||
|
||||
def assertDirsEqual(self, left_path, right_path):
|
||||
out, err = subprocess.Popen(
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ class Category(URLWrapper):
|
|||
|
||||
class Tag(URLWrapper):
|
||||
def __init__(self, name, *args, **kwargs):
|
||||
super(Tag, self).__init__(name.strip(), *args, **kwargs)
|
||||
super().__init__(name.strip(), *args, **kwargs)
|
||||
|
||||
|
||||
class Author(URLWrapper):
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ class SafeDatetime(datetime.datetime):
|
|||
if safe:
|
||||
return strftime(self, fmt)
|
||||
else:
|
||||
return super(SafeDatetime, self).strftime(fmt)
|
||||
return super().strftime(fmt)
|
||||
|
||||
|
||||
class DateFormatter(object):
|
||||
|
|
@ -407,18 +407,11 @@ class _HTMLWordTruncator(HTMLParser):
|
|||
class TruncationCompleted(Exception):
|
||||
|
||||
def __init__(self, truncate_at):
|
||||
super(_HTMLWordTruncator.TruncationCompleted, self).__init__(
|
||||
truncate_at)
|
||||
super().__init__(truncate_at)
|
||||
self.truncate_at = truncate_at
|
||||
|
||||
def __init__(self, max_words):
|
||||
# In Python 2, HTMLParser is not a new-style class,
|
||||
# hence super() cannot be used.
|
||||
try:
|
||||
HTMLParser.__init__(self, convert_charrefs=False)
|
||||
except TypeError:
|
||||
# pre Python 3.3
|
||||
HTMLParser.__init__(self)
|
||||
super().__init__(convert_charrefs=False)
|
||||
|
||||
self.max_words = max_words
|
||||
self.words_found = 0
|
||||
|
|
@ -428,9 +421,7 @@ class _HTMLWordTruncator(HTMLParser):
|
|||
|
||||
def feed(self, *args, **kwargs):
|
||||
try:
|
||||
# With Python 2, super() cannot be used.
|
||||
# See the comment for __init__().
|
||||
HTMLParser.feed(self, *args, **kwargs)
|
||||
super().feed(*args, **kwargs)
|
||||
except self.TruncationCompleted as exc:
|
||||
self.truncate_at = exc.truncate_at
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue