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