Intersphinx: parse inventories correctly when object names contain embedded spaces.

This is an issue, e.g., for (multi-word) glossary terms.
This commit is contained in:
Jeff Dairiki 2012-02-26 07:49:07 -08:00
parent 64593b946e
commit 743521d55b
2 changed files with 10 additions and 1 deletions

View File

@ -30,6 +30,7 @@ import codecs
import urllib2
import posixpath
from os import path
import re
from docutils import nodes
@ -99,7 +100,12 @@ def read_inventory_v2(f, uri, join, bufsize=16*1024):
assert not buf
for line in split_lines(read_chunks()):
name, type, prio, location, dispname = line.rstrip().split(None, 4)
# be careful to handle names with embedded spaces correctly
m = re.match(r'(?x)(.+?)\s+(\S*:\S*)\s+(\S+)\s+(\S+)\s+(.*)',
line.rstrip())
if not m:
continue
name, type, prio, location, dispname = m.groups()
if location.endswith(u'$'):
location = location[:-1] + name
location = join(uri, location)

View File

@ -43,6 +43,7 @@ module1 py:module 0 foo.html#module-module1 Long Module desc
module2 py:module 0 foo.html#module-$ -
module1.func py:function 1 sub/foo.html#$ -
CFunc c:function 2 cfunc.html#CFunc -
a term std:term -1 glossary.html#term-a-term -
'''.encode('utf-8'))
@ -76,6 +77,8 @@ def test_read_inventory_v2():
assert invdata1['py:function']['module1.func'][2] == \
'/util/sub/foo.html#module1.func'
assert invdata1['c:function']['CFunc'][2] == '/util/cfunc.html#CFunc'
assert invdata1['std:term']['a term'][2] == \
'/util/glossary.html#term-a-term'
@with_app(confoverrides={'extensions': 'sphinx.ext.intersphinx'})