Walk the tree and extract excert into resource.excerpt
503553
def stamp_excerpt(kb_app: kb,
                  sphinx_app: Sphinx,
                  doctree: doctree):
    

    # First, find out which resource this is. Won't be easy.
    resources = sphinx_app.env.resources
    confdir = sphinx_app.confdir
    source = PurePath(doctree.attributes['source'])

    # Get the relative path inside the docs dir, without .rst, then
    # get the resource
    docname = str(source.relative_to(confdir)).split('.rst')[0]
    resource = resources.get(docname)

    if resource:
        # Stamp the excerpt on the resource
        excerpt = getattr(resource.props, 'excerpt', False)
        auto_excerpt = getattr(resource.props, 'auto_excerpt', False)
        if excerpt:
            resource.excerpt = excerpt
        elif not auto_excerpt:
            resource.excerpt = None
        else:
            # Extract the excerpt based on the number of paragraphs
            # in auto_excerpt
            resource.excerpt = get_rst_excerpt(doctree, auto_excerpt)
685205
def extract_tree_block(self):
        ""        

        lines = iter(self.data)
        while 1:
            try:
                line = next(lines).strip()
            except StopIteration:
                break
    
            # enter trees block
            if line.lower() == "begin trees;":
                while 1:
                    # iter through trees block
                    sub = next(lines).strip().split()
                    
                    # skip if a blank line
                    if not sub:
                        continue

                    # look for translation
                    if sub[0].lower() == "translate":
                        while sub[0] != ";":
                            sub = next(lines).strip().split()
                            self.tdict[sub[0]] = sub[-1].strip(",")

                    # parse tree blocks
                    if sub[0].lower().startswith("tree"):
                        self.newicks.append(sub[-1])
        
                    # end of trees block
                    if sub[0].lower() == "end;":
                        break
177726
def walk(self, head=None):
        """"""
        head = head or self._root_node

        queue = []
        queue.insert(0, head)

        while queue:
            node = queue.pop()

            yield node.num, node.previous, node.siblings

            for child in node.siblings:
                if child in self._graph:
                    queue.insert(0, self._graph[child])
1354765
def exercise_callback_factory(match, url_template,
                              mc_client=None, token=None, mml_url=None):
    """"""

    def _replace_exercises(elem):
        item_code = elem.get('href')[len(match):]
        url = url_template.format(itemCode=item_code)
        exercise = {}
        if mc_client:
            mc_key = item_code + (token or '')
            exercise = json.loads(mc_client.get(mc_key) or '{}')

        if not exercise:
            if token:
                headers = {'Authorization': 'Bearer {}'.format(token)}
                res = requests.get(url, headers=headers)
            else:
                res = requests.get(url)
            if res:
                # grab the json exercise, run it through Jinja2 template,
                # replace element w/ it
                exercise = res.json()
                if mc_client:
                    mc_client.set(mc_key, res.text)

        if exercise['total_count'] == 0:
            logger.warning('MISSING EXERCISE: {}'.format(url))

            XHTML = '{{{}}}'.format(HTML_DOCUMENT_NAMESPACES['xhtml'])
            missing = etree.Element(XHTML + 'div',
                                    {'class': 'missing-exercise'},
                                    nsmap=HTML_DOCUMENT_NAMESPACES)
            missing.text = 'MISSING EXERCISE: tag:{}'.format(item_code)
            nodes = [missing]
        else:
            html = EXERCISE_TEMPLATE.render(data=exercise)
            try:
                nodes = etree.fromstring('<div>{}</div>'.format(html))
            except etree.XMLSyntaxError:  # Probably HTML
                nodes = etree.HTML(html)[0]  # body node

            if mml_url:
                for node in nodes.xpath('//*[@data-math]'):
                    mathml = _replace_tex_math(node, mml_url, mc_client)
                    if mathml is not None:
                        mparent = node.getparent()
                        mparent.replace(node, mathml)
                    else:
                        mathtext = node.get('data-math') or node.text or ''
                        logger.warning('BAD TEX CONVERSION: "%s" URL: %s'
                                       % (mathtext.encode('utf-8'), url))

        parent = elem.getparent()
        if etree.QName(parent.tag).localname == 'p':
            elem = parent
            parent = elem.getparent()

        parent.remove(elem)  # Special case - assumes single wrapper elem
        for child in nodes:
            parent.append(child)

    xpath = '//xhtml:a[contains(@href, "{}")]'.format(match)
    return (xpath, _replace_exercises)
492708
async function archiveGitTree(repPath, tree, archive) {
  // recursively collect all entries (blobs and trees)
  const allEntries = await collectTreeEntries(repPath, tree, [], '');

  const process = async ({ type, oid, path }) => {
    if (type === 'tree' || type === 'commit') {
      // directory or submodule
      archive.append(null, { name: `${path}/` });
    } else {
      // blob
      const stream = await createBlobReadStream(repPath, oid);
      archive.append(stream, { name: path });
    }
  };

  return new Promise((resolve, reject) => {
    async.eachSeries(
      allEntries,
      async.asyncify(process),
      (err) => {
        if (err) {
          reject(err);
        } else {
          resolve(archive);
        }
      },
    );
  });
}
1361297
protected void extractResult(Session session, Health.Builder builder)
			throws Exception {
		Result result = session.query(CYPHER, Collections.emptyMap());
		builder.up().withDetail("nodes",
				result.queryResults().iterator().next().get("nodes"));
	}
1075014
@Override
	public void walkTree(IResourceVisitor visitor) throws IOException {
		if (!exists() || symname == null) {
			throw new IOException(getURI().toString());
		}
		Bundle bundle = Platform.getBundle(symname);
		recurse(bundle, getURI().getPath(), visitor, ""); //$NON-NLS-1$
	}
774476
@Override
	public void walkTree(IResourceVisitor visitor) throws IOException {
		if (!exists()) {
			throw new FileNotFoundException(file.getAbsolutePath());
		}
		if (!file.isDirectory()) {
			return;
		}
		recurse(file, visitor, ""); //$NON-NLS-1$
	}
654280
def walk_tree(root):
    """"""
    yield root

    for child in root.children:
        for el in walk_tree(child):
            yield el
377297
def walk(self, node):
        ""
        node = self.visit(node)

        if node is None:
            return None

        if isinstance(node, parso.tree.BaseNode):
            walked = map(self.walk, node.children)
            node.children = [child for child in walked if child is not None]

        return node
747024
def _walk(r):
    '''
    
    '''
    if not r.dir:
        return [r.key.split('/', 3)[3]]

    keys = []
    for c in client.read(r.key).children:
        keys.extend(_walk(c))
    return keys
1076368
def takeFromTree(self):
        
        tree = self.treeWidget()
        parent = self.parent()
        
        if parent:
            parent.takeChild(parent.indexOfChild(self))
        else:
            tree.takeTopLevelItem(tree.indexOfTopLevelItem(self))
996916
def walk(
            self, node, omit=(
                'lexpos', 'lineno', 'colno', 'rowno'),
            indent=0, depth=-1,
            pos=False,
            _level=0):
        

        if not depth:
            return '<%s ...>' % node.__class__.__name__

        attrs = []
        children = node.children()
        ids = {id(child) for child in children}

        indentation = ' ' * (indent * (_level + 1))
        header = '\n' + indentation if indent else ''
        joiner = ',\n' + indentation if indent else ', '
        tailer = '\n' + ' ' * (indent * _level) if indent else ''

        for k, v in vars(node).items():
            if k.startswith('_'):
                continue
            if id(v) in ids:
                ids.remove(id(v))

            if isinstance(v, Node):
                attrs.append((k, self.walk(
                    v, omit, indent, depth - 1, pos, _level)))
            elif isinstance(v, list):
                items = []
                for i in v:
                    if id(i) in ids:
                        ids.remove(id(i))
                    items.append(self.walk(
                        i, omit, indent, depth - 1, pos, _level + 1))
                attrs.append(
                    (k, '[' + header + joiner.join(items) + tailer + ']'))
            else:
                attrs.append((k, repr_compat(v)))

        if ids:
            # for unnamed child nodes.
            attrs.append(('?children', '[' + header + joiner.join(
                self.walk(child, omit, indent, depth - 1, pos, _level + 1)
                for child in children
                if id(child) in ids) + tailer + ']'))

        position = ('@%s:%s ' % (
            '?' if node.lineno is None else node.lineno,
            '?' if node.colno is None else node.colno,
        ) if pos else '')

        omit_keys = () if not omit else set(omit)
        return '<%s %s%s>' % (node.__class__.__name__, position, ', '.join(
            '%s=%s' % (k, v) for k, v in sorted(attrs)
            if k not in omit_keys
        ))
40388
def walk(self, top, topdown=True, ignore_file_handler=None):
        

        tree = self.git_object_by_path(top)
        if tree is None:
            raise IOError(errno.ENOENT, "No such file")

        for x in self._walk(tree, topdown):
            yield x
935241
def excerpts(n_samples, n_excerpts=None, excerpt_size=None):
    """"""
    assert n_excerpts >= 2
    step = _excerpt_step(n_samples,
                         n_excerpts=n_excerpts,
                         excerpt_size=excerpt_size)
    for i in range(n_excerpts):
        start = i * step
        if start >= n_samples:
            break
        end = min(start + excerpt_size, n_samples)
        yield start, end
1078051
def from_etree(root):
        
        cite_list = []
        citations = root.xpath('Citations/EventIVORN')
        if citations:
            description = root.xpath('Citations/Description')
            if description:
                description_text = description[0].text
            else:
                description_text = None
            for entry in root.Citations.EventIVORN:
                if entry.text:
                    cite_list.append(
                        Cite(ref_ivorn=entry.text,
                             cite_type=entry.attrib['cite'],
                             description=description_text)
                    )
                else:
                    logger.info(
                        'Ignoring empty citation in {}'.format(
                            root.attrib['ivorn']))
        return cite_list
846286
def text_extract(path, password=None):
    """"""
    pdf = Info(path, password).pdf

    return [pdf.getPage(i).extractText() for i in range(pdf.getNumPages())]