gurudesh/pytracebugs huggingface dataset:
# Buggy code
def category_path_to_category_name(self, category_path):
    """Translate a category path to a category name."""
    if self.config["CATEGORY_ALLOW_HIERARCHIES"]:
        return utils.join_hierarchical_category_path(category_path)
    else:
        return "".join(category_path)


# Traceback (KeyError)
########################################
TaskError - taskid:render_galleries:output/galleries/index.html
PythonAction Error
Traceback (most recent call last):
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/doit/action.py", line 360, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/kwpolska/git/nikola/nikola/plugins/task/galleries.py", line 466, in render_gallery_index
self.site.render_template(template_name, output_name, context)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 607, in render_template
template_name, None, local_context)
File "/home/kwpolska/git/nikola/nikola/plugins/template/mako.py", line 88, in render_template
data = template.render_unicode(**context)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/template.py", line 452, in render_unicode
as_unicode=True)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 807, in _render
**_kwargs_for_callable(callable_, data))
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 839, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 865, in _exec_template
callable_(context, *args, **kwargs)
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base.tmpl.py", line 91, in render_body
__M_writer(unicode(base.meta_translations()))
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base_helper.tmpl.py", line 274, in render_meta_translations
__M_writer(unicode(_link(permalink, None, langname)))
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 765, in link
return self.path(*args, is_link=True)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 729, in path
path = self.path_handlers[kind](name, lang)
KeyError: u'/galleries/galleries/index.html'

# Fixed code
def category_path_to_category_name(self, category_path):
    """Translate a category path to a category name."""
    if self.config["CATEGORY_ALLOW_HIERARCHIES"]:
        return hierarchy_utils.join_hierarchical_category_path(category_path)
    else:
        return "".join(category_path)
# Buggy code
def set_site(self, site):
    """Set Nikola site."""
    self.show_list_as_index = site.config["AUTHOR_PAGES_ARE_INDEXES"]
    self.template_for_single_list = (
        "authorindex.tmpl" if self.show_list_as_index else "author.tmpl"
    )
    return super(ClassifyAuthors, self).set_site(site)


# Traceback (KeyError)
########################################
TaskError - taskid:render_galleries:output/galleries/index.html
PythonAction Error
Traceback (most recent call last):
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/doit/action.py", line 360, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/kwpolska/git/nikola/nikola/plugins/task/galleries.py", line 466, in render_gallery_index
self.site.render_template(template_name, output_name, context)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 607, in render_template
template_name, None, local_context)
File "/home/kwpolska/git/nikola/nikola/plugins/template/mako.py", line 88, in render_template
data = template.render_unicode(**context)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/template.py", line 452, in render_unicode
as_unicode=True)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 807, in _render
**_kwargs_for_callable(callable_, data))
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 839, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 865, in _exec_template
callable_(context, *args, **kwargs)
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base.tmpl.py", line 91, in render_body
__M_writer(unicode(base.meta_translations()))
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base_helper.tmpl.py", line 274, in render_meta_translations
__M_writer(unicode(_link(permalink, None, langname)))
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 765, in link
return self.path(*args, is_link=True)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 729, in path
path = self.path_handlers[kind](name, lang)
KeyError: u'/galleries/galleries/index.html'

# Fixed code
def set_site(self, site):
    """Set Nikola site."""
    super(ClassifyAuthors, self).set_site(site)
    self.show_list_as_index = site.config["AUTHOR_PAGES_ARE_INDEXES"]
    self.template_for_single_list = (
        "authorindex.tmpl" if self.show_list_as_index else "author.tmpl"
    )
    self.translation_manager = utils.ClassificationTranslationManager()
# Buggy code
def classify(self, post, lang):
    """Classify the given post for the given language."""
    return [post.author()]


# Traceback (KeyError)
########################################
TaskError - taskid:render_galleries:output/galleries/index.html
PythonAction Error
Traceback (most recent call last):
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/doit/action.py", line 360, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/kwpolska/git/nikola/nikola/plugins/task/galleries.py", line 466, in render_gallery_index
self.site.render_template(template_name, output_name, context)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 607, in render_template
template_name, None, local_context)
File "/home/kwpolska/git/nikola/nikola/plugins/template/mako.py", line 88, in render_template
data = template.render_unicode(**context)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/template.py", line 452, in render_unicode
as_unicode=True)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 807, in _render
**_kwargs_for_callable(callable_, data))
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 839, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 865, in _exec_template
callable_(context, *args, **kwargs)
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base.tmpl.py", line 91, in render_body
__M_writer(unicode(base.meta_translations()))
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base_helper.tmpl.py", line 274, in render_meta_translations
__M_writer(unicode(_link(permalink, None, langname)))
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 765, in link
return self.path(*args, is_link=True)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 729, in path
path = self.path_handlers[kind](name, lang)
KeyError: u'/galleries/galleries/index.html'

# Fixed code
def classify(self, post, lang):
    """Classify the given post for the given language."""
    return [post.author(lang=lang)]
# Buggy code
def get_classification_friendly_name(self, author, lang, only_last_component=False):
    """Extract a friendly name from the classification."""
    return author


# Traceback (KeyError)
########################################
TaskError - taskid:render_galleries:output/galleries/index.html
PythonAction Error
Traceback (most recent call last):
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/doit/action.py", line 360, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/kwpolska/git/nikola/nikola/plugins/task/galleries.py", line 466, in render_gallery_index
self.site.render_template(template_name, output_name, context)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 607, in render_template
template_name, None, local_context)
File "/home/kwpolska/git/nikola/nikola/plugins/template/mako.py", line 88, in render_template
data = template.render_unicode(**context)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/template.py", line 452, in render_unicode
as_unicode=True)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 807, in _render
**_kwargs_for_callable(callable_, data))
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 839, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 865, in _exec_template
callable_(context, *args, **kwargs)
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base.tmpl.py", line 91, in render_body
__M_writer(unicode(base.meta_translations()))
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base_helper.tmpl.py", line 274, in render_meta_translations
__M_writer(unicode(_link(permalink, None, langname)))
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 765, in link
return self.path(*args, is_link=True)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 729, in path
path = self.path_handlers[kind](name, lang)
KeyError: u'/galleries/galleries/index.html'

# Fixed code
def get_classification_friendly_name(
    self, classification, lang, only_last_component=False
):
    """Extract a friendly name from the classification."""
    return classification
# Buggy code
def get_path(self, author, lang, dest_type="page"):
    """Return a path for the given classification."""
    if self.site.config["SLUG_AUTHOR_PATH"]:
        slug = utils.slugify(author, lang)
    else:
        slug = author
    return [self.site.config["AUTHOR_PATH"](lang), slug], "auto"


# Traceback (KeyError)
########################################
TaskError - taskid:render_galleries:output/galleries/index.html
PythonAction Error
Traceback (most recent call last):
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/doit/action.py", line 360, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/kwpolska/git/nikola/nikola/plugins/task/galleries.py", line 466, in render_gallery_index
self.site.render_template(template_name, output_name, context)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 607, in render_template
template_name, None, local_context)
File "/home/kwpolska/git/nikola/nikola/plugins/template/mako.py", line 88, in render_template
data = template.render_unicode(**context)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/template.py", line 452, in render_unicode
as_unicode=True)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 807, in _render
**_kwargs_for_callable(callable_, data))
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 839, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 865, in _exec_template
callable_(context, *args, **kwargs)
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base.tmpl.py", line 91, in render_body
__M_writer(unicode(base.meta_translations()))
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base_helper.tmpl.py", line 274, in render_meta_translations
__M_writer(unicode(_link(permalink, None, langname)))
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 765, in link
return self.path(*args, is_link=True)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 729, in path
path = self.path_handlers[kind](name, lang)
KeyError: u'/galleries/galleries/index.html'

# Fixed code
def get_path(self, classification, lang, dest_type="page"):
    """Return a path for the given classification."""
    if self.site.config["SLUG_AUTHOR_PATH"]:
        slug = utils.slugify(classification, lang)
    else:
        slug = classification
    return [self.site.config["AUTHOR_PATH"](lang), slug], "auto"
# Buggy code
def set_site(self, site):
    """Set site, which is a Nikola instance."""
    super(ClassifyCategories, self).set_site(site)
    self.show_list_as_index = self.site.config["CATEGORY_PAGES_ARE_INDEXES"]
    self.template_for_single_list = (
        "tagindex.tmpl" if self.show_list_as_index else "tag.tmpl"
    )


# Traceback (KeyError)
########################################
TaskError - taskid:render_galleries:output/galleries/index.html
PythonAction Error
Traceback (most recent call last):
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/doit/action.py", line 360, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/kwpolska/git/nikola/nikola/plugins/task/galleries.py", line 466, in render_gallery_index
self.site.render_template(template_name, output_name, context)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 607, in render_template
template_name, None, local_context)
File "/home/kwpolska/git/nikola/nikola/plugins/template/mako.py", line 88, in render_template
data = template.render_unicode(**context)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/template.py", line 452, in render_unicode
as_unicode=True)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 807, in _render
**_kwargs_for_callable(callable_, data))
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 839, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 865, in _exec_template
callable_(context, *args, **kwargs)
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base.tmpl.py", line 91, in render_body
__M_writer(unicode(base.meta_translations()))
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base_helper.tmpl.py", line 274, in render_meta_translations
__M_writer(unicode(_link(permalink, None, langname)))
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 765, in link
return self.path(*args, is_link=True)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 729, in path
path = self.path_handlers[kind](name, lang)
KeyError: u'/galleries/galleries/index.html'

# Fixed code
def set_site(self, site):
    """Set site, which is a Nikola instance."""
    super(ClassifyCategories, self).set_site(site)
    self.show_list_as_index = self.site.config["CATEGORY_PAGES_ARE_INDEXES"]
    self.template_for_single_list = (
        "tagindex.tmpl" if self.show_list_as_index else "tag.tmpl"
    )
    self.translation_manager = utils.ClassificationTranslationManager()
# Buggy code
def extract_hierarchy(self, classification):
    """Given a classification, return a list of parts in the hierarchy."""
    return utils.parse_escaped_hierarchical_category_name(classification)


# Traceback (KeyError)
########################################
TaskError - taskid:render_galleries:output/galleries/index.html
PythonAction Error
Traceback (most recent call last):
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/doit/action.py", line 360, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/kwpolska/git/nikola/nikola/plugins/task/galleries.py", line 466, in render_gallery_index
self.site.render_template(template_name, output_name, context)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 607, in render_template
template_name, None, local_context)
File "/home/kwpolska/git/nikola/nikola/plugins/template/mako.py", line 88, in render_template
data = template.render_unicode(**context)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/template.py", line 452, in render_unicode
as_unicode=True)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 807, in _render
**_kwargs_for_callable(callable_, data))
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 839, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 865, in _exec_template
callable_(context, *args, **kwargs)
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base.tmpl.py", line 91, in render_body
__M_writer(unicode(base.meta_translations()))
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base_helper.tmpl.py", line 274, in render_meta_translations
__M_writer(unicode(_link(permalink, None, langname)))
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 765, in link
return self.path(*args, is_link=True)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 729, in path
path = self.path_handlers[kind](name, lang)
KeyError: u'/galleries/galleries/index.html'

# Fixed code
def extract_hierarchy(self, classification):
    """Given a classification, return a list of parts in the hierarchy."""
    return hierarchy_utils.parse_escaped_hierarchical_category_name(classification)
# Buggy code
def recombine_classification_from_hierarchy(self, hierarchy):
    """Given a list of parts in the hierarchy, return the classification string."""
    return utils.join_hierarchical_category_path(hierarchy)


# Traceback (KeyError)
########################################
TaskError - taskid:render_galleries:output/galleries/index.html
PythonAction Error
Traceback (most recent call last):
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/doit/action.py", line 360, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/kwpolska/git/nikola/nikola/plugins/task/galleries.py", line 466, in render_gallery_index
self.site.render_template(template_name, output_name, context)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 607, in render_template
template_name, None, local_context)
File "/home/kwpolska/git/nikola/nikola/plugins/template/mako.py", line 88, in render_template
data = template.render_unicode(**context)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/template.py", line 452, in render_unicode
as_unicode=True)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 807, in _render
**_kwargs_for_callable(callable_, data))
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 839, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 865, in _exec_template
callable_(context, *args, **kwargs)
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base.tmpl.py", line 91, in render_body
__M_writer(unicode(base.meta_translations()))
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base_helper.tmpl.py", line 274, in render_meta_translations
__M_writer(unicode(_link(permalink, None, langname)))
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 765, in link
return self.path(*args, is_link=True)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 729, in path
path = self.path_handlers[kind](name, lang)
KeyError: u'/galleries/galleries/index.html'

# Fixed code
def recombine_classification_from_hierarchy(self, hierarchy):
    """Given a list of parts in the hierarchy, return the classification string."""
    return hierarchy_utils.join_hierarchical_category_path(hierarchy)
# Buggy code
def set_site(self, site):
    """Set Nikola site."""
    self.show_list_as_index = site.config["POSTS_SECTIONS_ARE_INDEXES"]
    self.template_for_single_list = (
        "sectionindex.tmpl" if self.show_list_as_index else "list.tmpl"
    )
    self.enable_for_lang = {}
    return super(ClassifySections, self).set_site(site)


# Traceback (KeyError)
########################################
TaskError - taskid:render_galleries:output/galleries/index.html
PythonAction Error
Traceback (most recent call last):
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/doit/action.py", line 360, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/kwpolska/git/nikola/nikola/plugins/task/galleries.py", line 466, in render_gallery_index
self.site.render_template(template_name, output_name, context)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 607, in render_template
template_name, None, local_context)
File "/home/kwpolska/git/nikola/nikola/plugins/template/mako.py", line 88, in render_template
data = template.render_unicode(**context)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/template.py", line 452, in render_unicode
as_unicode=True)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 807, in _render
**_kwargs_for_callable(callable_, data))
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 839, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 865, in _exec_template
callable_(context, *args, **kwargs)
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base.tmpl.py", line 91, in render_body
__M_writer(unicode(base.meta_translations()))
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base_helper.tmpl.py", line 274, in render_meta_translations
__M_writer(unicode(_link(permalink, None, langname)))
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 765, in link
return self.path(*args, is_link=True)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 729, in path
path = self.path_handlers[kind](name, lang)
KeyError: u'/galleries/galleries/index.html'

# Fixed code
def set_site(self, site):
    """Set Nikola site."""
    super(ClassifySections, self).set_site(site)
    self.show_list_as_index = site.config["POSTS_SECTIONS_ARE_INDEXES"]
    self.template_for_single_list = (
        "sectionindex.tmpl" if self.show_list_as_index else "list.tmpl"
    )
    self.enable_for_lang = {}
    self.translation_manager = utils.ClassificationTranslationManager()
# Buggy code
def set_site(self, site):
    """Set site, which is a Nikola instance."""
    super(ClassifyTags, self).set_site(site)
    self.show_list_as_index = self.site.config["TAG_PAGES_ARE_INDEXES"]
    self.template_for_single_list = (
        "tagindex.tmpl" if self.show_list_as_index else "tag.tmpl"
    )
    self.minimum_post_count_per_classification_in_overview = self.site.config[
        "TAGLIST_MINIMUM_POSTS"
    ]


# Traceback (KeyError)
########################################
TaskError - taskid:render_galleries:output/galleries/index.html
PythonAction Error
Traceback (most recent call last):
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/doit/action.py", line 360, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/kwpolska/git/nikola/nikola/plugins/task/galleries.py", line 466, in render_gallery_index
self.site.render_template(template_name, output_name, context)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 607, in render_template
template_name, None, local_context)
File "/home/kwpolska/git/nikola/nikola/plugins/template/mako.py", line 88, in render_template
data = template.render_unicode(**context)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/template.py", line 452, in render_unicode
as_unicode=True)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 807, in _render
**_kwargs_for_callable(callable_, data))
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 839, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 865, in _exec_template
callable_(context, *args, **kwargs)
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base.tmpl.py", line 91, in render_body
__M_writer(unicode(base.meta_translations()))
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base_helper.tmpl.py", line 274, in render_meta_translations
__M_writer(unicode(_link(permalink, None, langname)))
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 765, in link
return self.path(*args, is_link=True)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 729, in path
path = self.path_handlers[kind](name, lang)
KeyError: u'/galleries/galleries/index.html'

# Fixed code
def set_site(self, site):
    """Set site, which is a Nikola instance."""
    super(ClassifyTags, self).set_site(site)
    self.show_list_as_index = self.site.config["TAG_PAGES_ARE_INDEXES"]
    self.template_for_single_list = (
        "tagindex.tmpl" if self.show_list_as_index else "tag.tmpl"
    )
    self.minimum_post_count_per_classification_in_overview = self.site.config[
        "TAGLIST_MINIMUM_POSTS"
    ]
    self.translation_manager = utils.ClassificationTranslationManager()
# Buggy code
def __init__(self, name, parent=None):
    """Initialize node."""
    self.name = name
    self.parent = parent
    self.children = []


# Traceback (KeyError)
########################################
TaskError - taskid:render_galleries:output/galleries/index.html
PythonAction Error
Traceback (most recent call last):
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/doit/action.py", line 360, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/kwpolska/git/nikola/nikola/plugins/task/galleries.py", line 466, in render_gallery_index
self.site.render_template(template_name, output_name, context)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 607, in render_template
template_name, None, local_context)
File "/home/kwpolska/git/nikola/nikola/plugins/template/mako.py", line 88, in render_template
data = template.render_unicode(**context)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/template.py", line 452, in render_unicode
as_unicode=True)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 807, in _render
**_kwargs_for_callable(callable_, data))
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 839, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 865, in _exec_template
callable_(context, *args, **kwargs)
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base.tmpl.py", line 91, in render_body
__M_writer(unicode(base.meta_translations()))
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base_helper.tmpl.py", line 274, in render_meta_translations
__M_writer(unicode(_link(permalink, None, langname)))
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 765, in link
return self.path(*args, is_link=True)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 729, in path
path = self.path_handlers[kind](name, lang)
KeyError: u'/galleries/galleries/index.html'

# Fixed code
def __init__(self):
    self._data = defaultdict(dict)
# Buggy code
def __str__(self):
    """Stringify node (return name)."""
    return self.name


# Traceback (KeyError)
########################################
TaskError - taskid:render_galleries:output/galleries/index.html
PythonAction Error
Traceback (most recent call last):
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/doit/action.py", line 360, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/kwpolska/git/nikola/nikola/plugins/task/galleries.py", line 466, in render_gallery_index
self.site.render_template(template_name, output_name, context)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 607, in render_template
template_name, None, local_context)
File "/home/kwpolska/git/nikola/nikola/plugins/template/mako.py", line 88, in render_template
data = template.render_unicode(**context)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/template.py", line 452, in render_unicode
as_unicode=True)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 807, in _render
**_kwargs_for_callable(callable_, data))
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 839, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 865, in _exec_template
callable_(context, *args, **kwargs)
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base.tmpl.py", line 91, in render_body
__M_writer(unicode(base.meta_translations()))
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base_helper.tmpl.py", line 274, in render_meta_translations
__M_writer(unicode(_link(permalink, None, langname)))
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 765, in link
return self.path(*args, is_link=True)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 729, in path
path = self.path_handlers[kind](name, lang)
KeyError: u'/galleries/galleries/index.html'

# Fixed code
def __str__(self):
    """Stringify the exception."""
    return "cannot find language {0}".format(self.lang)
# Buggy code
def __repr__(self):
    """Return programmer-friendly node representation."""
    return "<TreeNode {0}>".format(self._repr_partial())


# Traceback (KeyError)
########################################
TaskError - taskid:render_galleries:output/galleries/index.html
PythonAction Error
Traceback (most recent call last):
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/doit/action.py", line 360, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/kwpolska/git/nikola/nikola/plugins/task/galleries.py", line 466, in render_gallery_index
self.site.render_template(template_name, output_name, context)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 607, in render_template
template_name, None, local_context)
File "/home/kwpolska/git/nikola/nikola/plugins/template/mako.py", line 88, in render_template
data = template.render_unicode(**context)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/template.py", line 452, in render_unicode
as_unicode=True)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 807, in _render
**_kwargs_for_callable(callable_, data))
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 839, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 865, in _exec_template
callable_(context, *args, **kwargs)
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base.tmpl.py", line 91, in render_body
__M_writer(unicode(base.meta_translations()))
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base_helper.tmpl.py", line 274, in render_meta_translations
__M_writer(unicode(_link(permalink, None, langname)))
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 765, in link
return self.path(*args, is_link=True)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 729, in path
path = self.path_handlers[kind](name, lang)
KeyError: u'/galleries/galleries/index.html'

# Fixed code
def __repr__(self):
    """Return useful and verbose help."""
    return """\
<Nikola Commands>

    Sample usage:
    >>> commands.check('-l')

    Or, if you know the internal argument names:
    >>> commands.check(list=True)

Available commands: {0}.""".format(", ".join(self._cmdnames))
# Buggy code
def generate(input_list, indent_levels_so_far):
    for index, element in enumerate(input_list):
        # add to destination
        elements.append(element)
        # compute and set indent levels
        indent_levels = indent_levels_so_far + [(index, len(input_list))]
        element.indent_levels = indent_levels
        # add children
        children = element.get_children()
        element.children_count = len(children)
        generate(children, indent_levels)


# Traceback (KeyError)
########################################
TaskError - taskid:render_galleries:output/galleries/index.html
PythonAction Error
Traceback (most recent call last):
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/doit/action.py", line 360, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/kwpolska/git/nikola/nikola/plugins/task/galleries.py", line 466, in render_gallery_index
self.site.render_template(template_name, output_name, context)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 607, in render_template
template_name, None, local_context)
File "/home/kwpolska/git/nikola/nikola/plugins/template/mako.py", line 88, in render_template
data = template.render_unicode(**context)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/template.py", line 452, in render_unicode
as_unicode=True)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 807, in _render
**_kwargs_for_callable(callable_, data))
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 839, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 865, in _exec_template
callable_(context, *args, **kwargs)
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base.tmpl.py", line 91, in render_body
__M_writer(unicode(base.meta_translations()))
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base_helper.tmpl.py", line 274, in render_meta_translations
__M_writer(unicode(_link(permalink, None, langname)))
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 765, in link
return self.path(*args, is_link=True)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 729, in path
path = self.path_handlers[kind](name, lang)
KeyError: u'/galleries/galleries/index.html'

# Fixed code
def generate(self):
    """Generate items."""
    for c, inp, site, args, kwargs in self._items:
        if c:
            if site:
                kwargs["site"] = self.site
                kwargs["context"] = self.context
            yield inp(*args, **kwargs)
        else:
            yield inp
# Buggy code
def _compile_string(self, nb_json):
    """Export notebooks as HTML strings."""
    if flag is None:
        req_missing(["ipython[notebook]>=2.0.0"], "build this site (compile ipynb)")
    c = Config(self.site.config["IPYNB_CONFIG"])
    c.update(get_default_jupyter_config())
    exportHtml = HTMLExporter(config=c)
    body, _ = exportHtml.from_notebook_node(nb_json)
    return body


# Traceback (AttributeError)
[2017-04-23T16:38:22Z] ERROR: yapsy: Unable to import plugin: /usr/lib/python3.5/site-packages/nikola/plugins/compile/ipynb
Traceback (most recent call last):
File "/usr/lib/python3.5/site-packages/yapsy/PluginManager.py", line 488, in loadPlugins
candidate_module = imp.load_module(plugin_module_name,plugin_file,candidate_filepath+".py",("py","r",imp.PY_SOURCE))
File "/usr/lib64/python3.5/imp.py", line 234, in load_module
return load_source(name, filename, file)
File "/usr/lib64/python3.5/imp.py", line 172, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 693, in _load
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 697, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/usr/lib/python3.5/site-packages/nikola/plugins/compile/ipynb.py", line 36, in <module>
from nbconvert.exporters import HTMLExporter
File "/usr/lib/python3.5/site-packages/nbconvert/__init__.py", line 4, in <module>
from .exporters import *
File "/usr/lib/python3.5/site-packages/nbconvert/exporters/__init__.py", line 1, in <module>
from .base import (export, get_exporter,
File "/usr/lib/python3.5/site-packages/nbconvert/exporters/base.py", line 16, in <module>
from .exporter import Exporter
File "/usr/lib/python3.5/site-packages/nbconvert/exporters/exporter.py", line 47, in <module>
class Exporter(LoggingConfigurable):
File "/usr/lib/python3.5/site-packages/nbconvert/exporters/exporter.py", line 55, in Exporter
help="Extension of the file that should be written to disk"
AttributeError: 'FilenameExtension' object has no attribute 'tag'
Nikola v7.8.4

# Fixed code
def _compile_string(self, nb_json):
    """Export notebooks as HTML strings."""
    self._req_missing_ipynb()
    c = Config(self.site.config["IPYNB_CONFIG"])
    c.update(get_default_jupyter_config())
    exportHtml = HTMLExporter(config=c)
    body, _ = exportHtml.from_notebook_node(nb_json)
    return body
# Buggy code
def read_metadata(
    self, post, file_metadata_regexp=None, unslugify_titles=False, lang=None
):
    """Read metadata directly from ipynb file.

    As ipynb file support arbitrary metadata as json, the metadata used by Nikola
    will be assume to be in the 'nikola' subfield.
    """
    if flag is None:
        req_missing(["ipython[notebook]>=2.0.0"], "build this site (compile ipynb)")
    source = post.source_path
    with io.open(source, "r", encoding="utf8") as in_file:
        nb_json = nbformat.read(in_file, current_nbformat)
    # Metadata might not exist in two-file posts or in hand-crafted
    # .ipynb files.
    return nb_json.get("metadata", {}).get("nikola", {})


# Traceback (AttributeError)
[2017-04-23T16:38:22Z] ERROR: yapsy: Unable to import plugin: /usr/lib/python3.5/site-packages/nikola/plugins/compile/ipynb
Traceback (most recent call last):
File "/usr/lib/python3.5/site-packages/yapsy/PluginManager.py", line 488, in loadPlugins
candidate_module = imp.load_module(plugin_module_name,plugin_file,candidate_filepath+".py",("py","r",imp.PY_SOURCE))
File "/usr/lib64/python3.5/imp.py", line 234, in load_module
return load_source(name, filename, file)
File "/usr/lib64/python3.5/imp.py", line 172, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 693, in _load
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 697, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/usr/lib/python3.5/site-packages/nikola/plugins/compile/ipynb.py", line 36, in <module>
from nbconvert.exporters import HTMLExporter
File "/usr/lib/python3.5/site-packages/nbconvert/__init__.py", line 4, in <module>
from .exporters import *
File "/usr/lib/python3.5/site-packages/nbconvert/exporters/__init__.py", line 1, in <module>
from .base import (export, get_exporter,
File "/usr/lib/python3.5/site-packages/nbconvert/exporters/base.py", line 16, in <module>
from .exporter import Exporter
File "/usr/lib/python3.5/site-packages/nbconvert/exporters/exporter.py", line 47, in <module>
class Exporter(LoggingConfigurable):
File "/usr/lib/python3.5/site-packages/nbconvert/exporters/exporter.py", line 55, in Exporter
help="Extension of the file that should be written to disk"
AttributeError: 'FilenameExtension' object has no attribute 'tag'
Nikola v7.8.4

# Fixed code
def read_metadata(
    self, post, file_metadata_regexp=None, unslugify_titles=False, lang=None
):
    """Read metadata directly from ipynb file.

    As ipynb file support arbitrary metadata as json, the metadata used by Nikola
    will be assume to be in the 'nikola' subfield.
    """
    self._req_missing_ipynb()
    source = post.source_path
    with io.open(source, "r", encoding="utf8") as in_file:
        nb_json = nbformat.read(in_file, current_nbformat)
    # Metadata might not exist in two-file posts or in hand-crafted
    # .ipynb files.
    return nb_json.get("metadata", {}).get("nikola", {})
# Buggy code
def classify(self, post, lang):
    """Classify the given post for the given language."""
    destpath = post.destination_path(lang, sep="/")
    index_len = len(self.site.config["INDEX_FILE"])
    if destpath[-(1 + index_len) :] == "/" + self.site.config["INDEX_FILE"]:
        destpath = destpath[: -(1 + index_len)]
    i = destpath.rfind("/")
    return destpath[:i] if i >= 0 else ""


# Traceback (KeyError)
$ nikola build
Traceback (most recent call last):
File "/usr/local/bin/nikola", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.5/dist-packages/nikola/__main__.py", line 171, in main
_ = DN.run(oargs)
File "/usr/local/lib/python3.5/dist-packages/nikola/__main__.py", line 339, in run
self.nikola.init_plugins()
File "/usr/local/lib/python3.5/dist-packages/nikola/nikola.py", line 1077, in init_plugins
self._activate_plugins_of_category("SignalHandler")
File "/usr/local/lib/python3.5/dist-packages/nikola/nikola.py", line 1233, in _activate_plugins_of_category
plugin_info.plugin_object.set_site(self)
File "/usr/local/lib/python3.5/dist-packages/nikola/plugins/misc/taxonomies_classifier.py", line 328, in set_site
self._register_path_handlers(taxonomy)
File "/usr/local/lib/python3.5/dist-packages/nikola/plugins/misc/taxonomies_classifier.py", line 316, in _register_path_handlers
doc = taxonomy.path_handler_docstrings[name]
KeyError: 'page_index_folder_index'

# Fixed code
def classify(self, post, lang):
    """Classify the given post for the given language."""
    destpath = post.destination_path(lang, sep="/")
    index_len = len(self.site.config["INDEX_FILE"])
    if destpath[-(1 + index_len) :] == "/" + self.site.config["INDEX_FILE"]:
        destpath = destpath[: -(1 + index_len)]
    i = destpath.rfind("/")
    return [destpath[:i] if i >= 0 else ""]
# Buggy code
def provide_context_and_uptodate(self, dirname, lang, node=None):
    """Provide data for the context and the uptodate list for the list of the given classifiation."""
    kw = {
        "translations": self.site.config["TRANSLATIONS"],
        "filters": self.site.config["FILTERS"],
    }
    context = {
        "title": self.site.config["BLOG_TITLE"](lang),
        "pagekind": ["list", "front_page"] if dirname == "" else ["list"],
    }
    kw.update(context)
    return context, kw


# Traceback (KeyError)
$ nikola build
Traceback (most recent call last):
File "/usr/local/bin/nikola", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.5/dist-packages/nikola/__main__.py", line 171, in main
_ = DN.run(oargs)
File "/usr/local/lib/python3.5/dist-packages/nikola/__main__.py", line 339, in run
self.nikola.init_plugins()
File "/usr/local/lib/python3.5/dist-packages/nikola/nikola.py", line 1077, in init_plugins
self._activate_plugins_of_category("SignalHandler")
File "/usr/local/lib/python3.5/dist-packages/nikola/nikola.py", line 1233, in _activate_plugins_of_category
plugin_info.plugin_object.set_site(self)
File "/usr/local/lib/python3.5/dist-packages/nikola/plugins/misc/taxonomies_classifier.py", line 328, in set_site
self._register_path_handlers(taxonomy)
File "/usr/local/lib/python3.5/dist-packages/nikola/plugins/misc/taxonomies_classifier.py", line 316, in _register_path_handlers
doc = taxonomy.path_handler_docstrings[name]
KeyError: 'page_index_folder_index'

# Fixed code
def provide_context_and_uptodate(self, dirname, lang, node=None):
    """Provide data for the context and the uptodate list for the list of the given classifiation."""
    kw = {
        "translations": self.site.config["TRANSLATIONS"],
        "filters": self.site.config["FILTERS"],
    }
    context = {
        "title": self.site.config["BLOG_TITLE"](lang),
        "pagekind": ["list", "front_page", "page_index"]
        if dirname == ""
        else ["list", "page_index"],
    }
    kw.update(context)
    return context, kw
# Buggy code
def write_content(cls, filename, content, rewrite_html=True):
    """Write content to file."""
    if rewrite_html:
        doc = html.document_fromstring(content)
        doc.rewrite_links(replacer)
        content = html.tostring(doc, encoding="utf8")
    else:
        content = content.encode("utf-8")

    utils.makedirs(os.path.dirname(filename))
    with open(filename, "wb+") as fd:
        fd.write(content)


# Traceback (lxml.etree.ParserError)
$ nikola import_wordpress /Users/davidak/Downloads/davidakweblog.wordpress.2016-02-23.xml
[2016-02-23T17:06:37Z] NOTICE: Nikola: The folder new_site already exists - assuming that this is a already existing Nikola site.
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/doit/doit_cmd.py", line 168, in run
return command.parse_execute(args)
File "/usr/local/lib/python3.5/site-packages/doit/cmd_base.py", line 122, in parse_execute
return self.execute(params, args)
File "/usr/local/lib/python3.5/site-packages/nikola/plugin_categories.py", line 124, in execute
return self._execute(options, args)
File "/usr/local/lib/python3.5/site-packages/nikola/plugins/command/import_wordpress.py", line 332, in _execute
self.import_posts(channel)
File "/usr/local/lib/python3.5/site-packages/nikola/plugins/command/import_wordpress.py", line 1015, in import_posts
self.process_item_if_post_or_page(item)
File "/usr/local/lib/python3.5/site-packages/nikola/plugins/command/import_wordpress.py", line 996, in process_item_if_post_or_page
out_folder_slug = self.import_postpage_item(item, wordpress_namespace, 'posts', attachments)
File "/usr/local/lib/python3.5/site-packages/nikola/plugins/command/import_wordpress.py", line 938, in import_postpage_item
rewrite_html)
File "/usr/local/lib/python3.5/site-packages/nikola/plugins/basic_import.py", line 130, in write_content
doc = html.document_fromstring(content)
File "/usr/local/lib/python3.5/site-packages/lxml/html/__init__.py", line 755, in document_fromstring
"Document is empty")
lxml.etree.ParserError: Document is empty

# Fixed code
def write_content(cls, filename, content, rewrite_html=True):
    """Write content to file."""
    if rewrite_html:
        try:
            doc = html.document_fromstring(content)
            doc.rewrite_links(replacer)
            content = html.tostring(doc, encoding="utf8")
        except etree.ParserError:
            content = content.encode("utf-8")
    else:
        content = content.encode("utf-8")

    utils.makedirs(os.path.dirname(filename))
    with open(filename, "wb+") as fd:
        fd.write(content)