Fix compatibility with Sphinx 2.1
- Fix deprecation warnings - Fix missing API in tests - Fix relative imports in tests - use proper logger
This commit is contained in:
parent
fc809c1041
commit
585085250e
4 changed files with 48 additions and 37 deletions
|
@ -18,14 +18,18 @@ from docutils.parsers.rst import Directive
|
|||
|
||||
from sphinx import addnodes
|
||||
from sphinx.domains import Domain, ObjType
|
||||
from sphinx.environment import NoUri
|
||||
from sphinx.locale import l_
|
||||
from sphinx.errors import NoUri
|
||||
from sphinx.locale import _
|
||||
from sphinx.roles import XRefRole
|
||||
from sphinx.util import logging
|
||||
from sphinx.util.nodes import make_refnode
|
||||
|
||||
__version__ = '0.2.5.dev1'
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def ip_object_anchor(typ, path):
|
||||
path = re.sub(r'[.:/]', '-', path)
|
||||
return typ.lower() + '-' + path
|
||||
|
@ -52,13 +56,17 @@ class IPXRefRole(XRefRole):
|
|||
super(IPXRefRole, self).__init__(
|
||||
innernodeclass=innernodeclass, **kwargs)
|
||||
|
||||
def __call__(self, typ, rawtext, text, lineno, inliner,
|
||||
options={}, content=[]):
|
||||
def __cal__(self, typ, rawtext, text, lineno, inliner,
|
||||
options=None, content=None):
|
||||
if content is None:
|
||||
content = []
|
||||
if options is None:
|
||||
options = {}
|
||||
try:
|
||||
Network(text)
|
||||
except ValueError as e:
|
||||
env = inliner.document.settings.env
|
||||
env.warn(env.docname, "invalid ip address/range %s" % text, lineno)
|
||||
logger.warning("invalid ip address/range %s" % text, location=(env.docname, lineno))
|
||||
return [nodes.literal(text, text), []]
|
||||
return super(IPXRefRole, self).__call__(
|
||||
typ, rawtext, text, lineno, inliner, options, content)
|
||||
|
@ -140,20 +148,20 @@ class IPv4Range(IPRange):
|
|||
typ = 'v4range'
|
||||
|
||||
def get_prefix_title(self):
|
||||
return l_('IPv4 address range ')
|
||||
return _('IPv4 address range ')
|
||||
|
||||
def get_index_text(self):
|
||||
return "%s; %s" % (l_('IPv4 range'), self.rangespec)
|
||||
return "%s; %s" % (_('IPv4 range'), self.rangespec)
|
||||
|
||||
|
||||
class IPv6Range(IPRange):
|
||||
typ = 'v6range'
|
||||
|
||||
def get_prefix_title(self):
|
||||
return l_('IPv6 address range ')
|
||||
return _('IPv6 address range ')
|
||||
|
||||
def get_index_text(self):
|
||||
return "%s; %s" % (l_('IPv6 range'), self.rangespec)
|
||||
return "%s; %s" % (_('IPv6 range'), self.rangespec)
|
||||
|
||||
|
||||
class IPDomain(Domain):
|
||||
|
@ -164,10 +172,10 @@ class IPDomain(Domain):
|
|||
label = 'IP addresses and ranges.'
|
||||
|
||||
object_types = {
|
||||
'v4': ObjType(l_('v4'), 'v4', 'obj'),
|
||||
'v6': ObjType(l_('v6'), 'v6', 'obj'),
|
||||
'v4range': ObjType(l_('v4range'), 'v4range', 'obj'),
|
||||
'v6range': ObjType(l_('v6range'), 'v6range', 'obj'),
|
||||
'v4': ObjType(_('v4'), 'v4', 'obj'),
|
||||
'v6': ObjType(_('v6'), 'v6', 'obj'),
|
||||
'v4range': ObjType(_('v4range'), 'v4range', 'obj'),
|
||||
'v6range': ObjType(_('v6range'), 'v6range', 'obj'),
|
||||
}
|
||||
|
||||
directives = {
|
||||
|
@ -176,10 +184,10 @@ class IPDomain(Domain):
|
|||
}
|
||||
|
||||
roles = {
|
||||
'v4': IPXRefRole('v4', l_('IPv4 address')),
|
||||
'v6': IPXRefRole('v6', l_('IPv6 address')),
|
||||
'v4range': IPXRefRole('v4range', l_('IPv4 range')),
|
||||
'v6range': IPXRefRole('v6range', l_('IPv6 range')),
|
||||
'v4': IPXRefRole('v4', _('IPv4 address')),
|
||||
'v6': IPXRefRole('v6', _('IPv6 address')),
|
||||
'v4range': IPXRefRole('v4range', _('IPv4 range')),
|
||||
'v6range': IPXRefRole('v6range', _('IPv6 range')),
|
||||
}
|
||||
|
||||
initial_data = {
|
||||
|
@ -277,7 +285,7 @@ def process_ip_nodes(app, doctree, fromdocname):
|
|||
env = app.builder.env
|
||||
domaindata = env.domaindata[IPDomain.name]
|
||||
|
||||
header = (l_('IP address'), l_('Used by'))
|
||||
header = (_('IP address'), _('Used by'))
|
||||
colwidths = (1, 3)
|
||||
|
||||
for node in doctree.traverse(ip_range):
|
||||
|
@ -286,8 +294,14 @@ def process_ip_nodes(app, doctree, fromdocname):
|
|||
ips = {}
|
||||
for key, value in [
|
||||
(ip_info['ip'], ip_info) for ip_info in
|
||||
domaindata['ips'] if ip_info['ip'] in net
|
||||
domaindata['ips']
|
||||
]:
|
||||
try:
|
||||
if not key in net:
|
||||
continue
|
||||
except ValueError as e:
|
||||
logger.info("invalid IP address info %s", e.args)
|
||||
continue
|
||||
addrlist = ips.get(key, [])
|
||||
addrlist.append(value)
|
||||
ips[key] = addrlist
|
||||
|
@ -337,7 +351,7 @@ def process_ip_nodes(app, doctree, fromdocname):
|
|||
tbody += create_table_row([para, refnode])
|
||||
content.append(table)
|
||||
else:
|
||||
para = nodes.paragraph(l_('No IP addresses in this range'))
|
||||
para = nodes.paragraph(_('No IP addresses in this range'))
|
||||
content.append(para)
|
||||
node.replace_self(content)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue