# Buggy code
def get_doctree(self, docname):
    # type: (unicode) -> nodes.Node
    """Read the doctree for a file from the pickle and return it."""
    doctree_filename = self.doc2path(docname, self.doctreedir, ".doctree")
    with open(doctree_filename, "rb") as f:
        doctree = pickle.load(f)
    doctree.settings.env = self
    doctree.reporter = Reporter(
        self.doc2path(docname), 2, 5, stream=WarningStream(self._warnfunc)
    )
    return doctree


# Traceback (TypeError)
# Sphinx version: 1.6.1
# Python version: 3.5.3 (CPython)
# Docutils version: 0.13.1 release
# Jinja2 version: 2.9.6
# Last messages:
#   done
#
#   checking consistency...
#
#   done
#
#   preparing documents...
#
#   done
#
# Loaded extensions:
#   vimeo (unknown version) from /data/svn/bf-manual-zh.cn/exts/vimeo.py
#   youtube (unknown version) from /data/svn/bf-manual-zh.cn/exts/youtube.py
#   sphinx.ext.mathjax (1.6.1) from /usr/local/lib/python3.5/site-packages/sphinx/ext/mathjax.py
#   googleanalytics (0.1) from /data/svn/bf-manual-zh.cn/exts/googleanalytics.py
#   alabaster (0.7.10) from /usr/local/lib/python3.5/site-packages/alabaster/__init__.py
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/docutils/utils/error_reporting.py", line 197, in write
self.stream.write(data)
File "/usr/local/lib/python3.5/site-packages/sphinx/util/nodes.py", line 45, in write
self.warnfunc(self._re.sub(r'\1:', text), None, '')
TypeError: 'NoneType' object is not callable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/sphinx/cmdline.py", line 306, in main
app.build(opts.force_all, filenames)
File "/usr/local/lib/python3.5/site-packages/sphinx/application.py", line 332, in build
self.builder.build_all()
File "/usr/local/lib/python3.5/site-packages/sphinx/builders/__init__.py", line 285, in build_all
self.build(None, summary='all source files', method='all')
File "/usr/local/lib/python3.5/site-packages/sphinx/builders/__init__.py", line 394, in build
self.write(docnames, list(updated_docnames), method)
File "/usr/local/lib/python3.5/site-packages/sphinx/builders/__init__.py", line 429, in write
nproc=self.app.parallel - 1)
File "/usr/local/lib/python3.5/site-packages/sphinx/builders/__init__.py", line 451, in _write_parallel
doctree = self.env.get_and_resolve_doctree(firstname, self)
File "/usr/local/lib/python3.5/site-packages/sphinx/environment/__init__.py", line 904, in get_and_resolve_doctree
self.apply_post_transforms(doctree, docname)
File "/usr/local/lib/python3.5/site-packages/sphinx/environment/__init__.py", line 951, in apply_post_transforms
transformer.apply_transforms()
File "/usr/local/lib/python3.5/site-packages/sphinx/transforms/__init__.py", line 88, in apply_transforms
Transformer.apply_transforms(self)
File "/usr/local/lib/python3.5/site-packages/docutils/transforms/__init__.py", line 170, in apply_transforms
transform = transform_class(self.document, startnode=pending)
File "/usr/local/lib/python3.5/site-packages/docutils/transforms/__init__.py", line 56, in __init__
document.settings.language_code, document.reporter)
File "/usr/local/lib/python3.5/site-packages/docutils/languages/__init__.py", line 45, in get_language
'Docutils-generated text will be in English.')
File "/usr/local/lib/python3.5/site-packages/docutils/utils/__init__.py", line 220, in warning
return self.system_message(self.WARNING_LEVEL, *args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/docutils/utils/__init__.py", line 191, in system_message
self.stream.write(msg.astext() + '\n')
File "/usr/local/lib/python3.5/site-packages/docutils/utils/error_reporting.py", line 203, in write
self.encoding_errors))
File "/usr/local/lib/python3.5/site-packages/sphinx/util/nodes.py", line 45, in write
self.warnfunc(self._re.sub(r'\1:', text), None, '')
TypeError: cannot use a string pattern on a bytes-like object

# Fixed code
def get_doctree(self, docname):
    # type: (unicode) -> nodes.Node
    """Read the doctree for a file from the pickle and return it."""
    doctree_filename = self.doc2path(docname, self.doctreedir, ".doctree")
    with open(doctree_filename, "rb") as f:
        doctree = pickle.load(f)
    doctree.settings.env = self
    doctree.reporter = Reporter(self.doc2path(docname), 2, 5, stream=WarningStream())
    return doctree