Example #1
0
 def parse(cls, lines):
     header = lines[0].strip()
     term, classifier = header_regex.split(header, maxsplit=1) if \
         (' :' in header) else (header, '')
     trimed_lines = trim_indent(lines[1:]) if (len(lines) > 1) else ['']
     definition = [line.rstrip() for line in trimed_lines]
     return cls(term.strip(), [classifier.strip()], definition)
Example #2
0
 def parse(cls, lines):
     header = lines[0].strip()
     term, classifier = header_regex.split(header, maxsplit=1) if \
         (' :' in header) else (header, '')
     trimed_lines = trim_indent(lines[1:]) if (len(lines) > 1) else ['']
     definition = [line.rstrip() for line in trimed_lines]
     return cls(term.strip(), [classifier.strip()], definition)
Example #3
0
    def parse(cls, lines):
        """ Parse a method definition item from a set of lines.

        Parse the method signature and definition from the list of docstring
        lines and produce a MethodItem where the `term` is the method name and
        the classifier is arguments.

        .. note:: The global indention in the definition lines is striped

        The format of the method definition item is expected to be as follows::

          +---------------------------------------------+
          | term "(" [ classifier [, classifier]* ] ")" |
          +--+--------------------------------------+---+
             | definition                           |
             | (body elements)+                     |
             +--------------------------------------+

        Arguments
        ---------
        lines :
            docstring lines of the method definition item without any empty
            lines before or after.

        Returns
        -------
        definition : MethodItem

        """
        header = lines[0].strip()
        term, classifiers, _ = signature_regex.split(header)
        classifiers = [classifiers.strip()]
        definition = trim_indent(lines[1:]) if (len(lines) > 1) else ['']
        return cls(term, classifiers, definition)
Example #4
0
    def parse(cls, lines):
        """Parse a definition item from a set of lines.

        The class method parses the definition list item from the list of
        docstring lines and produces a DefinitionItem with the term,
        classifier and the definition.

        .. note:: The global indention in the definition lines is striped.

        The term definition is assumed to be in one of the following formats::

            term
                Definition.

        ::

            term :
                Definition.

        ::

            term
                Definition, paragraph 1.

                Definition, paragraph 2.

        ::
            term:
                Definition, paragraph 1.

                Definition, paragraph 2.

        ::

            term : any text is valid here
                Definition.

        Arguments
        ---------
        lines
            docstring lines of the definition without any empty lines before or
            after.

        Returns
        -------
        definition : AnyItem

        """
        header = lines[0].strip()
        term, classifier = header_regex.split(header, maxsplit=1) if \
            (' :' in header) else (header, '')
        classifier = classifier.strip()
        classifier = [] if classifier == '' else [classifier]
        trimed_lines = trim_indent(lines[1:]) if (len(lines) > 1) else []
        definition = [line.rstrip() for line in trimed_lines]
        return cls(term.strip(), classifier, definition)
Example #5
0
    def parse(cls, lines):
        """Parse a definition item from a set of lines.

        The class method parses the definition list item from the list of
        docstring lines and produces a DefinitionItem with the term,
        classifier and the definition.

        .. note:: The global indention in the definition lines is striped

        The term definition is assumed to be in one of the following formats::

            term
                Definition.

        ::

            term
                Definition, paragraph 1.

                Definition, paragraph 2.

        ::

            term : classifier
                Definition.

        ::

            term : classifier : classifier
                Definition.

        Arguments
        ---------
        lines
            docstring lines of the definition without any empty lines before or
            after.

        Returns
        -------
        definition : DefinitionItem

        """
        header = lines[0].strip()
        components = [
            component.strip()
            for component in header.split(":") if component != '']
        term = components[0]
        if len(components) > 1:
            classifiers = components[1:]
        else:
            classifiers = []
        trimed_lines = trim_indent(lines[1:]) if (len(lines) > 1) else ['']
        definition = [line.rstrip() for line in trimed_lines]
        return Item(term.strip(), classifiers, definition)