~nprescott/quiescent

4b3604077b76572692ae084cea8ef979598cc31e — Nolan Prescott 2 years ago ca41ac4
Specify default encoding

Without an encoding specified for the open() method, it relies on the
default system encoding
1 files changed, 6 insertions(+), 6 deletions(-)

M quiescent/static.py
M quiescent/static.py => quiescent/static.py +6 -6
@@ 95,7 95,7 @@ class StaticGenerator:
    def process_posts(self):
        for directory, filename in self.collect_posts(self.posts_dir):
            file_path = os.path.join(directory, filename)
            with open(file_path) as f:
            with open(file_path, encoding='utf-8') as f:
                text = f.read()
            try:
                relative_dir = os.path.relpath(directory, self.posts_dir)


@@ 108,7 108,7 @@ class StaticGenerator:

    def render_page(self, template_name, **kwargs):
        template_file = os.path.join(self.template_dir, template_name)
        with open(template_file) as f:
        with open(template_file, encoding='utf-8') as f:
            template_text = f.read()
        template = Templite(template_text)
        return template.render(kwargs)


@@ 120,19 120,19 @@ class StaticGenerator:
            # reconstitute the input tree in the output directory
            os.makedirs(output_tree, exist_ok=True)
            output_path = os.path.join(self.output_dir, post.path)
            with open(output_path, 'w') as f:
            with open(output_path, 'w', encoding='utf-8') as f:
                f.write(post_page)

        index_path = os.path.join(self.output_dir, self.index_template)
        index = self.render_page(self.index_template,
                                 front_posts=self.all_posts[:10])
        with open(index_path, 'w') as f:
        with open(index_path, 'w', encoding='utf-8') as f:
            f.write(index)

        archive_path = os.path.join(self.output_dir, self.archive_template)
        archive = self.render_page(self.archive_template,
                                   all_posts=self.all_posts)
        with open(archive_path, 'w') as f:
        with open(archive_path, 'w', encoding='utf-8') as f:
            f.write(archive)

        self.write_feed()


@@ 146,5 146,5 @@ class StaticGenerator:
                           feed_link=self.feed_link,
                           feed_author=self.author)
        output_path = os.path.join(self.output_dir, self.feed_link)
        with open(output_path, 'wb') as f:
        with open(output_path, 'wb', encoding='utf-8') as f:
            f.write(feed_string.encode())