mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
use six privided functions/classes to support py2/py3 in one source. refs #1350
This commit is contained in:
parent
9dbb6bf092
commit
f31d9113ff
@ -13,11 +13,12 @@ import re
|
||||
import socket
|
||||
import threading
|
||||
from os import path
|
||||
from urllib2 import build_opener, unquote, Request, \
|
||||
HTTPError, HTTPRedirectHandler
|
||||
from HTMLParser import HTMLParser, HTMLParseError
|
||||
|
||||
from six.moves import queue
|
||||
from six.moves.urllib.request import build_opener, Request, HTTPRedirectHandler
|
||||
from six.moves.urllib.parse import unquote
|
||||
from six.moves.urllib.error import HTTPError
|
||||
from six.moves.html_parser import HTMLParser, HTMLParseError
|
||||
from docutils import nodes
|
||||
|
||||
from sphinx.builders import Builder
|
||||
|
@ -27,12 +27,12 @@
|
||||
import time
|
||||
import zlib
|
||||
import codecs
|
||||
import urllib2
|
||||
import posixpath
|
||||
from os import path
|
||||
import re
|
||||
|
||||
from six import iteritems
|
||||
from six.moves.urllib import request
|
||||
from docutils import nodes
|
||||
from docutils.utils import relative_path
|
||||
|
||||
@ -41,14 +41,14 @@ from sphinx.builders.html import INVENTORY_FILENAME
|
||||
from sphinx.util.pycompat import b
|
||||
|
||||
|
||||
handlers = [urllib2.ProxyHandler(), urllib2.HTTPRedirectHandler(),
|
||||
urllib2.HTTPHandler()]
|
||||
handlers = [request.ProxyHandler(), request.HTTPRedirectHandler(),
|
||||
request.HTTPHandler()]
|
||||
try:
|
||||
handlers.append(urllib2.HTTPSHandler)
|
||||
handlers.append(request.HTTPSHandler)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
urllib2.install_opener(urllib2.build_opener(*handlers))
|
||||
request.install_opener(request.build_opener(*handlers))
|
||||
|
||||
UTF8StreamReader = codecs.lookup('utf-8')[2]
|
||||
|
||||
@ -130,7 +130,7 @@ def fetch_inventory(app, uri, inv):
|
||||
join = localuri and path.join or posixpath.join
|
||||
try:
|
||||
if inv.find('://') != -1:
|
||||
f = urllib2.urlopen(inv)
|
||||
f = request.urlopen(inv)
|
||||
else:
|
||||
f = open(path.join(app.srcdir, inv), 'rb')
|
||||
except Exception as err:
|
||||
|
@ -13,7 +13,7 @@
|
||||
import re
|
||||
|
||||
import six
|
||||
from six import iteritems
|
||||
from six import iteritems, integer_types
|
||||
|
||||
from sphinx.util.pycompat import u
|
||||
|
||||
@ -87,7 +87,7 @@ def dumps(obj, key=False):
|
||||
return 'null'
|
||||
elif obj is True or obj is False:
|
||||
return obj and 'true' or 'false'
|
||||
elif isinstance(obj, (int, long, float)):
|
||||
elif isinstance(obj, integer_types + (float,)):
|
||||
return str(obj)
|
||||
elif isinstance(obj, dict):
|
||||
return '{%s}' % ','.join('%s:%s' % (
|
||||
|
@ -11,10 +11,10 @@
|
||||
|
||||
import os
|
||||
import re
|
||||
import htmlentitydefs
|
||||
|
||||
import six
|
||||
from six import iteritems
|
||||
from six.moves import html_entities
|
||||
|
||||
try:
|
||||
import pygments
|
||||
@ -347,7 +347,7 @@ def test_html(app):
|
||||
|
||||
for fname, paths in iteritems(HTML_XPATH):
|
||||
parser = NslessParser()
|
||||
parser.entity.update(htmlentitydefs.entitydefs)
|
||||
parser.entity.update(html_entities.entitydefs)
|
||||
fp = open(os.path.join(app.outdir, fname), 'rb')
|
||||
try:
|
||||
etree = ET.parse(fp, parser)
|
||||
|
Loading…
Reference in New Issue
Block a user