class Case: def __init__(self, file_name): self.attribs = dict(meta=None, regions=dict()) with open(file_name) as handle: self.attribs = self._parse(handle.read()) def _parse(self, source): case = dict(meta=None, regions=dict()) region_name = None region_start = 0 lines = source.split('\n') for comment in find_comments(source): meta = parse_yaml(comment['source']) if meta: case['meta'] = meta continue match = regionStartPattern.match(comment['source']) if match: if region_name: case['regions'][region_name] = \ '\n'.join(lines[region_start:comment['lineno'] - 1]) region_name = match.group(1) region_start = comment['lineno'] continue if region_name: case['regions'][region_name] = \ '\n'.join(lines[region_start:-1]) return case
def _parse(self, source): case = dict(meta=None, regions=dict()) region_name = None region_start = 0 lines = source.split("\n") for comment in find_comments(source): meta = parse_yaml(comment["source"]) if meta: case["meta"] = meta continue match = regionStartPattern.match(comment["source"]) if match: if region_name: case["regions"][region_name] = "\n".join(lines[region_start : comment["lineno"] - 1]) region_name = match.group(1) region_start = comment["lineno"] continue if region_name: case["regions"][region_name] = "\n".join(lines[region_start:-1]) return case
def _parse(self): for comment in find_comments(self.source): meta = parse_yaml(comment['source']) # Do not emit the template's frontmatter in generated files # (file-specific frontmatter is generated as part of the rendering # process) if meta: self.attribs['meta'] = meta self._remove_comment(comment) continue # Do not emit license information in generated files (recognized as # comments preceeding the YAML frontmatter) if not self.attribs.get('meta'): self._remove_comment(comment) continue match = interpolatePattern.match(comment['source']) if match == None: continue self.regions.insert(0, dict(name=match.group(1), **comment))
def _parse(self): for comment in find_comments(self.source): meta = parse_yaml(comment['source']) if meta: self.attribs['meta'] = meta break