本文整理汇总了Python中sphinx.ext.intersphinx.read_inventory_v2函数的典型用法代码示例。如果您正苦于以下问题:Python read_inventory_v2函数的具体用法?Python read_inventory_v2怎么用?Python read_inventory_v2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_inventory_v2函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_read_inventory_v2
def test_read_inventory_v2():
f = BytesIO(inventory_v2)
f.readline()
invdata1 = read_inventory_v2(f, "/util", posixpath.join)
# try again with a small buffer size to test the chunking algorithm
f = BytesIO(inventory_v2)
f.readline()
invdata2 = read_inventory_v2(f, "/util", posixpath.join, bufsize=5)
assert invdata1 == invdata2
assert len(invdata1["py:module"]) == 2
assert invdata1["py:module"]["module1"] == ("foo", "2.0", "/util/foo.html#module-module1", "Long Module desc")
assert invdata1["py:module"]["module2"] == ("foo", "2.0", "/util/foo.html#module-module2", "-")
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"
示例2: parse_sphinx_inventory
def parse_sphinx_inventory(self, version):
# Parsing objects.inv is strange.
urlpattern = 'http://docs.djangoproject.com/en/%s/%%s' % version
sphinx_index = urlpattern % '_objects/'
req = requests.get(sphinx_index)
if req.status_code in [200, 301]:
fp = urllib.urlopen(sphinx_index)
fp.readline()
return intersphinx.read_inventory_v2(fp, urlpattern, operator.mod)
return []
示例3: test_read_inventory_v2
def test_read_inventory_v2():
f = BytesIO(inventory_v2)
f.readline()
invdata1 = read_inventory_v2(f, '/util', posixpath.join)
# try again with a small buffer size to test the chunking algorithm
f = BytesIO(inventory_v2)
f.readline()
invdata2 = read_inventory_v2(f, '/util', posixpath.join, bufsize=5)
assert invdata1 == invdata2
assert len(invdata1['py:module']) == 2
assert invdata1['py:module']['module1'] == \
('foo', '2.0', '/util/foo.html#module-module1', 'Long Module desc')
assert invdata1['py:module']['module2'] == \
('foo', '2.0', '/util/foo.html#module-module2', '-')
assert invdata1['py:function']['module1.func'][2] == \
'/util/sub/foo.html#module1.func'
assert invdata1['c:function']['CFunc'][2] == '/util/cfunc.html#CFunc'
示例4: get_inventory
def get_inventory(url):
inv_url = urljoin(url, 'objects.inv')
f = urllib.urlopen(inv_url)
line = f.readline().rstrip().decode('utf-8')
if line == '# Sphinx inventory version 1':
invdata = read_inventory_v1(f, url, urljoin)
elif line == '# Sphinx inventory version 2':
invdata = read_inventory_v2(f, url, urljoin)
else:
raise ValueError(line)
return invdata
示例5: parse
def parse(self):
"""
Parse sphinx docs at self.doc_path.
yield `ParserEntry`s.
"""
with open(os.path.join(self.doc_path, "objects.inv"), "rb") as inv_f:
inv_f.readline() # skip version line that is verified in detection
for pe in _inv_to_entries(
read_inventory_v2(inv_f, "", os.path.join)
): # this is what Guido gave us `yield from` for :-|
yield pe
示例6: fetch_data
def fetch_data(url, inv):
f = open(inv, 'rb')
line = f.readline() # burn a line
invdata = read_inventory_v2(f, url or '', join)
if args.html:
print("<dl>")
for role in invdata:
start_role(role)
for item in invdata[role]:
(domain, version, url, title) = invdata[role][item]
start_item(role, item)
print_link(role, item, domain, title)
print_meta(role, item, domain, version, url, title)
end_item(role, item)
if args.html:
print("</dl>\n")
示例7: fetch_data
def fetch_data(url,f):
line = f.readline() # burn a line
invdata = read_inventory_v2(f, url or '', join)
if (args.html):
print "<dl>"
for role in invdata:
start_role(role)
for item in invdata[role]:
(domain, version, url, title) = invdata[role][item]
print("{}:{} :: {}\n".format(role,item,invdata[role][item]))
start_item(role,item)
print_link(role,item,domain,title)
print_meta(role,item,domain,version,url,title)
end_item(role,item)
if (args.html):
print "</dl>\n"
示例8: fetch_data
def fetch_data(url,inv):
f = open(inv, 'rb')
line = f.readline() # burn a line
invdata = read_inventory_v2(f, url or "", join)
if (args.html):
print("<dl>")
for role in invdata:
start_role(role)
for item in invdata[role]:
(domain, version, url, title) = invdata[role][item]
#sys.stderr.write("{}:{} :: {}\n".format(role,item,invdata[role][item]))
start_item(role,item)
print_link(role,item,domain,title)
print_meta(role,item,domain,version,url,title)
end_item(role,item)
if (args.html):
print("</dl>\n")
示例9: update_intersphinx
def update_intersphinx(version_pk, api=None):
if api is None:
api = tastyapi.api
version_data = api.version(version_pk).get()
version = make_api_version(version_data)
project = version.project
try:
object_file = version.project.find('objects.inv', version.slug)[0]
except IndexError:
print "Failed to find objects file"
return None
f = open(object_file)
f.readline()
urlpattern = "http://%s/en/%s/%%s" % (project.subdomain, version.slug)
data = intersphinx.read_inventory_v2(f, urlpattern, operator.mod)
for top_key in data.keys():
#print "KEY: %s" % top_key
inner_keys = data[top_key].keys()
for inner_key in inner_keys:
#print "INNER KEY: %s" % inner_key
_project, sphinx_version, url, title = data[top_key][inner_key]
try:
url_key = url.split('#')[1]
except IndexError:
# Invalid data
continue
if ":" in url_key:
#This dumps junk data into the url namespace we don't need
#print "INNER: %s->%s" % (inner_key, url)
save_term(version, inner_key, url)
else:
last_key = url_key.split('.')[-1]
if last_key != url_key:
#Only save last key if it differes
#print "LAST: %s->%s" % (last_key, url)
save_term(version, last_key, url)
#print "URL: %s->%s" % (url_key, url)
save_term(version, url_key, url)
示例10: read_intersphinx
def read_intersphinx(project, file, urlpattern):
"""
Reads file as intersphinx format. Prepends the url pattern on the front of
URLs. URL Pattern should have a %s in it for string formatting.
Only supports intersphinx v2. It parses down into an effective set of data
that is:
{'<id>': [
"<project>", # From conf.py
"<version>", # From conf.py
"<url>", # With anchor
<title>" # Usually blank
]
}
We then smartly parse the anchor tag and add it into Redis.
"""
f = open(file)
f.readline()
data = intersphinx.read_inventory_v2(f, urlpattern, operator.mod)
for top_key in data.keys():
print "KEY: %s" % top_key
inner_keys = data[top_key].keys()
for inner_key in inner_keys:
print "INNER KEY: %s" % inner_key
_project, version, url, title = data[top_key][inner_key]
url_key = url.split('#')[1]
if ":" in url_key:
#This dumps junk data into the url namespace we don't need
print "INNER: %s->%s" % (inner_key, url)
safe_save(project, inner_key, url)
else:
last_key = url_key.split('.')[-1]
if last_key != url_key:
#Only save last key if it differes
print "LAST: %s->%s" % (last_key, url)
safe_save(project, last_key, url)
print "URL: %s->%s" % (url_key, url)
safe_save(project, url_key, url)
示例11: update_intersphinx
@task
def update_intersphinx(version_pk):
version_data = api.version(version_pk).get()
version = make_api_version(version_data)
project = version.project
try:
object_file = version.project.find("objects.inv", version.slug)[0]
except IndexError, e:
print "Failed to find objects file"
return None
f = open(object_file)
f.readline()
urlpattern = "http://%s/en/%s/%%s" % (project.subdomain, version.slug)
data = intersphinx.read_inventory_v2(f, urlpattern, operator.mod)
for top_key in data.keys():
# print "KEY: %s" % top_key
inner_keys = data[top_key].keys()
for inner_key in inner_keys:
# print "INNER KEY: %s" % inner_key
_project, sphinx_version, url, title = data[top_key][inner_key]
try:
url_key = url.split("#")[1]
except IndexError:
# Invalid data
continue
if ":" in url_key:
# This dumps junk data into the url namespace we don't need
# print "INNER: %s->%s" % (inner_key, url)
save_term(version, inner_key, url)
示例12: open
from sphinx.ext.intersphinx import read_inventory_v2
from posixpath import join
url = "https://raw.github.com/xuru/vixDiskLib/gh-pages/"
inv = "objects.inv"
f = open(inv, 'rb')
line = f.readline()
invdata = read_inventory_v2(f, url, join)
print invdata.keys()
示例13: getInventory
def getInventory(self):
f = urllib.urlopen(self.inventory_uri)
f.readline() # burn a line
self.inventory = read_inventory_v2(f, self.uri, join)
f.close()
self.inventory_items = self.inventory.get('std:label', {})
示例14: parse_sphinx_inventory
def parse_sphinx_inventory(self, version):
# Parsing objects.inv is strange.
urlpattern = 'http://docs.djangoproject.com/en/%s/%%s' % version
fp = urllib.urlopen(urlpattern % '_objects/')
fp.readline()
return intersphinx.read_inventory_v2(fp, urlpattern, operator.mod)