def parse_header(self, line): try: super(ComplexDirective, self).add_line(line) except NodeCompleteError: pass if ">" in line: header_str, remainder = line.split(">", 1) if remainder.strip() != "": raise InvalidLineError( "Directive header has an extraneous tail: %s" % line) else: header_str = line header_str = header_str.lstrip() if header_str and header_str.startswith( "<") and self.header.name is None: header_str = header_str[1:] if header_str and "<" in header_str: raise InvalidLineError( "Angle brackets not allowed in complex directive header. Received: %s" % line) if header_str: try: self.header.parse_directive_header(header_str) except (NodeCompleteError, DirectiveError) as e: raise InvalidLineError(str(e)) if ">" in line: self.header.complete = True
def add_line(self, line, depth=0): # base case if self.complete: raise NodeCompleteError("Can't add lines to a complete Node.") # first we need a header if not self.header.complete: self.parse_header(line) # then the body elif not self.body.stable and not re.match("\s*<\/%s>\s*$" % self.name, line): self.body.add_line(line, depth + 1) # check for the closing tag / tail elif re.match("\s*<\/%s>\s*$" % self.name, line): try: self.body.complete = True self.tail = line self.tailmatch = True except NodeCompleteError as err: self.body.add_line(line, depth + 1) # if we haven't found the closing tag / tail, keep adding to the body elif not self.body.complete: self.body.add_line(line, depth + 1) else: raise InvalidLineError("Expecting closing tag. Got: %s" % line)
def add_line(self, line): if "\n" in line: raise InvalidLineError("Lines cannot contain newlines.") if self.complete: raise NodeCompleteError(line) matches = None if isinstance(self.match_regexp, list): for regexp in self.match_regexp: matches = re.match(regexp, line) if matches: break else: matches = re.match(self.match_regexp, line) if matches: self.matches = matches.groupdict() self.lines.append(line) if not line.endswith("\\"): self.complete = True
def add_line(self, line): try: self.parse_directive_header(line) except DirectiveError as e: raise InvalidLineError(str(e)) super(GenericDirective, self).add_line(line)
def add_line(self, line): if line.endswith("\\"): raise InvalidLineError( "Blank lines cannot have line continuations.") super(BlankNode, self).add_line(line) self._content = ""
def add_line(self, line): if line.endswith("\\"): raise InvalidLineError("Comments cannot have line continuations.") super(CommentNode, self).add_line(line) self._content = self.comment