当前位置: 首页>>代码示例>>Python>>正文


Python url_re.match函数代码示例

本文整理汇总了Python中sphinx.util.url_re.match函数的典型用法代码示例。如果您正苦于以下问题:Python match函数的具体用法?Python match怎么用?Python match使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了match函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse_content

    def parse_content(self, toctree):
        suffixes = self.config.source_suffix

        # glob target documents
        all_docnames = self.env.found_docs.copy()
        all_docnames.remove(self.env.docname)  # remove current document

        ret = []
        for entry in self.content:
            if not entry:
                continue
            # look for explicit titles ("Some Title <document>")
            explicit = explicit_title_re.match(entry)
            if (toctree['glob'] and glob_re.match(entry) and
                    not explicit and not url_re.match(entry)):
                patname = docname_join(self.env.docname, entry)
                docnames = sorted(patfilter(all_docnames, patname))
                for docname in docnames:
                    all_docnames.remove(docname)  # don't include it again
                    toctree['entries'].append((None, docname))
                    toctree['includefiles'].append(docname)
                if not docnames:
                    ret.append(self.state.document.reporter.warning(
                        'toctree glob pattern %r didn\'t match any documents'
                        % entry, line=self.lineno))
            else:
                if explicit:
                    ref = explicit.group(2)
                    title = explicit.group(1)
                    docname = ref
                else:
                    ref = docname = entry
                    title = None
                # remove suffixes (backwards compatibility)
                for suffix in suffixes:
                    if docname.endswith(suffix):
                        docname = docname[:-len(suffix)]
                        break
                # absolutize filenames
                docname = docname_join(self.env.docname, docname)
                if url_re.match(ref) or ref == 'self':
                    toctree['entries'].append((title, ref))
                elif docname not in self.env.found_docs:
                    ret.append(self.state.document.reporter.warning(
                        'toctree contains reference to nonexisting '
                        'document %r' % docname, line=self.lineno))
                    self.env.note_reread()
                else:
                    all_docnames.discard(docname)
                    toctree['entries'].append((title, docname))
                    toctree['includefiles'].append(docname)

        # entries contains all entries (self references, external links etc.)
        if 'reversed' in self.options:
            toctree['entries'] = list(reversed(toctree['entries']))

        return ret
开发者ID:papadeltasierra,项目名称:sphinx,代码行数:57,代码来源:other.py

示例2: _walk_doctree

        def _walk_doctree(docname, doctree, secnum):
            # type: (unicode, nodes.Node, Tuple[int, ...]) -> None
            for subnode in doctree.children:
                if isinstance(subnode, nodes.section):
                    next_secnum = get_section_number(docname, subnode)
                    if next_secnum:
                        _walk_doctree(docname, subnode, next_secnum)
                    else:
                        _walk_doctree(docname, subnode, secnum)
                    continue
                elif isinstance(subnode, addnodes.toctree):
                    for title, subdocname in subnode['entries']:
                        if url_re.match(subdocname) or subdocname == 'self':
                            # don't mess with those
                            continue

                        _walk_doc(subdocname, secnum)

                    continue

                figtype = get_figtype(subnode)
                if figtype and subnode['ids']:
                    register_fignumber(docname, secnum, figtype, subnode)

                _walk_doctree(docname, subnode, secnum)
开发者ID:AWhetter,项目名称:sphinx,代码行数:25,代码来源:toctree.py

示例3: _walk_toctree

 def _walk_toctree(toctreenode, depth):
     if depth == 0:
         return
     for (title, ref) in toctreenode['entries']:
         if url_re.match(ref) or ref == 'self' or ref in assigned:
             # don't mess with those
             continue
         if ref in self.tocs:
             secnums = self.toc_secnumbers[ref] = {}
             assigned.add(ref)
             _walk_toc(self.tocs[ref], secnums, depth,
                       self.env.titles.get(ref))
             if secnums != old_secnumbers.get(ref):
                 rewrite_needed.append(ref)
开发者ID:JelteF,项目名称:sphinx,代码行数:14,代码来源:toctree.py

示例4: _walk_toctree

 def _walk_toctree(toctreenode, depth):
     if depth == 0:
         return
     for (title, ref) in toctreenode['entries']:
         if url_re.match(ref) or ref == 'self':
             # don't mess with those
             continue
         elif ref in assigned:
             logger.warning('%s is already assigned section numbers '
                            '(nested numbered toctree?)', ref,
                            location=toctreenode, type='toc', subtype='secnum')
         elif ref in env.tocs:
             secnums = env.toc_secnumbers[ref] = {}
             assigned.add(ref)
             _walk_toc(env.tocs[ref], secnums, depth,
                       env.titles.get(ref))
             if secnums != old_secnumbers.get(ref):
                 rewrite_needed.append(ref)
开发者ID:LFYG,项目名称:sphinx,代码行数:18,代码来源:toctree.py

示例5: _walk_doctree

        def _walk_doctree(docname, doctree, secnum):
            for subnode in doctree.children:
                if isinstance(subnode, nodes.section):
                    next_secnum = get_section_number(docname, subnode)
                    if next_secnum:
                        _walk_doctree(docname, subnode, next_secnum)
                    else:
                        _walk_doctree(docname, subnode, secnum)
                    continue
                elif isinstance(subnode, addnodes.toctree):
                    for title, subdocname in subnode['entries']:
                        if url_re.match(subdocname) or subdocname == 'self':
                            # don't mess with those
                            continue

                        _walk_doc(subdocname, secnum)

                    continue

                figtype = self.env.get_domain('std').get_figtype(subnode)  # type: ignore
                if figtype and subnode['ids']:
                    register_fignumber(docname, secnum, figtype, subnode)

                _walk_doctree(docname, subnode, secnum)
开发者ID:JelteF,项目名称:sphinx,代码行数:24,代码来源:toctree.py

示例6: _entries_from_toctree

 def _entries_from_toctree(toctreenode, parents,
                           separate=False, subtree=False):
     """Return TOC entries for a toctree node."""
     refs = [(e[0], e[1]) for e in toctreenode['entries']]
     entries = []
     for (title, ref) in refs:
         try:
             refdoc = None
             if url_re.match(ref):
                 if title is None:
                     title = ref
                 reference = nodes.reference('', '', internal=False,
                                             refuri=ref, anchorname='',
                                             *[nodes.Text(title)])
                 para = addnodes.compact_paragraph('', '', reference)
                 item = nodes.list_item('', para)
                 toc = nodes.bullet_list('', item)
             elif ref == 'self':
                 # 'self' refers to the document from which this
                 # toctree originates
                 ref = toctreenode['parent']
                 if not title:
                     title = clean_astext(self.titles[ref])
                 reference = nodes.reference('', '', internal=True,
                                             refuri=ref,
                                             anchorname='',
                                             *[nodes.Text(title)])
                 para = addnodes.compact_paragraph('', '', reference)
                 item = nodes.list_item('', para)
                 # don't show subitems
                 toc = nodes.bullet_list('', item)
             else:
                 if ref in parents:
                     self.env.warn(ref, 'circular toctree references '
                                   'detected, ignoring: %s <- %s' %
                                   (ref, ' <- '.join(parents)))
                     continue
                 refdoc = ref
                 toc = self.tocs[ref].deepcopy()
                 maxdepth = self.env.metadata[ref].get('tocdepth', 0)
                 if ref not in toctree_ancestors or (prune and maxdepth > 0):
                     self._toctree_prune(toc, 2, maxdepth, collapse)
                 process_only_nodes(toc, builder.tags, warn_node=self.env.warn_node)
                 if title and toc.children and len(toc.children) == 1:
                     child = toc.children[0]
                     for refnode in child.traverse(nodes.reference):
                         if refnode['refuri'] == ref and \
                            not refnode['anchorname']:
                             refnode.children = [nodes.Text(title)]
             if not toc.children:
                 # empty toc means: no titles will show up in the toctree
                 self.env.warn_node(
                     'toctree contains reference to document %r that '
                     'doesn\'t have a title: no link will be generated'
                     % ref, toctreenode)
         except KeyError:
             # this is raised if the included file does not exist
             self.env.warn_node(
                 'toctree contains reference to nonexisting document %r'
                 % ref, toctreenode)
         else:
             # if titles_only is given, only keep the main title and
             # sub-toctrees
             if titles_only:
                 # delete everything but the toplevel title(s)
                 # and toctrees
                 for toplevel in toc:
                     # nodes with length 1 don't have any children anyway
                     if len(toplevel) > 1:
                         subtrees = toplevel.traverse(addnodes.toctree)
                         if subtrees:
                             toplevel[1][:] = subtrees
                         else:
                             toplevel.pop(1)
             # resolve all sub-toctrees
             for subtocnode in toc.traverse(addnodes.toctree):
                 if not (subtocnode.get('hidden', False) and
                         not includehidden):
                     i = subtocnode.parent.index(subtocnode) + 1
                     for item in _entries_from_toctree(
                             subtocnode, [refdoc] + parents,
                             subtree=True):
                         subtocnode.parent.insert(i, item)
                         i += 1
                     subtocnode.parent.remove(subtocnode)
             if separate:
                 entries.append(toc)
             else:
                 entries.extend(toc.children)
     if not subtree and not separate:
         ret = nodes.bullet_list()
         ret += entries
         return [ret]
     return entries
开发者ID:JelteF,项目名称:sphinx,代码行数:94,代码来源:toctree.py

示例7: resolve_toctree

    def resolve_toctree(self, docname, builder, toctree, prune=True, maxdepth=0,
                        titles_only=False, collapse=False, includehidden=False):
        # type: (unicode, Builder, addnodes.toctree, bool, int, bool, bool, bool) -> nodes.Node
        """Resolve a *toctree* node into individual bullet lists with titles
        as items, returning None (if no containing titles are found) or
        a new node.

        If *prune* is True, the tree is pruned to *maxdepth*, or if that is 0,
        to the value of the *maxdepth* option on the *toctree* node.
        If *titles_only* is True, only toplevel document titles will be in the
        resulting tree.
        If *collapse* is True, all branches not containing docname will
        be collapsed.
        """
        if toctree.get('hidden', False) and not includehidden:
            return None

        # For reading the following two helper function, it is useful to keep
        # in mind the node structure of a toctree (using HTML-like node names
        # for brevity):
        #
        # <ul>
        #   <li>
        #     <p><a></p>
        #     <p><a></p>
        #     ...
        #     <ul>
        #       ...
        #     </ul>
        #   </li>
        # </ul>
        #
        # The transformation is made in two passes in order to avoid
        # interactions between marking and pruning the tree (see bug #1046).

        toctree_ancestors = self.get_toctree_ancestors(docname)

        def _toctree_add_classes(node, depth):
            """Add 'toctree-l%d' and 'current' classes to the toctree."""
            for subnode in node.children:
                if isinstance(subnode, (addnodes.compact_paragraph,
                                        nodes.list_item)):
                    # for <p> and <li>, indicate the depth level and recurse
                    subnode['classes'].append('toctree-l%d' % (depth-1))
                    _toctree_add_classes(subnode, depth)
                elif isinstance(subnode, nodes.bullet_list):
                    # for <ul>, just recurse
                    _toctree_add_classes(subnode, depth+1)
                elif isinstance(subnode, nodes.reference):
                    # for <a>, identify which entries point to the current
                    # document and therefore may not be collapsed
                    if subnode['refuri'] == docname:
                        if not subnode['anchorname']:
                            # give the whole branch a 'current' class
                            # (useful for styling it differently)
                            branchnode = subnode
                            while branchnode:
                                branchnode['classes'].append('current')
                                branchnode = branchnode.parent
                        # mark the list_item as "on current page"
                        if subnode.parent.parent.get('iscurrent'):
                            # but only if it's not already done
                            return
                        while subnode:
                            subnode['iscurrent'] = True
                            subnode = subnode.parent

        def _entries_from_toctree(toctreenode, parents,
                                  separate=False, subtree=False):
            """Return TOC entries for a toctree node."""
            refs = [(e[0], e[1]) for e in toctreenode['entries']]
            entries = []
            for (title, ref) in refs:
                try:
                    refdoc = None
                    if url_re.match(ref):
                        if title is None:
                            title = ref
                        reference = nodes.reference('', '', internal=False,
                                                    refuri=ref, anchorname='',
                                                    *[nodes.Text(title)])
                        para = addnodes.compact_paragraph('', '', reference)
                        item = nodes.list_item('', para)
                        toc = nodes.bullet_list('', item)
                    elif ref == 'self':
                        # 'self' refers to the document from which this
                        # toctree originates
                        ref = toctreenode['parent']
                        if not title:
                            title = clean_astext(self.titles[ref])
                        reference = nodes.reference('', '', internal=True,
                                                    refuri=ref,
                                                    anchorname='',
                                                    *[nodes.Text(title)])
                        para = addnodes.compact_paragraph('', '', reference)
                        item = nodes.list_item('', para)
                        # don't show subitems
                        toc = nodes.bullet_list('', item)
                    else:
                        if ref in parents:
#.........这里部分代码省略.........
开发者ID:JelteF,项目名称:sphinx,代码行数:101,代码来源:toctree.py

示例8: my_resolve_toctree

def my_resolve_toctree(self, docname, builder, toctree, prune=True, maxdepth=0,
                       titles_only=False, collapse=False, includehidden=False):
    """alter 'sphinx.environment.BuildEnvironment.resolve_toctree'.

    Very long copied function but only to replace one str() with unicode() :-(

    Note: Difference of this function between 1.0.7 and 1.1pre is only 1 line.
          search to see "added 1.1".

    Original description is following:
    Resolve a *toctree* node into individual bullet lists with titles
    as items, returning None (if no containing titles are found) or
    a new node.

    If *prune* is True, the tree is pruned to *maxdepth*, or if that is 0,
    to the value of the *maxdepth* option on the *toctree* node.
    If *titles_only* is True, only toplevel document titles will be in the
    resulting tree.
    If *collapse* is True, all branches not containing docname will
    be collapsed.
    """
    if toctree.get('hidden', False) and not includehidden:
        return None

    def _walk_depth(node, depth, maxdepth):
        """Utility: Cut a TOC at a specified depth."""

        # For reading this function, it is useful to keep in mind the node
        # structure of a toctree (using HTML-like node names for brevity):
        #
        # <ul>
        #   <li>
        #     <p><a></p>
        #     <p><a></p>
        #     ...
        #     <ul>
        #       ...
        #     </ul>
        #   </li>
        # </ul>

        for subnode in node.children[:]:
            if isinstance(subnode, (addnodes.compact_paragraph,
                                    nodes.list_item)):
                # for <p> and <li>, just indicate the depth level and
                # recurse to children
                subnode['classes'].append('toctree-l%d' % (depth-1))
                _walk_depth(subnode, depth, maxdepth)

            elif isinstance(subnode, nodes.bullet_list):
                # for <ul>, determine if the depth is too large or if the
                # entry is to be collapsed
                if maxdepth > 0 and depth > maxdepth:
                    subnode.parent.replace(subnode, [])
                else:
                    # to find out what to collapse, *first* walk subitems,
                    # since that determines which children point to the
                    # current page
                    _walk_depth(subnode, depth+1, maxdepth)
                    # cull sub-entries whose parents aren't 'current'
                    if (collapse and depth > 1 and
                        'iscurrent' not in subnode.parent):
                        subnode.parent.remove(subnode)

            elif isinstance(subnode, nodes.reference):
                # for <a>, identify which entries point to the current
                # document and therefore may not be collapsed
                if subnode['refuri'] == docname:
                    if not subnode['anchorname']:
                        # give the whole branch a 'current' class
                        # (useful for styling it differently)
                        branchnode = subnode
                        while branchnode:
                            branchnode['classes'].append('current')
                            branchnode = branchnode.parent
                    # mark the list_item as "on current page"
                    if subnode.parent.parent.get('iscurrent'):
                        # but only if it's not already done
                        return
                    while subnode:
                        subnode['iscurrent'] = True
                        subnode = subnode.parent

    def _entries_from_toctree(toctreenode, separate=False, subtree=False):
        """Return TOC entries for a toctree node."""
        refs = [(e[0], to_unicode(e[1])) for e in toctreenode['entries']]
        entries = []
        for (title, ref) in refs:
            try:
                if url_re.match(ref):
                    reference = nodes.reference('', '', internal=False,
                                                refuri=ref, anchorname='',
                                                *[nodes.Text(title)])
                    para = addnodes.compact_paragraph('', '', reference)
                    item = nodes.list_item('', para)
                    toc = nodes.bullet_list('', item)
                elif ref == 'self':
                    # 'self' refers to the document from which this
                    # toctree originates
                    ref = toctreenode['parent']
#.........这里部分代码省略.........
开发者ID:tkzwtks,项目名称:zaffy,代码行数:101,代码来源:unicode_ids.py

示例9: my_toctree_run

def my_toctree_run(self):
    """Show non existing entries of toctree

    Used to replace the function -> sphinx.directives.other.TocTree.run

    Only %r following are replaced %s to avoid unreadable string.
    """
    env = self.state.document.settings.env
    suffix = env.config.source_suffix
    glob = 'glob' in self.options

    ret = []
    # (title, ref) pairs, where ref may be a document, or an external link,
    # and title may be None if the document's title is to be used
    entries = []
    includefiles = []
    all_docnames = env.found_docs.copy()
    # don't add the currently visited file in catch-all patterns
    all_docnames.remove(env.docname)
    for entry in self.content:
        if not entry:
            continue
        if not glob:
            # look for explicit titles ("Some Title <document>")
            m = explicit_title_re.match(entry)
            if m:
                ref = m.group(2)
                title = m.group(1)
                docname = ref
            else:
                ref = docname = entry
                title = None
            # remove suffixes (backwards compatibility)
            if docname.endswith(suffix):
                docname = docname[:-len(suffix)]
            # absolutize filenames
            docname = docname_join(env.docname, docname)
            if url_re.match(ref) or ref == 'self':
                entries.append((title, ref))
            elif docname not in env.found_docs:
                ret.append(self.state.document.reporter.warning(
                    u'toctree contains reference to nonexisting '
                    u'document %s' % docname, line=self.lineno))
                env.note_reread()
            else:
                entries.append((title, docname))
                includefiles.append(docname)
        else:
            patname = docname_join(env.docname, entry)
            docnames = sorted(patfilter(all_docnames, patname))
            for docname in docnames:
                all_docnames.remove(docname) # don't include it again
                entries.append((None, docname))
                includefiles.append(docname)
            if not docnames:
                ret.append(self.state.document.reporter.warning(
                    'toctree glob pattern %s didn\'t match any documents'
                    % entry, line=self.lineno))
    subnode = addnodes.toctree()
    subnode['parent'] = env.docname
    # entries contains all entries (self references, external links etc.)
    subnode['entries'] = entries
    # includefiles only entries that are documents
    subnode['includefiles'] = includefiles
    subnode['maxdepth'] = self.options.get('maxdepth', -1)
    subnode['glob'] = glob
    subnode['hidden'] = 'hidden' in self.options
    subnode['numbered'] = 'numbered' in self.options
    subnode['titlesonly'] = 'titlesonly' in self.options
    wrappernode = nodes.compound(classes=['toctree-wrapper'])
    wrappernode.append(subnode)
    ret.append(wrappernode)
    return ret
开发者ID:tkzwtks,项目名称:zaffy,代码行数:73,代码来源:unicode_ids.py

示例10: _entries_from_toctree

 def _entries_from_toctree(toctreenode, separate=False, subtree=False):
     """Return TOC entries for a toctree node."""
     refs = [(e[0], to_unicode(e[1])) for e in toctreenode['entries']]
     entries = []
     for (title, ref) in refs:
         try:
             if url_re.match(ref):
                 reference = nodes.reference('', '', internal=False,
                                             refuri=ref, anchorname='',
                                             *[nodes.Text(title)])
                 para = addnodes.compact_paragraph('', '', reference)
                 item = nodes.list_item('', para)
                 toc = nodes.bullet_list('', item)
             elif ref == 'self':
                 # 'self' refers to the document from which this
                 # toctree originates
                 ref = toctreenode['parent']
                 if not title:
                     title = clean_astext(self.titles[ref])
                 reference = nodes.reference('', '', internal=True,
                                             refuri=ref,
                                             anchorname='',
                                             *[nodes.Text(title)])
                 para = addnodes.compact_paragraph('', '', reference)
                 item = nodes.list_item('', para)
                 # don't show subitems
                 toc = nodes.bullet_list('', item)
             else:
                 toc = self.tocs[ref].deepcopy()
                 self.process_only_nodes(toc, builder, ref) # added 1.1
                 if title and toc.children and len(toc.children) == 1:
                     child = toc.children[0]
                     for refnode in child.traverse(nodes.reference):
                         if refnode['refuri'] == ref and \
                                not refnode['anchorname']:
                             refnode.children = [nodes.Text(title)]
             if not toc.children:
                 # empty toc means: no titles will show up in the toctree
                 self.warn(docname,
                           'toctree contains reference to document '
                           '%r that doesn\'t have a title: no link '
                           'will be generated' % ref, toctreenode.line)
         except KeyError:
             # this is raised if the included file does not exist
             self.warn(docname, 'toctree contains reference to '
                       'nonexisting document %r' % ref,
                       toctreenode.line)
         else:
             # if titles_only is given, only keep the main title and
             # sub-toctrees
             if titles_only:
                 # delete everything but the toplevel title(s)
                 # and toctrees
                 for toplevel in toc:
                     # nodes with length 1 don't have any children anyway
                     if len(toplevel) > 1:
                         subtrees = toplevel.traverse(addnodes.toctree)
                         toplevel[1][:] = subtrees
             # resolve all sub-toctrees
             for toctreenode in toc.traverse(addnodes.toctree):
                 i = toctreenode.parent.index(toctreenode) + 1
                 for item in _entries_from_toctree(toctreenode,
                                                   subtree=True):
                     toctreenode.parent.insert(i, item)
                     i += 1
                 toctreenode.parent.remove(toctreenode)
             if separate:
                 entries.append(toc)
             else:
                 entries.extend(toc.children)
     if not subtree and not separate:
         ret = nodes.bullet_list()
         ret += entries
         return [ret]
     return entries
开发者ID:tkzwtks,项目名称:zaffy,代码行数:75,代码来源:unicode_ids.py

示例11: run

    def run(self):
        env = self.state.document.settings.env
        suffix = env.config.source_suffix
        glob = "glob" in self.options
        limit = "limit" in self.options

        ret = []
        # (title, ref) pairs, where ref may be a document, or an external link,
        # and title may be None if the document's title is to be used
        entries = []
        includefiles = []
        all_docnames = env.found_docs.copy()
        # don't add the currently visited file in catch-all patterns
        all_docnames.remove(env.docname)
        for entry in self.content:
            if not entry:
                continue
            if not glob:
                # look for explicit titles ("Some Title <document>")
                m = explicit_title_re.match(entry)
                if m:
                    ref = m.group(2)
                    title = m.group(1)
                    docname = ref
                else:
                    ref = docname = entry
                    title = None
                # remove suffixes (backwards compatibility)
                if docname.endswith(suffix):
                    docname = docname[: -len(suffix)]
                # absolutize filenames
                docname = docname_join(env.docname, docname)
                if url_re.match(ref) or ref == "self":
                    entries.append((title, ref))
                elif docname not in env.found_docs:
                    ret.append(
                        self.state.document.reporter.warning(
                            "toctree contains reference to nonexisting " "document %r" % docname, line=self.lineno
                        )
                    )
                    env.note_reread()
                else:
                    entries.append((title, docname))
                    includefiles.append(docname)
            else:
                patname = docname_join(env.docname, entry)
                docnames = sorted(patfilter(all_docnames, patname))
                for docname in docnames:
                    all_docnames.remove(docname)  # don't include it again
                    entries.append((None, docname))
                    includefiles.append(docname)
                if not docnames:
                    ret.append(
                        self.state.document.reporter.warning(
                            "toctree glob pattern %r didn't match any documents" % entry, line=self.lineno
                        )
                    )

        sorted_entries = {}
        for entry in entries:
            metadata = env.metadata.get(entry[1], {})

            if "date" not in metadata:
                continue
            try:
                pub_date = parse_date(metadata["date"])
                env.metadata.get(entry[1], {})
            except ValueError, exc:
                continue

            sorted_entries[pub_date.isoformat()] = entry
开发者ID:rmasters,项目名称:doctrine-website-sphinx,代码行数:71,代码来源:directives.py

示例12: run

 def run(self):
     env = self.state.document.settings.env
     suffix = env.config.source_suffix
     glob = 'glob' in self.options
             
     # (title, ref) pairs, where ref may only be a document
     # external links are forbidden, since we have no way of dating them
     # and title may be None if the document's title is to be used
     entries = []
     includefiles = []
     
     all_docnames = env.found_docs.copy()
     # don't add the currently visited file in catch-all patterns
     all_docnames.remove(env.docname)
     
     ret = []
     
     for entry in self.content:
         if not entry:
             continue
         if not glob:
             # look for explicit titles ("Some Title <document>")
             m = explicit_title_re.match(entry)
             if m:
                 ref = m.group(2)
                 title = m.group(1)
                 docname = ref
             else:
                 ref = docname = entry
                 title = None
             # remove suffixes (backwards compatibility)
             if docname.endswith(suffix):
                 docname = docname[:-len(suffix)]
             # absolutize filenames
             docname = docname_join(env.docname, docname)
             if url_re.match(ref) or ref == 'self':
                 entries.append((title, ref))
             elif docname not in env.found_docs:
                 ret.append(self.state.document.reporter.warning(
                     'toctree contains reference to nonexisting '
                     'document %r' % docname, line=self.lineno))
                 env.note_reread()
             else:
                 entries.append((title, docname))
                 includefiles.append(docname)
         else:
             patname = docname_join(env.docname, entry)
             docnames = patfilter(all_docnames, patname)
             for docname in docnames:
                 all_docnames.remove(docname) # don't include it again
                 entries.append((None, docname))
                 includefiles.append(docname)
             if not docnames:
                 ret.append(self.state.document.reporter.warning(
                     'latest list glob pattern %r didn\'t match any documents'
                     % entry, line=self.lineno))
     
     subnode = latest()
     subnode['parent'] = env.docname
     # entries contains all entries (self references, external links etc.)
     subnode['entries'] = entries
     # includefiles only entries that are documents
     subnode['includefiles'] = includefiles
     subnode['maxdepth'] = self.options.get('maxdepth', -1)
     subnode['glob'] = glob
     subnode['titlesonly'] = 'titlesonly' in self.options
     #what does this do?
     set_source_info(self, subnode)
     wrappernode = nodes.compound(classes=['feed-latest-wrapper'])
     wrappernode.append(subnode)
     ret.append(wrappernode)
     return ret
开发者ID:B-Rich,项目名称:docs,代码行数:72,代码来源:feeddirectives.py

示例13: run

    def run(self):
        env = self.state.document.settings.env
        suffix = env.config.source_suffix
        glob = 'glob' in self.options

        ret = []
        # (title, ref) pairs, where ref may be a document, or an external link,
        # and title may be None if the document's title is to be used
        entries = []
        includefiles = []
        includetitles = {}
        all_docnames = env.found_docs.copy()
        # don't add the currently visited file in catch-all patterns
        all_docnames.remove(env.docname)
        for entry in self.content:
            if not entry:
                continue
            if not glob:
                # look for explicit titles ("Some Title <document>")
                m = caption_ref_re.match(entry)
                if m:
                    ref = m.group(2)
                    title = m.group(1)
                    docname = ref
                else:
                    ref = docname = entry
                    title = None
                # remove suffixes (backwards compatibility)
                if docname.endswith(suffix):
                    docname = docname[:-len(suffix)]
                # absolutize filenames
                docname = docname_join(env.docname, docname)
                if url_re.match(ref) or ref == 'self':
                    entries.append((title, ref))
#                 elif docname not in env.found_docs:
#                     ret.append(self.state.document.reporter.warning(
#                         'toctree references unknown document %r' % docname,
#                         line=self.lineno))
                else:
                    entries.append((title, docname))
                    includefiles.append(docname)
            else:
                patname = docname_join(env.docname, entry)
                docnames = sorted(patfilter(all_docnames, patname))
                for docname in docnames:
                    all_docnames.remove(docname) # don't include it again
                    entries.append((None, docname))
                    includefiles.append(docname)
                if not docnames:
                    ret.append(self.state.document.reporter.warning(
                        'toctree glob pattern %r didn\'t match any documents'
                        % entry, line=self.lineno))
        subnode = addnodes.toctree()
        subnode['parent'] = env.docname
        # entries contains all entries (self references, external links etc.)
        subnode['entries'] = entries
        # includefiles only entries that are documents
        subnode['includefiles'] = includefiles
        subnode['maxdepth'] = self.options.get('maxdepth', -1)
        subnode['glob'] = glob
        subnode['hidden'] = 'hidden' in self.options
        subnode['numbered'] = 'numbered' in self.options
        ret.append(subnode)
        return ret
开发者ID:LWhitson2,项目名称:fipy,代码行数:64,代码来源:example.py

示例14: _entries_from_toctree

  def _entries_from_toctree(self, docname, toctreenode, separate=False, subtree=True):
    """
    Copied from sphinx.environment.  Modified to utilize list items instead of
    the old version which had an independent bullet_list for each entry.
    """
    refs = [(e[0], str(e[1])) for e in toctreenode['entries']]
# EV: instead of a [], use a bullet_list
    entries = nodes.bullet_list()
    for (title, ref) in refs:
      try:
        if url_re.match(ref):
          reference = nodes.reference('', '', internal=False,
                                      refuri=ref, anchorname='',
                                      *[nodes.Text(title)])
          para = addnodes.compact_paragraph('', '', reference)
          item = nodes.list_item('', para)
          toc = nodes.bullet_list('', item)
        elif ref == 'self':
          # 'self' refers to the document from which this
          # toctree originates
          ref = toctreenode['parent']
          if not title:
            title = clean_astext(self.titles[ref])
          reference = nodes.reference('', '', internal=True,
                                      refuri=ref,
                                      anchorname='',
                                      *[nodes.Text(title)])
          para = addnodes.compact_paragraph('', '', reference)
          item = nodes.list_item('', para)
          # don't show subitems
          toc = nodes.bullet_list('', item)
        else:
          # EV: get the tocs reference using self.env.main_tocs instead of just
          # self.tocs
          #toc = self.tocs[ref].deepcopy()
          toc = self.env.main_tocs[ref].deepcopy()
          if title and toc.children and len(toc.children) == 1:
            child = toc.children[0]
            for refnode in child.traverse(nodes.reference):
              if refnode['refuri'] == ref and not refnode['anchorname']:
                refnode.children = [nodes.Text(title)]
        if not toc.children:
          # empty toc means: no titles will show up in the toctree
          self.warn(docname,
                    'toctree contains reference to document '
                    '%r that doesn\'t have a title: no link '
                    'will be generated' % ref)
      except KeyError:
        # this is raised if the included file does not exist
        self.warn(docname, 'toctree contains reference to '
                  'nonexisting document %r' % ref)
      else:
# EV: copied over from 0.6.3, but outside of Environment, we don't have the
# titles_only var.
#        # if titles_only is given, only keep the main title and
#        # sub-toctrees
#        if titles_only:
#          # delete everything but the toplevel title(s)
#          # and toctrees
#          for toplevel in toc:
#            # nodes with length 1 don't have any children anyway
#            if len(toplevel) > 1:
#              subtrees = toplevel.traverse(addnodes.toctree)
#              toplevel[1][:] = subtrees

        # resolve all sub-toctrees
        for toctreenode in toc.traverse(addnodes.toctree):
          #i = toctreenode.parent.index(toctreenode) + 1
          #for item in self._entries_from_toctree(toctreenode, subtree=True):
          #  toctreenode.parent.insert(i, item)
          #  i += 1
          #toctreenode.parent.remove(toctreenode)
          toctreenode.parent.replace_self(
              self._entries_from_toctree(docname, toctreenode, subtree=True))

# EV: append each child as a list item in the bullet_list.
        #if separate:
        #  entries.append(toc)
        #else:
        #  entries.extend(toc.children)
        for child in toc.children:
          entries.append(child)

# EV: pass the entries in as a single element instead of a list of elements.
#    if not subtree and not separate:
#        ret = nodes.bullet_list()
#        ret += entries
#        return [ret]
#    return entries
    return addnodes.compact_paragraph('', '', entries)
开发者ID:DamienCassou,项目名称:eclim,代码行数:90,代码来源:builder.py

示例15: _entries_from_toctree_v122

        def _entries_from_toctree_v122(toctreenode, parents,
                                       separate=False, subtree=False,
                                       # photron: add forced_expand option to force expansion
                                       # one sublevel below the path to the current document
                                       forced_expand=False):
                                       # photron: end
            """Return TOC entries for a toctree node."""
            refs = [(e[0], e[1]) for e in toctreenode['entries']]
            entries = []
            for (title, ref) in refs:
                if title != None and title.startswith('~'):
                    continue

                try:
                    refdoc = None
                    if url_re.match(ref):
                        reference = nodes.reference('', '', internal=False,
                                                    refuri=ref, anchorname='',
                                                    *[nodes.Text(title)])
                        para = addnodes.compact_paragraph('', '', reference)
                        item = nodes.list_item('', para)
                        toc = nodes.bullet_list('', item)
                    elif ref == 'self':
                        # 'self' refers to the document from which this
                        # toctree originates
                        ref = toctreenode['parent']
                        if not title:
                            title = clean_astext(self.titles[ref])
                        reference = nodes.reference('', '', internal=True,
                                                    refuri=ref,
                                                    anchorname='',
                                                    *[nodes.Text(title)])
                        para = addnodes.compact_paragraph('', '', reference)
                        item = nodes.list_item('', para)
                        # don't show subitems
                        toc = nodes.bullet_list('', item)
                    else:
                        if ref in parents:
                            self.warn(ref, 'circular toctree references '
                                      'detected, ignoring: %s <- %s' %
                                      (ref, ' <- '.join(parents)))
                            continue
                        refdoc = ref
                        toc = self.tocs[ref].deepcopy()
                        self.process_only_nodes(toc, builder, ref)
                        if title and toc.children and len(toc.children) == 1:
                            child = toc.children[0]
                            for refnode in child.traverse(nodes.reference):
                                if refnode['refuri'] == ref and \
                                       not refnode['anchorname']:
                                    refnode.children = [nodes.Text(title)]
                    if not toc.children:
                        # empty toc means: no titles will show up in the toctree
                        self.warn_node(
                            'toctree contains reference to document %r that '
                            'doesn\'t have a title: no link will be generated'
                            % ref, toctreenode)
                except KeyError:
                    # this is raised if the included file does not exist
                    self.warn_node(
                        'toctree contains reference to nonexisting document %r'
                        % ref, toctreenode)
                else:
                    # if titles_only is given, only keep the main title and
                    # sub-toctrees
                    if titles_only:
                        # delete everything but the toplevel title(s)
                        # and toctrees
                        for toplevel in toc:
                            # nodes with length 1 don't have any children anyway
                            if len(toplevel) > 1:
                                subtrees = toplevel.traverse(addnodes.toctree)
                                toplevel[1][:] = subtrees
                    # resolve all sub-toctrees
                    for toctreenode in toc.traverse(addnodes.toctree):
                        if not (toctreenode.get('hidden', False)
                                and not includehidden):

                            # photron: use the reverse toctree lookup to only expand
                            # nodes along the way to the current document
                            if docname != 'index':
                                if docname not in self.monkey_reverse_toctree:
                                    continue

                                if not forced_expand and refdoc not in self.monkey_reverse_toctree[docname]:
                                    continue
                            # photron: end

                            # photron: force sublevel for the index and other toplevel documents,
                            # also force it for one sublevel below the path to the current document
                            next_forced_expand = \
                                docname == 'index' or \
                                len(self.monkey_reverse_toctree[docname]) == 0 or \
                                refdoc == self.monkey_reverse_toctree[docname][-1]
                            # photron: end

                            i = toctreenode.parent.index(toctreenode) + 1
                            for item in _entries_from_toctree_v122(
                                    toctreenode, [refdoc] + parents,
                                    subtree=True,
#.........这里部分代码省略.........
开发者ID:Tinkerforge,项目名称:doc,代码行数:101,代码来源:conf.py


注:本文中的sphinx.util.url_re.match函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。