Fixed some unicode decode errors

pull/171/head
Ashley Whetter 5 years ago
parent fd1cef5ced
commit 86a2aeb6d7

@ -19,6 +19,7 @@ Bug Fixes
* (Python) Forward reference annotations are no longer rendered as strings.
* (Python) autoapifunction directive no longer documents async functions as
a normal function.
* (Python) Fixed unicode decode errors in some Python 3 situations.
v1.1.0 (2019-06-23)

@ -4,7 +4,7 @@ Sphinx Auto-API Top-level Extension.
This extension allows you to automagically generate API documentation from your project.
"""
import codecs
import io
import os
import shutil
@ -189,7 +189,7 @@ def viewcode_find(app, modname):
stack.extend((full_name + ".", gchild) for gchild in children)
if module.obj["encoding"]:
source = codecs.open(
source = io.open(
module.obj["file_path"], encoding=module.obj["encoding"]
).read()
else:

@ -1,3 +1,4 @@
import io
import re
import os
import fnmatch
@ -312,6 +313,6 @@ class SphinxMapperBase(object):
# Render Top Index
top_level_index = os.path.join(root, "index.rst")
pages = self.objects.values()
with open(top_level_index, "w+") as top_level_file:
with open(top_level_index, "wb") as top_level_file:
content = self.jinja_env.get_template("index.rst")
top_level_file.write(content.render(pages=pages))
top_level_file.write(content.render(pages=pages).encode("utf-8"))

@ -20,7 +20,7 @@ class Parser(object):
return ".".join(self._name_stack + [name])
def _encode(self, to_encode):
if self._encoding:
if sys.version_info < (3,) and self._encoding:
try:
return _TEXT_TYPE(to_encode, self._encoding)
except TypeError:

@ -1,4 +1,4 @@
import codecs
import io
from setuptools import setup, find_packages
@ -12,7 +12,7 @@ setup(
license='BSD',
description='Sphinx API documentation generator',
packages=find_packages('.'),
long_description=codecs.open("README.rst", "r", "utf-8").read(),
long_description=io.open("README.rst", "r", encoding="utf-8").read(),
include_package_data=True,
install_requires=[
'astroid;python_version>="3"',

@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
data = "\xf0\xf0\xf0"
data = b"\xf0\xf0\xf0"

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
unicode_str = 'αβγδεζηθικλμνξοπρςστυφχψ'

@ -401,3 +401,10 @@ class TestComplexPackage(object):
foo_file = foo_handle.read()
assert "PublicClass" in foo_file
def test_parses_unicode_file(self):
foo_path = "_build/text/autoapi/complex/unicode_data/index.txt"
with io.open(foo_path, encoding="utf8") as foo_handle:
foo_file = foo_handle.read()
assert "unicode_str" in foo_file

Loading…
Cancel
Save