mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Closes #810: fix deprecation warnings with Python 3. What is left over is from nose or docutils.
This commit is contained in:
@@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
import codecs
|
import codecs
|
||||||
from os import path
|
from os import path
|
||||||
from cgi import escape
|
|
||||||
|
|
||||||
from sphinx import package_dir
|
from sphinx import package_dir
|
||||||
from sphinx.util import copy_static_entry
|
from sphinx.util import copy_static_entry
|
||||||
@@ -20,6 +19,7 @@ from sphinx.theming import Theme
|
|||||||
from sphinx.builders import Builder
|
from sphinx.builders import Builder
|
||||||
from sphinx.util.osutil import ensuredir, os_path
|
from sphinx.util.osutil import ensuredir, os_path
|
||||||
from sphinx.util.console import bold
|
from sphinx.util.console import bold
|
||||||
|
from sphinx.util.pycompat import htmlescape
|
||||||
|
|
||||||
|
|
||||||
class ChangesBuilder(Builder):
|
class ChangesBuilder(Builder):
|
||||||
@@ -115,7 +115,7 @@ class ChangesBuilder(Builder):
|
|||||||
'.. deprecated:: %s' % version]
|
'.. deprecated:: %s' % version]
|
||||||
|
|
||||||
def hl(no, line):
|
def hl(no, line):
|
||||||
line = '<a name="L%s"> </a>' % no + escape(line)
|
line = '<a name="L%s"> </a>' % no + htmlescape(line)
|
||||||
for x in hltext:
|
for x in hltext:
|
||||||
if x in line:
|
if x in line:
|
||||||
line = '<span class="hl">%s</span>' % line
|
line = '<span class="hl">%s</span>' % line
|
||||||
@@ -125,7 +125,10 @@ class ChangesBuilder(Builder):
|
|||||||
self.info(bold('copying source files...'))
|
self.info(bold('copying source files...'))
|
||||||
for docname in self.env.all_docs:
|
for docname in self.env.all_docs:
|
||||||
f = codecs.open(self.env.doc2path(docname), 'r', 'latin1')
|
f = codecs.open(self.env.doc2path(docname), 'r', 'latin1')
|
||||||
|
try:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
|
finally:
|
||||||
|
f.close()
|
||||||
targetfn = path.join(self.outdir, 'rst', os_path(docname)) + '.html'
|
targetfn = path.join(self.outdir, 'rst', os_path(docname)) + '.html'
|
||||||
ensuredir(path.dirname(targetfn))
|
ensuredir(path.dirname(targetfn))
|
||||||
f = codecs.open(targetfn, 'w', 'latin1')
|
f = codecs.open(targetfn, 'w', 'latin1')
|
||||||
@@ -148,7 +151,7 @@ class ChangesBuilder(Builder):
|
|||||||
self.outdir, self)
|
self.outdir, self)
|
||||||
|
|
||||||
def hl(self, text, version):
|
def hl(self, text, version):
|
||||||
text = escape(text)
|
text = htmlescape(text)
|
||||||
for directive in ['versionchanged', 'versionadded', 'deprecated']:
|
for directive in ['versionchanged', 'versionadded', 'deprecated']:
|
||||||
text = text.replace('.. %s:: %s' % (directive, version),
|
text = text.replace('.. %s:: %s' % (directive, version),
|
||||||
'<b>.. %s:: %s</b>' % (directive, version))
|
'<b>.. %s:: %s</b>' % (directive, version))
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import cgi
|
|
||||||
import codecs
|
import codecs
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
@@ -19,6 +18,7 @@ from docutils import nodes
|
|||||||
|
|
||||||
from sphinx import addnodes
|
from sphinx import addnodes
|
||||||
from sphinx.builders.html import StandaloneHTMLBuilder
|
from sphinx.builders.html import StandaloneHTMLBuilder
|
||||||
|
from sphinx.util.pycompat import htmlescape
|
||||||
|
|
||||||
|
|
||||||
# Project file (*.hhp) template. 'outname' is the file basename (like
|
# Project file (*.hhp) template. 'outname' is the file basename (like
|
||||||
@@ -241,7 +241,7 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
write_toc(subnode, ullevel)
|
write_toc(subnode, ullevel)
|
||||||
elif isinstance(node, nodes.reference):
|
elif isinstance(node, nodes.reference):
|
||||||
link = node['refuri']
|
link = node['refuri']
|
||||||
title = cgi.escape(node.astext()).replace('"','"')
|
title = htmlescape(node.astext()).replace('"','"')
|
||||||
f.write(object_sitemap % (title, link))
|
f.write(object_sitemap % (title, link))
|
||||||
elif isinstance(node, nodes.bullet_list):
|
elif isinstance(node, nodes.bullet_list):
|
||||||
if ullevel != 0:
|
if ullevel != 0:
|
||||||
@@ -272,7 +272,7 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
item = ' <param name="%s" value="%s">\n' % \
|
item = ' <param name="%s" value="%s">\n' % \
|
||||||
(name, value)
|
(name, value)
|
||||||
f.write(item)
|
f.write(item)
|
||||||
title = cgi.escape(title)
|
title = htmlescape(title)
|
||||||
f.write('<LI> <OBJECT type="text/sitemap">\n')
|
f.write('<LI> <OBJECT type="text/sitemap">\n')
|
||||||
write_param('Keyword', title)
|
write_param('Keyword', title)
|
||||||
if len(refs) == 0:
|
if len(refs) == 0:
|
||||||
|
|||||||
@@ -14,12 +14,12 @@ import re
|
|||||||
import codecs
|
import codecs
|
||||||
import posixpath
|
import posixpath
|
||||||
from os import path
|
from os import path
|
||||||
from cgi import escape
|
|
||||||
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
|
|
||||||
from sphinx import addnodes
|
from sphinx import addnodes
|
||||||
from sphinx.builders.html import StandaloneHTMLBuilder
|
from sphinx.builders.html import StandaloneHTMLBuilder
|
||||||
|
from sphinx.util.pycompat import htmlescape
|
||||||
|
|
||||||
|
|
||||||
_idpattern = re.compile(
|
_idpattern = re.compile(
|
||||||
@@ -164,7 +164,7 @@ class QtHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
fn.endswith('.html'):
|
fn.endswith('.html'):
|
||||||
filename = path.join(root, fn)[olen:]
|
filename = path.join(root, fn)[olen:]
|
||||||
projectfiles.append(file_template %
|
projectfiles.append(file_template %
|
||||||
{'filename': escape(filename)})
|
{'filename': htmlescape(filename)})
|
||||||
projectfiles = '\n'.join(projectfiles)
|
projectfiles = '\n'.join(projectfiles)
|
||||||
|
|
||||||
# it seems that the "namespace" may not contain non-alphanumeric
|
# it seems that the "namespace" may not contain non-alphanumeric
|
||||||
@@ -179,12 +179,12 @@ class QtHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
f = codecs.open(path.join(outdir, outname+'.qhp'), 'w', 'utf-8')
|
f = codecs.open(path.join(outdir, outname+'.qhp'), 'w', 'utf-8')
|
||||||
try:
|
try:
|
||||||
f.write(project_template % {
|
f.write(project_template % {
|
||||||
'outname': escape(outname),
|
'outname': htmlescape(outname),
|
||||||
'title': escape(self.config.html_title),
|
'title': htmlescape(self.config.html_title),
|
||||||
'version': escape(self.config.version),
|
'version': htmlescape(self.config.version),
|
||||||
'project': escape(self.config.project),
|
'project': htmlescape(self.config.project),
|
||||||
'namespace': escape(nspace),
|
'namespace': htmlescape(nspace),
|
||||||
'masterdoc': escape(self.config.master_doc),
|
'masterdoc': htmlescape(self.config.master_doc),
|
||||||
'sections': sections,
|
'sections': sections,
|
||||||
'keywords': keywords,
|
'keywords': keywords,
|
||||||
'files': projectfiles})
|
'files': projectfiles})
|
||||||
@@ -199,10 +199,10 @@ class QtHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
f = codecs.open(path.join(outdir, outname+'.qhcp'), 'w', 'utf-8')
|
f = codecs.open(path.join(outdir, outname+'.qhcp'), 'w', 'utf-8')
|
||||||
try:
|
try:
|
||||||
f.write(collection_template % {
|
f.write(collection_template % {
|
||||||
'outname': escape(outname),
|
'outname': htmlescape(outname),
|
||||||
'title': escape(self.config.html_short_title),
|
'title': htmlescape(self.config.html_short_title),
|
||||||
'homepage': escape(homepage),
|
'homepage': htmlescape(homepage),
|
||||||
'startpage': escape(startpage)})
|
'startpage': htmlescape(startpage)})
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
@@ -224,7 +224,7 @@ class QtHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
if self.isdocnode(node):
|
if self.isdocnode(node):
|
||||||
refnode = node.children[0][0]
|
refnode = node.children[0][0]
|
||||||
link = refnode['refuri']
|
link = refnode['refuri']
|
||||||
title = escape(refnode.astext()).replace('"','"')
|
title = htmlescape(refnode.astext()).replace('"','"')
|
||||||
item = '<section title="%(title)s" ref="%(ref)s">' % {
|
item = '<section title="%(title)s" ref="%(ref)s">' % {
|
||||||
'title': title,
|
'title': title,
|
||||||
'ref': link}
|
'ref': link}
|
||||||
@@ -237,7 +237,7 @@ class QtHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
parts.extend(self.write_toc(subnode, indentlevel))
|
parts.extend(self.write_toc(subnode, indentlevel))
|
||||||
elif isinstance(node, nodes.reference):
|
elif isinstance(node, nodes.reference):
|
||||||
link = node['refuri']
|
link = node['refuri']
|
||||||
title = escape(node.astext()).replace('"','"')
|
title = htmlescape(node.astext()).replace('"','"')
|
||||||
item = section_template % {'title': title, 'ref': link}
|
item = section_template % {'title': title, 'ref': link}
|
||||||
item = u' ' * 4 * indentlevel + item
|
item = u' ' * 4 * indentlevel + item
|
||||||
parts.append(item.encode('ascii', 'xmlcharrefreplace'))
|
parts.append(item.encode('ascii', 'xmlcharrefreplace'))
|
||||||
@@ -274,7 +274,7 @@ class QtHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
def build_keywords(self, title, refs, subitems):
|
def build_keywords(self, title, refs, subitems):
|
||||||
keywords = []
|
keywords = []
|
||||||
|
|
||||||
title = escape(title)
|
title = htmlescape(title)
|
||||||
# if len(refs) == 0: # XXX
|
# if len(refs) == 0: # XXX
|
||||||
# write_param('See Also', title)
|
# write_param('See Also', title)
|
||||||
if len(refs) == 1:
|
if len(refs) == 1:
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import cgi
|
|
||||||
import re
|
import re
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
@@ -20,6 +19,7 @@ except ImportError:
|
|||||||
# parser is not available on Jython
|
# parser is not available on Jython
|
||||||
parser = None
|
parser = None
|
||||||
|
|
||||||
|
from sphinx.util.pycompat import htmlescape
|
||||||
from sphinx.util.texescape import tex_hl_escape_map_new
|
from sphinx.util.texescape import tex_hl_escape_map_new
|
||||||
from sphinx.ext import doctest
|
from sphinx.ext import doctest
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ class PygmentsBridge(object):
|
|||||||
|
|
||||||
def unhighlighted(self, source):
|
def unhighlighted(self, source):
|
||||||
if self.dest == 'html':
|
if self.dest == 'html':
|
||||||
return '<pre>' + cgi.escape(source) + '</pre>\n'
|
return '<pre>' + htmlescape(source) + '</pre>\n'
|
||||||
else:
|
else:
|
||||||
# first, escape highlighting characters like Pygments does
|
# first, escape highlighting characters like Pygments does
|
||||||
source = source.translate(escape_hl_chars)
|
source = source.translate(escape_hl_chars)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import sys
|
|||||||
inspect = __import__('inspect')
|
inspect = __import__('inspect')
|
||||||
|
|
||||||
from sphinx.util import force_decode
|
from sphinx.util import force_decode
|
||||||
|
from sphinx.util.pycompat import bytes
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info >= (2, 5):
|
if sys.version_info >= (2, 5):
|
||||||
@@ -89,4 +90,6 @@ def safe_repr(object):
|
|||||||
s = repr(object)
|
s = repr(object)
|
||||||
except Exception:
|
except Exception:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
|
if isinstance(s, bytes):
|
||||||
return force_decode(s, None).replace('\n', ' ')
|
return force_decode(s, None).replace('\n', ' ')
|
||||||
|
return s.replace('\n', ' ')
|
||||||
|
|||||||
@@ -64,6 +64,11 @@ else:
|
|||||||
return s.encode('ascii', 'backslashreplace')
|
return s.encode('ascii', 'backslashreplace')
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
from html import escape as htmlescape
|
||||||
|
except ImportError:
|
||||||
|
from cgi import escape as htmlescape
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Missing builtins and itertools in Python < 2.6
|
# Missing builtins and itertools in Python < 2.6
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
:license: BSD, see LICENSE for details.
|
:license: BSD, see LICENSE for details.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import cgi
|
|
||||||
import sys
|
import sys
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
import posixpath
|
import posixpath
|
||||||
@@ -22,6 +21,7 @@ from docutils.core import publish_parts
|
|||||||
from sphinx.application import Sphinx
|
from sphinx.application import Sphinx
|
||||||
from sphinx.util.osutil import ensuredir
|
from sphinx.util.osutil import ensuredir
|
||||||
from sphinx.util.jsonimpl import dumps as dump_json
|
from sphinx.util.jsonimpl import dumps as dump_json
|
||||||
|
from sphinx.util.pycompat import htmlescape
|
||||||
from sphinx.websupport import errors
|
from sphinx.websupport import errors
|
||||||
from sphinx.websupport.search import BaseSearch, SEARCH_ADAPTERS
|
from sphinx.websupport.search import BaseSearch, SEARCH_ADAPTERS
|
||||||
from sphinx.websupport.storage import StorageBackend
|
from sphinx.websupport.storage import StorageBackend
|
||||||
@@ -452,5 +452,5 @@ class WebSupport(object):
|
|||||||
ret = publish_parts(text, writer_name='html',
|
ret = publish_parts(text, writer_name='html',
|
||||||
settings_overrides=settings)['fragment']
|
settings_overrides=settings)['fragment']
|
||||||
except Exception:
|
except Exception:
|
||||||
ret = cgi.escape(text)
|
ret = htmlescape(text)
|
||||||
return ret
|
return ret
|
||||||
|
|||||||
@@ -10,9 +10,10 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from cgi import escape
|
|
||||||
from difflib import Differ
|
from difflib import Differ
|
||||||
|
|
||||||
|
from sphinx.util.pycompat import htmlescape
|
||||||
|
|
||||||
|
|
||||||
class CombinedHtmlDiff(object):
|
class CombinedHtmlDiff(object):
|
||||||
"""Create an HTML representation of the differences between two pieces
|
"""Create an HTML representation of the differences between two pieces
|
||||||
@@ -21,7 +22,7 @@ class CombinedHtmlDiff(object):
|
|||||||
highlight_regex = re.compile(r'([\+\-\^]+)')
|
highlight_regex = re.compile(r'([\+\-\^]+)')
|
||||||
|
|
||||||
def __init__(self, source, proposal):
|
def __init__(self, source, proposal):
|
||||||
proposal = escape(proposal)
|
proposal = htmlescape(proposal)
|
||||||
|
|
||||||
differ = Differ()
|
differ = Differ()
|
||||||
self.diff = list(differ.compare(source.splitlines(1),
|
self.diff = list(differ.compare(source.splitlines(1),
|
||||||
|
|||||||
@@ -328,7 +328,11 @@ def test_html(app):
|
|||||||
for fname, paths in HTML_XPATH.iteritems():
|
for fname, paths in HTML_XPATH.iteritems():
|
||||||
parser = NslessParser()
|
parser = NslessParser()
|
||||||
parser.entity.update(htmlentitydefs.entitydefs)
|
parser.entity.update(htmlentitydefs.entitydefs)
|
||||||
etree = ET.parse(os.path.join(app.outdir, fname), parser)
|
fp = open(os.path.join(app.outdir, fname))
|
||||||
|
try:
|
||||||
|
etree = ET.parse(fp, parser)
|
||||||
|
finally:
|
||||||
|
fp.close()
|
||||||
for path, check in paths:
|
for path, check in paths:
|
||||||
yield check_xpath, etree, fname, path, check
|
yield check_xpath, etree, fname, path, check
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user