Ejemplo n.º 1
0
 def load(self, fs):
     """
     Retrieve [Content_Types].xml from specified file system and load it.
     Returns a reference to this _ContentTypesItem instance to allow
     generative call, e.g. ``cti = _ContentTypesItem().load(fs)``.
     
     """
     element = fs.getelement("/[Content_Types].xml")
     defaults = element.findall(qtag("ct:Default"))
     overrides = element.findall(qtag("ct:Override"))
     self.__defaults = dict((d.get("Extension"), d.get("ContentType")) for d in defaults)
     self.__overrides = dict((o.get("PartName"), o.get("ContentType")) for o in overrides)
     return self
Ejemplo n.º 2
0
 def element(self):
     nsmap = {None: pptx.spec.nsmap['ct']}
     element = etree.Element(qtag('ct:Types'), nsmap=nsmap)
     if self.__defaults:
         for ext in sorted(self.__defaults.keys()):
             subelm = etree.SubElement(element, qtag('ct:Default'))
             subelm.set('Extension', ext)
             subelm.set('ContentType', self.__defaults[ext])
     if self.__overrides:
         for partname in sorted(self.__overrides.keys()):
             subelm = etree.SubElement(element, qtag('ct:Override'))
             subelm.set('PartName', partname)
             subelm.set('ContentType', self.__overrides[partname])
     return element
Ejemplo n.º 3
0
 def element(self):
     nsmap = {None: pptx.spec.nsmap["ct"]}
     element = etree.Element(qtag("ct:Types"), nsmap=nsmap)
     if self.__defaults:
         for ext in sorted(self.__defaults.keys()):
             subelm = etree.SubElement(element, qtag("ct:Default"))
             subelm.set("Extension", ext)
             subelm.set("ContentType", self.__defaults[ext])
     if self.__overrides:
         for partname in sorted(self.__overrides.keys()):
             subelm = etree.SubElement(element, qtag("ct:Override"))
             subelm.set("PartName", partname)
             subelm.set("ContentType", self.__overrides[partname])
     return element
Ejemplo n.º 4
0
 def element(self):
     nsmap = {None: pptx.spec.nsmap['ct']}
     element = etree.Element(qtag('ct:Types'), nsmap=nsmap)
     if self._defaults:
         for ext in sorted(self._defaults.keys()):
             subelm = etree.SubElement(element, qtag('ct:Default'))
             subelm.set('Extension', ext)
             subelm.set('ContentType', self._defaults[ext])
     if self._overrides:
         for partname in sorted(self._overrides.keys()):
             subelm = etree.SubElement(element, qtag('ct:Override'))
             subelm.set('PartName', partname)
             subelm.set('ContentType', self._overrides[partname])
     return element
Ejemplo n.º 5
0
    def load(self, fs):
        """
        Retrieve [Content_Types].xml from specified file system and load it.
        Returns a reference to this _ContentTypesItem instance to allow
        generative call, e.g. ``cti = _ContentTypesItem().load(fs)``.

        """
        element = fs.getelement('/[Content_Types].xml')
        defaults = element.findall(qtag('ct:Default'))
        overrides = element.findall(qtag('ct:Override'))
        self.__defaults = dict(
            (d.get('Extension'), d.get('ContentType')) for d in defaults)
        self.__overrides = dict(
            (o.get('PartName'), o.get('ContentType')) for o in overrides)
        return self
Ejemplo n.º 6
0
 def __init__(self):
     super(CT_Transform2D, self).__init__()
     self._element = Element(qtag('a:xfrm'), nsmap=nsmap)
     self.off = CT_Point2D()
     self._element.append(self.off.element)
     self.ext = CT_PositiveSize2D()
     self._element.append(self.ext.element)
Ejemplo n.º 7
0
 def __init__(self):
     super(CT_TextBody, self).__init__()
     self._element = Element(qtag('p:txBody'), nsmap=nsmap)
     self.bodyPr = CT_TextBodyProperties()
     self._element.append(self.bodyPr.element)
     self.lstStyle = CT_TextListStyle()
     self._element.append(self.lstStyle.element)
     self.p = CT_TextParagraph()
     self._element.append(self.p.element)
Ejemplo n.º 8
0
 def __init__(self):
     super(CT_ShapeProperties, self).__init__()
     self._element = Element(qtag('p:spPr'), nsmap=nsmap)
     self.xfrm = CT_Transform2D()
     self._element.append(self.xfrm.element)
     self.prstGeom = CT_PresetGeometry2D()
     self._element.append(self.prstGeom.element)
     self.noFill = CT_NoFillProperties()
     self._element.append(self.noFill.element)
Ejemplo n.º 9
0
 def __init__(self):
     super(CT_ShapeNonVisual, self).__init__()
     self._element = Element(qtag('p:nvSpPr'), nsmap=nsmap)
     self.cNvPr = CT_NonVisualDrawingProps()
     self._element.append(self.cNvPr.element)
     self.cNvSpPr = CT_NonVisualDrawingShapeProps()
     self._element.append(self.cNvSpPr.element)
     self.nvPr = CT_ApplicationNonVisualDrawingProps()
     self._element.append(self.nvPr.element)
Ejemplo n.º 10
0
 def __init__(self):
     super(CT_Shape, self).__init__()
     self._element = Element(qtag('p:sp'), nsmap=nsmap)
     self.nvSpPr = CT_ShapeNonVisual()
     self._element.append(self.nvSpPr.element)
     self.spPr = CT_ShapeProperties()
     self._element.append(self.spPr.element)
     self.txBody = CT_TextBody()
     self._element.append(self.txBody.element)
Ejemplo n.º 11
0
 def __get_rel_elms(self, fs):
     """
     Helper method for _load(). Return list of this relationship elements
     for this part from *fs*. Returns empty list if there are no
     relationships for this part, either because parts of this type never
     have relationships or its relationships are optional and none exist in
     this filesystem (package).
     """
     relsitemURI = self.__relsitemURI(self.typespec, self.__partname, fs)
     if relsitemURI is None:
         return []
     if relsitemURI not in fs:
         tmpl = "required relationships item '%s' not found in package"
         raise CorruptedPackageError(tmpl % relsitemURI)
     root_elm = fs.getelement(relsitemURI)
     return root_elm.findall(qtag('pr:Relationship'))
Ejemplo n.º 12
0
 def __get_rel_elms(self, fs):
     """
     Helper method for _load(). Return list of this relationship elements
     for this part from *fs*. Returns empty list if there are no
     relationships for this part, either because parts of this type never
     have relationships or its relationships are optional and none exist in
     this filesystem (package).
     """
     relsitemURI = self.__relsitemURI(self.typespec, self.__partname, fs)
     if relsitemURI is None:
         return []
     if relsitemURI not in fs:
         tmpl = "required relationships item '%s' not found in package"
         raise CorruptedPackageError(tmpl % relsitemURI)
     root_elm = fs.getelement(relsitemURI)
     return root_elm.findall(qtag('pr:Relationship'))
Ejemplo n.º 13
0
 def open(self, path):
     """Load the on-disk package located at *path*."""
     fs = FileSystem(path)
     cti = _ContentTypesItem().load(fs)
     self.__relationships = []  # discard any rels from prior load
     parts_dict = {}  # track loaded parts, graph is cyclic
     pkg_rel_elms = fs.getelement(Package.PKG_RELSITEM_URI).findall(qtag("pr:Relationship"))
     for rel_elm in pkg_rel_elms:
         rId = rel_elm.get("Id")
         reltype = rel_elm.get("Type")
         partname = "/%s" % rel_elm.get("Target")
         part = Part()
         parts_dict[partname] = part
         part._load(fs, partname, cti, parts_dict)
         rel = Relationship(rId, self, reltype, part)
         self.__relationships.append(rel)
     fs.close()
     return self
 def test__blob_rewrites_sldIdLst(self):
     """Presentation._blob rewrites sldIdLst"""
     # setup ------------------------
     rels = RelationshipCollectionBuilder()
     rels = rels.with_tuple_targets(2, RT_SLIDE_MASTER)
     rels = rels.with_tuple_targets(3, RT_SLIDE)
     rels = rels.with_ordering(RT_SLIDE_MASTER, RT_SLIDE)
     rels = rels.build()
     prs = Presentation()
     prs._relationships = rels
     prs.partname = '/ppt/presentation.xml'
     path = os.path.join(thisdir, 'test_files/presentation.xml')
     prs._element = oxml_parse(path).getroot()
     # exercise ---------------------
     blob = prs._blob
     # verify -----------------------
     presentation = oxml_fromstring(blob)
     sldIds = presentation.xpath('./p:sldIdLst/p:sldId', namespaces=nsmap)
     expected = ['rId3', 'rId4', 'rId5']
     actual = [sldId.get(qtag('r:id')) for sldId in sldIds]
     msg = "expected ordering %s, got %s" % (expected, actual)
     self.assertEqual(expected, actual, msg)
Ejemplo n.º 15
0
 def open(self, file):
     """
     Load the package contained in *file*, where *file* can be a path to a
     file or directory (a string), or a file-like object. If *file* is a
     path to a directory, the directory must contain an expanded package
     such as is produced by unzipping an OPC package file.
     """
     fs = FileSystem(file)
     cti = _ContentTypesItem().load(fs)
     self.__relationships = []  # discard any rels from prior load
     parts_dict = {}            # track loaded parts, graph is cyclic
     pkg_rel_elms = fs.getelement(Package.PKG_RELSITEM_URI)\
                      .findall(qtag('pr:Relationship'))
     for rel_elm in pkg_rel_elms:
         rId = rel_elm.get('Id')
         reltype = rel_elm.get('Type')
         partname = '/%s' % rel_elm.get('Target')
         part = Part()
         parts_dict[partname] = part
         part._load(fs, partname, cti, parts_dict)
         rel = Relationship(rId, self, reltype, part)
         self.__relationships.append(rel)
     fs.close()
     return self
Ejemplo n.º 16
0
 def open(self, file):
     """
     Load the package contained in *file*, where *file* can be a path to a
     file or directory (a string), or a file-like object. If *file* is a
     path to a directory, the directory must contain an expanded package
     such as is produced by unzipping an OPC package file.
     """
     fs = FileSystem(file)
     cti = _ContentTypesItem().load(fs)
     self.__relationships = []  # discard any rels from prior load
     parts_dict = {}  # track loaded parts, graph is cyclic
     pkg_rel_elms = fs.getelement(Package.PKG_RELSITEM_URI)\
                      .findall(qtag('pr:Relationship'))
     for rel_elm in pkg_rel_elms:
         rId = rel_elm.get('Id')
         reltype = rel_elm.get('Type')
         partname = '/%s' % rel_elm.get('Target')
         part = Part()
         parts_dict[partname] = part
         part._load(fs, partname, cti, parts_dict)
         rel = Relationship(rId, self, reltype, part)
         self.__relationships.append(rel)
     fs.close()
     return self
Ejemplo n.º 17
0
 def __init__(self):
     super(CT_GeomGuideList, self).__init__()
     self._element = Element(qtag('a:avLst'), nsmap=nsmap)
Ejemplo n.º 18
0
 def __init__(self):
     super(CT_PresetGeometry2D, self).__init__()
     self._element = Element(qtag('a:prstGeom'), nsmap=nsmap)
     self.avLst = CT_GeomGuideList()
     self._element.append(self.avLst.element)
Ejemplo n.º 19
0
 def _relsitem_element(self):
     nsmap = {None: pptx.spec.nsmap['pr']}
     element = etree.Element(qtag('pr:Relationships'), nsmap=nsmap)
     for rel in self.__relationships:
         element.append(rel._element)
     return element
Ejemplo n.º 20
0
 def __init__(self):
     super(CT_TextBodyProperties, self).__init__()
     self._element = Element(qtag('a:bodyPr'), nsmap=nsmap)
     self.spAutoFit = CT_TextShapeAutofit()
     self._element.append(self.spAutoFit.element)
Ejemplo n.º 21
0
 def __init__(self):
     super(CT_TextListStyle, self).__init__()
     self._element = Element(qtag('a:lstStyle'), nsmap=nsmap)
Ejemplo n.º 22
0
 def __init__(self):
     super(CT_TextParagraph, self).__init__()
     self._element = Element(qtag('a:p'), nsmap=nsmap)
Ejemplo n.º 23
0
 def __init__(self):
     super(CT_TextShapeAutofit, self).__init__()
     self._element = Element(qtag('a:spAutoFit'), nsmap=nsmap)
Ejemplo n.º 24
0
 def __init__(self):
     super(CT_ApplicationNonVisualDrawingProps, self).__init__()
     self._element = Element(qtag('p:nvPr'), nsmap=nsmap)
Ejemplo n.º 25
0
 def _relsitem_element(self):
     nsmap = {None: pptx.spec.nsmap['pr']}
     element = etree.Element(qtag('pr:Relationships'), nsmap=nsmap)
     for rel in self.__relationships:
         element.append(rel._element)
     return element
Ejemplo n.º 26
0
 def __init__(self):
     super(CT_NonVisualDrawingShapeProps, self).__init__()
     self._element = Element(qtag('p:cNvSpPr'), nsmap=nsmap)
Ejemplo n.º 27
0
 def __init__(self):
     super(CT_PositiveSize2D, self).__init__()
     self._element = Element(qtag('a:ext'), nsmap=nsmap)
Ejemplo n.º 28
0
 def __init__(self):
     super(CT_NoFillProperties, self).__init__()
     self._element = Element(qtag('a:noFill'), nsmap=nsmap)
Ejemplo n.º 29
0
 def __init__(self):
     super(CT_Point2D, self).__init__()
     self._element = Element(qtag('a:off'), nsmap=nsmap)