Exemplo n.º 1
0
Arquivo: fields.py Projeto: 5n1p/enaml
    def to_rst(self, indent=4, prefix=''):
        """ Outputs field in rst using as items in an list.

        Arguments
        ---------
        indent : int
            The indent to use for the decription block.

        prefix : str
            The prefix to use. For example if the item is part of a numbered
            list then ``prefix='# '``.

        Example
        -------


        Note
        ----
        The field descrption is reformated into a line.

        """
        indent_str = ' ' * indent
        rst_pattern = '{0}{1}**{2}**{3}' if is_empty(self.desc[0]) else \
                       '{0}{1}**{2}** -- {3}'
        description = '' if is_empty(self.desc[0]) else \
                      ' '.join(remove_indent(self.desc))
        return [rst_pattern.format(indent_str, prefix, self.name, description)]
Exemplo n.º 2
0
    def get_next_block(self):
        """ Get the next item block from the docstring.

        The method reads the next item block in the docstring. The first line
        is assumed to be the DefinitionItem header and the following lines to
        belong to the definition::

            <header line>
                <definition>

        The end of the field is designated by a line with the same indent
        as the field header or two empty lines are found in sequence.

        """
        item_header = self.pop()
        sub_indent = get_indent(item_header) + ' '
        block = [item_header]
        while not self.eod:
            peek_0 = self.peek()
            peek_1 = self.peek(1)
            if is_empty(peek_0) and not peek_1.startswith(sub_indent) \
                    or not is_empty(peek_0) \
                    and not peek_0.startswith(sub_indent):
                break
            else:
                line = self.pop()
                block += [line.rstrip()]
        return block
Exemplo n.º 3
0
    def to_rst(self, indent=4, prefix=''):
        """ Outputs field in rst using as items in an list.

        Arguments
        ---------
        indent : int
            The indent to use for the decription block.

        prefix : str
            The prefix to use. For example if the item is part of a numbered
            list then ``prefix='# '``.

        Example
        -------


        Note
        ----
        The field descrption is reformated into a line.

        """
        indent_str = ' ' * indent
        rst_pattern = '{0}{1}**{2}**{3}' if is_empty(self.desc[0]) else \
                       '{0}{1}**{2}** -- {3}'
        description = '' if is_empty(self.desc[0]) else \
                      ' '.join(remove_indent(self.desc))
        return [rst_pattern.format(indent_str, prefix, self.name, description)]
Exemplo n.º 4
0
Arquivo: fields.py Projeto: 5n1p/enaml
 def to_rst(self, indent=4, prefix=''):
     indent_str = ' ' * indent
     _type = '' if self.signature == '' else '({0})'.format(self.signature)
     rst_pattern = '{0}{1}**{2}** {3}{4}' if is_empty(self.desc[0]) else \
                    '{0}{1}**{2}** {3} -- {4}'
     description = '' if is_empty(self.desc[0]) else \
                 ' '.join(remove_indent(self.desc))
     return [rst_pattern.format(indent_str, prefix, self.name, _type, description)]
Exemplo n.º 5
0
    def get_section_paragraphs(self):
        """ Get the paragraphs in the section designated by two empty lines.

        """
        lines = []
        while (not self.eod) and not \
            (is_empty(self.peek()) and is_empty(self.peek(1))):
            line = self.pop()
            lines.append(line)
        return lines
Exemplo n.º 6
0
    def get_section_paragraphs(self):
        """ Get the paragraphs in the section designated by two empty lines.

        """
        lines = []
        while (not self.eod) and not \
            (is_empty(self.peek()) and is_empty(self.peek(1))):
            line = self.pop()
            lines.append(line)
        return lines
Exemplo n.º 7
0
 def to_rst(self, indent=4, prefix=''):
     indent_str = ' ' * indent
     _type = '' if self.signature == '' else '({0})'.format(self.signature)
     rst_pattern = '{0}{1}**{2}** {3}{4}' if is_empty(self.desc[0]) else \
                    '{0}{1}**{2}** {3} -- {4}'
     description = '' if is_empty(self.desc[0]) else \
                 ' '.join(remove_indent(self.desc))
     return [
         rst_pattern.format(indent_str, prefix, self.name, _type,
                            description)
     ]
Exemplo n.º 8
0
    def get_next_block(self):
        """ Get the next field block from the docstring.

        The method reads the next block in the docstring. The first line
        assumed to be the field header and the following lines to belong to
        the description::

            <header line>
                <descrition>

        The end of the field is designated by a line with the same indent
        as the field header or two empty lines are found in sequence. Thus,
        there are two valid field layouts:

        1. No lines between fields::

            <field1>
                <description1>
            <fieldd2>
                <description2>

        2. One line between fields::

            <field1>
                <description1>

            <field2>
                <description2>

        """
        start = self.index
        field_header = self.read()
        indent = get_indent(field_header) + ' '
        field = [field_header]
        while (not self.eol):
            peek_0 = self.peek()
            peek_1 = self.peek(1)
            if (is_empty(peek_0) and (not peek_1.startswith(indent))) \
                or \
                ((not is_empty(peek_0)) and (not peek_0.startswith(indent))):
                break
            else:
                line = self.read()
                field.append(line.rstrip())

        self.remove_lines(start, len(field))
        self.index = start
        return field
Exemplo n.º 9
0
    def get_next_block(self):
        """ Get the next field block from the docstring.

        The method reads the next block in the docstring. The first line
        assumed to be the field header and the following lines to belong to
        the description::

            <header line>
                <descrition>

        The end of the field is designated by a line with the same indent
        as the field header or two empty lines are found in sequence. Thus,
        there are two valid field layouts:

        1. No lines between fields::

            <field1>
                <description1>
            <fieldd2>
                <description2>

        2. One line between fields::

            <field1>
                <description1>

            <field2>
                <description2>

        """
        start = self.index
        field_header = self.read()
        indent = get_indent(field_header) + ' '
        field = [field_header]
        while (not self.eol):
            peek_0 = self.peek()
            peek_1 = self.peek(1)
            if (is_empty(peek_0) and (not peek_1.startswith(indent))) \
                or \
                ((not is_empty(peek_0)) and (not peek_0.startswith(indent))):
                break
            else:
                line = self.read()
                field.append(line.rstrip())

        self.remove_lines(start, len(field))
        self.index = start
        return field
Exemplo n.º 10
0
    def to_rst(self, indent=4):
        """ Outputs field in rst using the ``:param:`` role.

        Arguments
        ---------
        indent : int
            The indent to use for the decription block.

        Example
        -------

        >>> Field('indent', 'int', 'The indent to use for the decription block.')
        >>> print Field.to_rst()
        :param indent: The indent to use for the description block
        :type indent: int

        """
        lines = []
        _type = self.signature
        annotation = '{0}    :annotation: = {1}'
        type_str = '' if is_empty(_type) else annotation.format(
            indent * ' ', _type)
        directive = '{0}.. attribute:: {1}'
        lines += [directive.format(indent * ' ', self.name), type_str]
        if type_str != '':
            lines.append('')
        lines += self.desc
        lines.append('')
        return lines
Exemplo n.º 11
0
Arquivo: fields.py Projeto: 5n1p/enaml
    def to_rst(self, indent=4):
        """ Outputs field in rst using the ``:param:`` role.

        Arguments
        ---------
        indent : int
            The indent to use for the decription block.

        Example
        -------

        >>> Field('indent', 'int', 'The indent to use for the decription block.')
        >>> print Field.to_rst()
        :param indent: The indent to use for the description block
        :type indent: int

        """
        lines = []
        _type = self.signature
        annotation = '{0}    :annotation: = {1}'
        type_str = '' if is_empty(_type) else annotation.format(indent * ' ', _type)
        directive = '{0}.. attribute:: {1}'
        lines += [directive.format(indent * ' ', self.name), type_str]
        if type_str != '':
            lines.append('')
        lines += self.desc
        lines.append('')
        return lines
Exemplo n.º 12
0
    def get_next_paragraph(self):
        """ Get the next paragraph designated by an empty line.

        """
        lines = []
        while (not self.eod) and (not is_empty(self.peek())):
            line = self.pop()
            lines.append(line)
        return lines
Exemplo n.º 13
0
    def seek_to_next_non_empty_line(self):
        """ Goto the next non_empty line.

        """
        docstring = self.docstring
        for line in docstring[self.index:]:
            if not is_empty(line):
                break
            self.index += 1
Exemplo n.º 14
0
    def get_next_paragraph(self):
        """ Get the next paragraph designated by an empty line.

        """
        docstring = self.docstring
        lines = []
        start = self.index
        while (not self.eol) and (not is_empty(self.peek())):
            line = self.read()
            lines.append(line)
        del docstring[start:self.index]
        return lines
Exemplo n.º 15
0
    def get_next_paragraph(self):
        """ Get the next paragraph designated by an empty line.

        """
        docstring = self.docstring
        lines = []
        start = self.index
        while (not self.eol) and (not is_empty(self.peek())):
            line = self.read()
            lines.append(line)
        del docstring[start:self.index]
        return lines
Exemplo n.º 16
0
    def remove_if_empty(self, index=None):
        """ Remove the line from the docstring if it is empty.

        """
        if is_empty(self.docstring[index]):
            self.remove_lines(index)