Ejemplo 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)
Ejemplo 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'))
Ejemplo 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)
Ejemplo 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
Ejemplo 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'))
Ejemplo 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'))
Ejemplo 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
Ejemplo 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'))
Ejemplo 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'))
Ejemplo 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'))
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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)
Ejemplo 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)
Ejemplo n.º 18
0
 def p_with_text(self, p_with_text_xml):
     return parse_xml_bytes(p_with_text_xml)
Ejemplo n.º 19
0
 def cell(self):
     return parse_xml_bytes(test_table_xml.cell)
Ejemplo n.º 20
0
 def cell_with_margins(self):
     return parse_xml_bytes(test_table_xml.cell_with_margins)
Ejemplo n.º 21
0
 def textbox(self):
     return parse_xml_bytes(test_shape_xml.textbox)
Ejemplo n.º 22
0
 def placeholder(self):
     return parse_xml_bytes(test_shape_xml.placeholder)
Ejemplo n.º 23
0
 def autoshape(self):
     return parse_xml_bytes(test_shape_xml.autoshape)
Ejemplo n.º 24
0
 def element(self):
     """Return element based on XML generated by builder"""
     return parse_xml_bytes(self.xml)
Ejemplo n.º 25
0
 def r(self, r_xml):
     return parse_xml_bytes(r_xml)
Ejemplo n.º 26
0
 def p_with_text(self, p_with_text_xml):
     return parse_xml_bytes(p_with_text_xml)
Ejemplo n.º 27
0
 def it_prefers_to_parse_bytes(self, xml_bytes):
     parse_xml_bytes(xml_bytes)
Ejemplo 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
Ejemplo n.º 29
0
 def element(self):
     """Return element based on XML generated by builder"""
     return parse_xml_bytes(self.xml)
Ejemplo n.º 30
0
 def cell_with_margins(self):
     return parse_xml_bytes(test_table_xml.cell_with_margins)
Ejemplo n.º 31
0
 def element(self):
     """
     Element parsed from XML generated by builder in current state
     """
     elm = parse_xml_bytes(self.xml())
     return elm
Ejemplo n.º 32
0
 def isolated_tbl_with_true_props(self):
     return parse_xml_bytes(test_table_xml.isolated_tbl_with_true_props)
Ejemplo 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
Ejemplo n.º 34
0
 def new_coreProperties():
     """Return a new ``<cp:coreProperties>`` element"""
     xml = CT_CoreProperties._coreProperties_tmpl
     coreProperties = parse_xml_bytes(xml)
     return coreProperties
Ejemplo n.º 35
0
 def top_aligned_cell(self):
     return parse_xml_bytes(test_table_xml.top_aligned_cell)
Ejemplo n.º 36
0
 def empty_spTree(self):
     return parse_xml_bytes(test_shape_xml.empty_spTree)
Ejemplo n.º 37
0
 def isolated_tbl_with_true_props(self):
     return parse_xml_bytes(test_table_xml.isolated_tbl_with_true_props)
Ejemplo n.º 38
0
 def rounded_rectangle(self):
     return parse_xml_bytes(test_shape_xml.rounded_rectangle)
Ejemplo n.º 39
0
 def isolated_tbl(self):
     return parse_xml_bytes(test_table_xml.isolated_tbl)
Ejemplo 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
Ejemplo 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
Ejemplo 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'))
Ejemplo n.º 43
0
 def autoshape(self):
     return parse_xml_bytes(test_shape_xml.autoshape)
Ejemplo n.º 44
0
 def r(self, r_xml):
     return parse_xml_bytes(r_xml)
Ejemplo n.º 45
0
 def empty_spTree(self):
     return parse_xml_bytes(test_shape_xml.empty_spTree)
Ejemplo n.º 46
0
 def cell(self):
     return parse_xml_bytes(test_table_xml.cell)
Ejemplo n.º 47
0
 def placeholder(self):
     return parse_xml_bytes(test_shape_xml.placeholder)
Ejemplo n.º 48
0
 def isolated_tbl(self):
     return parse_xml_bytes(test_table_xml.isolated_tbl)
Ejemplo n.º 49
0
 def rounded_rectangle(self):
     return parse_xml_bytes(test_shape_xml.rounded_rectangle)
Ejemplo n.º 50
0
 def top_aligned_cell(self):
     return parse_xml_bytes(test_table_xml.top_aligned_cell)
Ejemplo n.º 51
0
 def textbox(self):
     return parse_xml_bytes(test_shape_xml.textbox)
Ejemplo n.º 52
0
 def element(self):
     """
     Element parsed from XML generated by builder in current state
     """
     elm = parse_xml_bytes(self.xml())
     return elm
Ejemplo 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'))