(filename, args)
| 35 | file_lines_used = {} |
| 36 | |
| 37 | def code_block(filename, args): |
| 38 | assert args, "args is empty" |
| 39 | lines = LineIterator(filename) |
| 40 | |
| 41 | result = [] |
| 42 | |
| 43 | for arg in args: |
| 44 | beginning_re = re.compile(' *' + arg) |
| 45 | for line in lines: |
| 46 | if beginning_re.match(line): |
| 47 | result.append(line) |
| 48 | lines.use_line() |
| 49 | break |
| 50 | else: |
| 51 | print >>sys.stderr, "no match found for %r" % arg |
| 52 | sys.exit(1) |
| 53 | |
| 54 | space = re.match('^ *', line).group(0) |
| 55 | space_re = re.compile('^%s ' % space) |
| 56 | whitespace = False |
| 57 | for line in lines: |
| 58 | if not line.strip(): |
| 59 | whitespace = True |
| 60 | continue |
| 61 | if not space_re.match(line): |
| 62 | break |
| 63 | if whitespace: |
| 64 | result.append('\n') |
| 65 | whitespace = False |
| 66 | result.append(line) |
| 67 | lines.use_line() |
| 68 | |
| 69 | # left-justify with a four-space leader |
| 70 | return [' ' + line + '\n' |
| 71 | for line in textwrap.dedent(''.join(result)).split('\n')] |
| 72 | extractors['code_block'] = code_block |
| 73 | |
| 74 | def from_to(filename, args): |
nothing calls this directly
no test coverage detected