Example #1
0
def headlined_sections(string, headline_pattern):
    """ return sections with headlines matching a pattern
    """
    lines = string.splitlines()
    join_lines = '\n'.join
    pattern_matcher = apf.matcher(headline_pattern)
    lines = mit.lstrip(lines, pred=lambda line: not pattern_matcher(line))
    sections = list(map(join_lines, mit.split_before(lines, pattern_matcher)))
    return sections
Example #2
0
def sections_with_headline(pattern, string):
    """ return sections with headlines matching a pattern
    """
    lines = string.splitlines()
    join_lines = '\n'.join
    pattern_matcher = matcher(pattern)
    lines = lstrip(lines, pred=lambda line: not pattern_matcher(line))
    sections = list(map(join_lines, split_before(lines, pattern_matcher)))
    return sections
Example #3
0
def headlined_sections(string, headline_pattern):
    """ Returns sections with headlines matching a pattern.

        :param string: string to return sections
        :type string: str
        :param headline_pattern: pattern to demarcate strings into sections
        :type headline_pattern: str
        :rtype: str
    """

    lines = string.splitlines()
    join_lines = '\n'.join
    pattern_matcher = apf.matcher(headline_pattern)
    lines = mit.lstrip(lines, pred=lambda line: not pattern_matcher(line))
    sections = list(map(join_lines, mit.split_before(lines, pattern_matcher)))

    return sections
Example #4
0
 def create_functions(self, dllvar='__dll') -> tp.List[ast.stmt]:
     return sum(
         [[
             ast.assign(
                 f'{cfuncname}.argtypes',
                 ast.Tuple(elts=list(
                     self.create_typename(param.annotation)
                     for param in sig.parameters.values()))),
             self.create_function(
                 name,
                 sig,
                 body=list(
                     lstrip(
                         (docstring and ast.Expr(value=ast.Constant(
                             value=self.format_docstring(docstring))),
                          ast.Return(value=ast.call(cfuncname, [
                              ast.rvalue(pname)
                              for pname in sig.parameters.keys()
                          ]))), lambda x: x is None)))
         ] for name, sig in self.typer.functions.items()
          for cfuncname in [f'{dllvar}.{name}']
          for docstring in [self.doxml and self.doxml.get_docs(name)]], [])
Example #5
0
def enumlstrip(iterable, pred):
    """lstrip with a pred that takes (index, value) as arguments"""
    for y in lstrip(enumerate(iterable), lambda ix: pred(*ix)):
        yield y[1]  # return value from (index, value)