def _insert_after(self, text=None, style=None):
    p = OxmlElement('w:p')
    self._p.addnext(p)
    paragraph = Paragraph(p, self._parent)
    if text:
        paragraph.add_run(text)
    if style is not None:
        paragraph.style = style
    return paragraph
示例#2
0
 def it_can_set_its_paragraph_style(self):
     cases = (
         ('foobar', 'foobar'),
         ('Normal', None),
     )
     for style, expected_setting in cases:
         p_elm = Mock(name='p_elm')
         p = Paragraph(p_elm)
         p.style = style
         assert p_elm.style == expected_setting
示例#3
0
 def it_can_set_its_paragraph_style(self):
     cases = (
         ('foobar', 'foobar'),
         ('Normal', None),
     )
     for style, expected_setting in cases:
         p_elm = Mock(name='p_elm')
         p = Paragraph(p_elm)
         p.style = style
         assert p_elm.style == expected_setting
示例#4
0
 def it_knows_its_paragraph_style(self):
     cases = (
         (Mock(name='p_elm', style='foobar'), 'foobar'),
         (Mock(name='p_elm', style=None), 'Normal'),
     )
     for p_elm, expected_style in cases:
         p = Paragraph(p_elm)
         assert p.style == expected_style
示例#5
0
def export_to_word(vuln_info, output_file_name, template=None):
    """
    Export Vulnerability info to word file.
    
    :param vuln_info: Vulnerability list info
    :type vuln_info: list(Vulnerability)
    
    :param output_file_name: filename to save word file,
    :type output_file_name: str

    :param template: path to template file.
    :type template: str

    :raises: TypeError
    """
    if not isinstance(vuln_info, list):
        raise TypeError("Expected list, got '%s' instead" % type(vuln_info))
    else:
        for x in vuln_info:
            if not isinstance(x, Vulnerability):
                raise TypeError("Expected Vulnerability, got '%s' instead" %
                                type(x))
    if not isinstance(output_file_name, str):
        raise TypeError("Expected basestring, got '%s' instead" %
                        type(output_file_name))
    else:
        if not output_file_name:
            raise ValueError("output_file_name must has a valid value.")
    if template is not None:
        if not isinstance(template, str):
            raise TypeError("Expected basestring, got '%s' instead" %
                            type(template))
        if not template or not os.path.exists(template):
            raise ValueError("Template must has a valid value.")

    if template:
        doc_template = Document(template)

        # Get mark where insert tables
        p = paragraph_search("#####TABLE####", doc_template)
        if p is None:
            raise IOError(
                "Incompatible document format. Can't find '#####TABLE####' in document."
            )
    else:
        p = Paragraph("")

    # Add table information
    create_tables(vuln_info, p)

    # Save doc
    doc = Document()
    # doc.add_paragraph(p)
    doc.save(output_file_name)
示例#6
0
def given_a_paragraph_with_content_and_formatting(context):
    p_xml = """\
        <w:p %s>
          <w:pPr>
            <w:pStyle w:val="%s"/>
          </w:pPr>
          <w:r>
            <w:t>foobar</w:t>
          </w:r>
        </w:p>""" % (nsdecls('w'), TEST_STYLE)
    p = parse_xml(p_xml)
    context.paragraph = Paragraph(p, None)
示例#7
0
 def text_prop_fixture(self):
     p = (a_p().with_nsdecls().with_child(an_r().with_child(
         a_t().with_text('foo'))).with_child(an_r().with_child(
             a_t().with_text(' de bar')))).element
     paragraph = Paragraph(p)
     return paragraph, 'foo de bar'
示例#8
0
 def text_set_fixture(self):
     paragraph = Paragraph(element('w:p'), None)
     paragraph.add_run('must not appear in result')
     new_text_value = 'foo\tbar\rbaz\n'
     expected_text_value = 'foo\tbar\nbaz\n'
     return paragraph, new_text_value, expected_text_value
示例#9
0
 def text_set_fixture(self):
     paragraph = Paragraph(element('w:p'), None)
     paragraph.add_run('must not appear in result')
     new_text_value = 'foo\tbar\rbaz\n'
     expected_text_value = 'foo\tbar\nbaz\n'
     return paragraph, new_text_value, expected_text_value
示例#10
0
 def text_get_fixture(self, request):
     p_cxml, expected_text_value = request.param
     paragraph = Paragraph(element(p_cxml), None)
     return paragraph, expected_text_value
示例#11
0
 def style_set_fixture(self, request):
     p_cxml, new_style_value, expected_cxml = request.param
     paragraph = Paragraph(element(p_cxml), None)
     expected_xml = xml(expected_cxml)
     return paragraph, new_style_value, expected_xml
示例#12
0
 def style_get_fixture(self, request):
     p_cxml, expected_style = request.param
     paragraph = Paragraph(element(p_cxml), None)
     return paragraph, expected_style
示例#13
0
 def insert_before_fixture(self, request):
     body_cxml, text, style, expected_cxml = request.param
     body = element(body_cxml)
     paragraph = Paragraph(body.find(qn('w:p')), None)
     expected_xml = xml(expected_cxml)
     return paragraph, text, style, body, expected_xml
示例#14
0
 def clear_fixture(self, request):
     initial_cxml, expected_cxml = request.param
     paragraph = Paragraph(element(initial_cxml), None)
     expected_xml = xml(expected_cxml)
     return paragraph, expected_xml
示例#15
0
 def alignment_set_fixture(self, request):
     initial_cxml, new_alignment_value, expected_cxml = request.param
     paragraph = Paragraph(element(initial_cxml), None)
     expected_xml = xml(expected_cxml)
     return paragraph, new_alignment_value, expected_xml
示例#16
0
 def paragraph(self, request):
     p = a_p().with_nsdecls().element
     return Paragraph(p)
示例#17
0
 def runs_fixture(self, p_, Run_, r_, r_2_, runs_):
     paragraph = Paragraph(p_)
     run_, run_2_ = runs_
     return paragraph, Run_, r_, r_2_, run_, run_2_
示例#18
0
 def add_run_fixture(self, request):
     before_cxml, text, style, after_cxml = request.param
     paragraph = Paragraph(element(before_cxml), None)
     expected_xml = xml(after_cxml)
     return paragraph, text, style, expected_xml
示例#19
0
 def paragraphs(self):
     return [Paragraph(parent=self, p=p) for p in self._tb.p_lst]
示例#20
0
 def alignment_get_fixture(self, request):
     cxml, expected_alignment_value = request.param
     paragraph = Paragraph(element(cxml), None)
     return paragraph, expected_alignment_value