Esempio n. 1
0
 def setUp(self):
     tr_xml = (
         '<a:tr %s h="370840"><a:tc><a:txBody><a:p/></a:txBody></a:tc><a:t'
         'c><a:txBody><a:p/></a:txBody></a:tc></a:tr>' % nsdecls('a')
     )
     test_tr_elm = parse_xml_bytes(tr_xml)
     self.cells = _CellCollection(test_tr_elm, None)
Esempio n. 2
0
 def setUp(self):
     tbl_xml = (
         '<a:tbl %s><a:tblGrid><a:gridCol w="3048000"/><a:gridCol w="30480'
         '00"/></a:tblGrid></a:tbl>' % nsdecls('a')
     )
     test_tbl_elm = parse_xml_bytes(tbl_xml)
     self.columns = _ColumnCollection(test_tbl_elm, Mock(name='table'))
Esempio n. 3
0
 def setUp(self):
     tr_xml = (
         '<a:tr %s h="370840"><a:tc><a:txBody><a:p/></a:txBody></a:tc><a:t'
         'c><a:txBody><a:p/></a:txBody></a:tc></a:tr>' % nsdecls('a')
     )
     test_tr_elm = parse_xml_bytes(tr_xml)
     self.cells = _CellCollection(test_tr_elm, None)
Esempio n. 4
0
    def new_tbl(rows, cols, width, height, tableStyleId=None):
        """Return a new ``<p:tbl>`` element tree"""
        # working hypothesis is this is the default table style GUID
        if tableStyleId is None:
            tableStyleId = '{5C22544A-7EE6-4342-B048-85BDC9FD1C3A}'

        xml = CT_Table._tbl_tmpl % (tableStyleId)
        tbl = parse_xml_bytes(xml)

        # add specified number of rows and columns
        rowheight = height/rows
        colwidth = width/cols

        for col in range(cols):
            # adjust width of last col to absorb any div error
            if col == cols-1:
                colwidth = width - ((cols-1) * colwidth)
            SubElement(tbl.tblGrid, 'a:gridCol', w=str(colwidth))

        for row in range(rows):
            # adjust height of last row to absorb any div error
            if row == rows-1:
                rowheight = height - ((rows-1) * rowheight)
            tr = SubElement(tbl, 'a:tr', h=str(rowheight))
            for col in range(cols):
                tr.append(CT_TableCell.new_tc())

        objectify.deannotate(tbl, cleanup_namespaces=True)
        return tbl
Esempio n. 5
0
 def setUp(self):
     tr_xml = (
         '<a:tr %s h="370840"><a:tc><a:txBody><a:p/></a:txBody></a:tc><a:t'
         'c><a:txBody><a:p/></a:txBody></a:tc></a:tr>' % nsdecls('a')
     )
     test_tr_elm = parse_xml_bytes(tr_xml)
     self.row = _Row(test_tr_elm, Mock(name='table'))
Esempio n. 6
0
 def setUp(self):
     tbl_xml = (
         '<a:tbl %s><a:tblGrid><a:gridCol w="3048000"/><a:gridCol w="30480'
         '00"/></a:tblGrid></a:tbl>' % nsdecls('a')
     )
     test_tbl_elm = parse_xml_bytes(tbl_xml)
     self.columns = _ColumnCollection(test_tbl_elm, Mock(name='table'))
Esempio n. 7
0
    def new_placeholder_sp(id_, name, ph_type, orient, sz, idx):
        """
        Return a new ``<p:sp>`` element tree configured as a placeholder
        shape.
        """
        xml = CT_Shape._ph_sp_tmpl % (id_, name)
        sp = parse_xml_bytes(xml)

        # placeholder shapes get a "no group" lock
        SubElement(sp.nvSpPr.cNvSpPr, 'a:spLocks')
        sp.nvSpPr.cNvSpPr[qn('a:spLocks')].set('noGrp', '1')

        # placeholder (ph) element attributes values vary by type
        ph = SubElement(sp.nvSpPr.nvPr, 'p:ph')
        if ph_type != PH_TYPE_OBJ:
            ph.set('type', ph_type)
        if orient != PH_ORIENT_HORZ:
            ph.set('orient', orient)
        if sz != PH_SZ_FULL:
            ph.set('sz', sz)
        if idx != 0:
            ph.set('idx', str(idx))

        placeholder_types_that_have_a_text_frame = (
            PH_TYPE_TITLE, PH_TYPE_CTRTITLE, PH_TYPE_SUBTITLE, PH_TYPE_BODY,
            PH_TYPE_OBJ)

        if ph_type in placeholder_types_that_have_a_text_frame:
            sp.append(CT_TextBody.new_txBody())

        objectify.deannotate(sp, cleanup_namespaces=True)
        return sp
Esempio n. 8
0
 def setUp(self):
     tr_xml = (
         '<a:tr %s h="370840"><a:tc><a:txBody><a:p/></a:txBody></a:tc><a:t'
         'c><a:txBody><a:p/></a:txBody></a:tc></a:tr>' % nsdecls('a')
     )
     test_tr_elm = parse_xml_bytes(tr_xml)
     self.row = _Row(test_tr_elm, Mock(name='table'))
Esempio n. 9
0
 def setUp(self):
     tbl_xml = (
         '<a:tbl %s><a:tr h="370840"><a:tc><a:txBody><a:p/></a:txBody></a:'
         'tc><a:tc><a:txBody><a:p/></a:txBody></a:tc></a:tr><a:tr h="37084'
         '0"><a:tc><a:txBody><a:p/></a:txBody></a:tc><a:tc><a:txBody><a:p/'
         '></a:txBody></a:tc></a:tr></a:tbl>' % nsdecls('a')
     )
     test_tbl_elm = parse_xml_bytes(tbl_xml)
     self.rows = _RowCollection(test_tbl_elm, Mock(name='table'))
Esempio n. 10
0
 def setUp(self):
     tbl_xml = (
         '<a:tbl %s><a:tr h="370840"><a:tc><a:txBody><a:p/></a:txBody></a:'
         'tc><a:tc><a:txBody><a:p/></a:txBody></a:tc></a:tr><a:tr h="37084'
         '0"><a:tc><a:txBody><a:p/></a:txBody></a:tc><a:tc><a:txBody><a:p/'
         '></a:txBody></a:tc></a:tr></a:tbl>' % nsdecls('a')
     )
     test_tbl_elm = parse_xml_bytes(tbl_xml)
     self.rows = _RowCollection(test_tbl_elm, Mock(name='table'))
Esempio n. 11
0
 def new_textbox_sp(id_, name, left, top, width, height):
     """
     Return a new ``<p:sp>`` element tree configured as a base textbox
     shape.
     """
     xml = CT_Shape._textbox_sp_tmpl % (id_, name, left, top, width, height)
     sp = parse_xml_bytes(xml)
     objectify.deannotate(sp, cleanup_namespaces=True)
     return sp
Esempio n. 12
0
 def it_raises_when_shape_type_called_on_unrecognized_shape(self):
     xml = (
         '<p:sp xmlns:p="http://schemas.openxmlformats.org/presentationml/'
         '2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/'
         '2006/main"><p:nvSpPr><p:cNvPr id="9" name="Unknown Shape Type 8"'
         '/><p:cNvSpPr/><p:nvPr/></p:nvSpPr><p:spPr/></p:sp>')
     sp = parse_xml_bytes(xml)
     shape = Shape(sp, None)
     # verify -----------------------
     with pytest.raises(NotImplementedError):
         shape.shape_type
Esempio n. 13
0
    def new_pic(id_, name, desc, rId, left, top, width, height):
        """
        Return a new ``<p:pic>`` element tree configured with the supplied
        parameters.
        """
        xml = CT_Picture._pic_tmpl % (id_, name, desc, rId,
                                      left, top, width, height)
        pic = parse_xml_bytes(xml)

        objectify.deannotate(pic, cleanup_namespaces=True)
        return pic
Esempio n. 14
0
    def new_graphicFrame(id_, name, left, top, width, height):
        """
        Return a new ``<p:graphicFrame>`` element tree suitable for containing
        a table or chart. Note that a graphicFrame element is not a valid
        shape until it contains a graphical object such as a table.
        """
        xml = CT_GraphicalObjectFrame._graphicFrame_tmpl % (
            id_, name, left, top, width, height)
        graphicFrame = parse_xml_bytes(xml)

        objectify.deannotate(graphicFrame, cleanup_namespaces=True)
        return graphicFrame
Esempio n. 15
0
 def it_raises_when_shape_type_called_on_unrecognized_shape(self):
     xml = (
         '<p:sp xmlns:p="http://schemas.openxmlformats.org/presentationml/'
         '2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/'
         '2006/main"><p:nvSpPr><p:cNvPr id="9" name="Unknown Shape Type 8"'
         '/><p:cNvSpPr/><p:nvPr/></p:nvSpPr><p:spPr/></p:sp>'
     )
     sp = parse_xml_bytes(xml)
     shape = Shape(sp, None)
     # verify -----------------------
     with pytest.raises(NotImplementedError):
         shape.shape_type
Esempio n. 16
0
 def but_accepts_unicode_providing_there_is_no_encoding_declaration(self):
     non_enc_decl = '<?xml version="1.0" standalone="yes"?>'
     enc_decl = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
     xml_body = "<foo><bar>føøbår</bar></foo>"
     # unicode body by itself doesn't raise
     parse_xml_bytes(xml_body)
     # adding XML decl without encoding attr doesn't raise either
     xml_text = "%s\n%s" % (non_enc_decl, xml_body)
     parse_xml_bytes(xml_text)
     # but adding encoding in the declaration raises ValueError
     xml_text = "%s\n%s" % (enc_decl, xml_body)
     with pytest.raises(ValueError):
         parse_xml_bytes(xml_text)
Esempio n. 17
0
 def but_accepts_unicode_providing_there_is_no_encoding_declaration(self):
     non_enc_decl = '<?xml version="1.0" standalone="yes"?>'
     enc_decl = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
     xml_body = '<foo><bar>føøbår</bar></foo>'
     # unicode body by itself doesn't raise
     parse_xml_bytes(xml_body)
     # adding XML decl without encoding attr doesn't raise either
     xml_text = '%s\n%s' % (non_enc_decl, xml_body)
     parse_xml_bytes(xml_text)
     # but adding encoding in the declaration raises ValueError
     xml_text = '%s\n%s' % (enc_decl, xml_body)
     with pytest.raises(ValueError):
         parse_xml_bytes(xml_text)
Esempio n. 18
0
 def p_with_text(self, p_with_text_xml):
     return parse_xml_bytes(p_with_text_xml)
Esempio n. 19
0
 def cell(self):
     return parse_xml_bytes(test_table_xml.cell)
Esempio n. 20
0
 def cell_with_margins(self):
     return parse_xml_bytes(test_table_xml.cell_with_margins)
Esempio n. 21
0
 def textbox(self):
     return parse_xml_bytes(test_shape_xml.textbox)
Esempio n. 22
0
 def placeholder(self):
     return parse_xml_bytes(test_shape_xml.placeholder)
Esempio n. 23
0
 def autoshape(self):
     return parse_xml_bytes(test_shape_xml.autoshape)
Esempio n. 24
0
 def element(self):
     """Return element based on XML generated by builder"""
     return parse_xml_bytes(self.xml)
Esempio n. 25
0
 def r(self, r_xml):
     return parse_xml_bytes(r_xml)
Esempio n. 26
0
 def p_with_text(self, p_with_text_xml):
     return parse_xml_bytes(p_with_text_xml)
Esempio n. 27
0
 def it_prefers_to_parse_bytes(self, xml_bytes):
     parse_xml_bytes(xml_bytes)
Esempio n. 28
0
 def it_uses_oxml_configured_parser_to_parse_xml(
         self, mock_xml_bytes, fromstring, mock_oxml_parser):
     element = parse_xml_bytes(mock_xml_bytes)
     fromstring.assert_called_once_with(mock_xml_bytes, mock_oxml_parser)
     assert element is fromstring.return_value
Esempio n. 29
0
 def element(self):
     """Return element based on XML generated by builder"""
     return parse_xml_bytes(self.xml)
Esempio n. 30
0
 def cell_with_margins(self):
     return parse_xml_bytes(test_table_xml.cell_with_margins)
Esempio n. 31
0
 def element(self):
     """
     Element parsed from XML generated by builder in current state
     """
     elm = parse_xml_bytes(self.xml())
     return elm
Esempio n. 32
0
 def isolated_tbl_with_true_props(self):
     return parse_xml_bytes(test_table_xml.isolated_tbl_with_true_props)
Esempio n. 33
0
 def load(cls, partname, content_type, blob, package):
     slide_elm = parse_xml_bytes(blob)
     slide = cls(partname, content_type, slide_elm, package)
     return slide
Esempio n. 34
0
 def new_coreProperties():
     """Return a new ``<cp:coreProperties>`` element"""
     xml = CT_CoreProperties._coreProperties_tmpl
     coreProperties = parse_xml_bytes(xml)
     return coreProperties
Esempio n. 35
0
 def top_aligned_cell(self):
     return parse_xml_bytes(test_table_xml.top_aligned_cell)
Esempio n. 36
0
 def empty_spTree(self):
     return parse_xml_bytes(test_shape_xml.empty_spTree)
Esempio n. 37
0
 def isolated_tbl_with_true_props(self):
     return parse_xml_bytes(test_table_xml.isolated_tbl_with_true_props)
Esempio n. 38
0
 def rounded_rectangle(self):
     return parse_xml_bytes(test_shape_xml.rounded_rectangle)
Esempio n. 39
0
 def isolated_tbl(self):
     return parse_xml_bytes(test_table_xml.isolated_tbl)
Esempio n. 40
0
 def new_txBody():
     """Return a new ``<p:txBody>`` element tree"""
     xml = CT_TextBody._txBody_tmpl
     txBody = parse_xml_bytes(xml)
     objectify.deannotate(txBody, cleanup_namespaces=True)
     return txBody
Esempio n. 41
0
 def new_tc():
     """Return a new ``<a:tc>`` element tree"""
     xml = CT_TableCell._tc_tmpl
     tc = parse_xml_bytes(xml)
     objectify.deannotate(tc, cleanup_namespaces=True)
     return tc
Esempio n. 42
0
 def setUp(self):
     gridCol_xml = '<a:gridCol %s w="3048000"/>' % nsdecls('a')
     test_gridCol_elm = parse_xml_bytes(gridCol_xml)
     self.column = _Column(test_gridCol_elm, Mock(name='table'))
Esempio n. 43
0
 def autoshape(self):
     return parse_xml_bytes(test_shape_xml.autoshape)
Esempio n. 44
0
 def r(self, r_xml):
     return parse_xml_bytes(r_xml)
Esempio n. 45
0
 def empty_spTree(self):
     return parse_xml_bytes(test_shape_xml.empty_spTree)
Esempio n. 46
0
 def cell(self):
     return parse_xml_bytes(test_table_xml.cell)
Esempio n. 47
0
 def placeholder(self):
     return parse_xml_bytes(test_shape_xml.placeholder)
Esempio n. 48
0
 def isolated_tbl(self):
     return parse_xml_bytes(test_table_xml.isolated_tbl)
Esempio n. 49
0
 def rounded_rectangle(self):
     return parse_xml_bytes(test_shape_xml.rounded_rectangle)
Esempio n. 50
0
 def top_aligned_cell(self):
     return parse_xml_bytes(test_table_xml.top_aligned_cell)
Esempio n. 51
0
 def textbox(self):
     return parse_xml_bytes(test_shape_xml.textbox)
Esempio n. 52
0
 def element(self):
     """
     Element parsed from XML generated by builder in current state
     """
     elm = parse_xml_bytes(self.xml())
     return elm
Esempio n. 53
0
 def setUp(self):
     gridCol_xml = '<a:gridCol %s w="3048000"/>' % nsdecls('a')
     test_gridCol_elm = parse_xml_bytes(gridCol_xml)
     self.column = _Column(test_gridCol_elm, Mock(name='table'))