def get_xhtml(self, element=True): lines = self.text.split('\n') xhtml = ET.Element('span') if self.font: xhtml.set('style', 'font-family: ' + self.font + ';') for subline in lines[:-1]: p = ET.SubElement(xhtml, 'p') p.text = subline ET.SubElement(xhtml, 'br') p = ET.SubElement(xhtml, 'p') p.text = lines[-1] if element: return xhtml return ET.tostring(xhtml)
def _personRefToETree(self, parent, nodeName, line): node = ET.SubElement(parent, "{{{0}}}{1}".format(self.xmlns, nodeName)) components = line.split(" ") email = components[-3] name = " ".join(components[1:-3]) node.text = name node.set("email", email)
def _submit(self, repoName, refPath): tree = ET.Element("{{{0}}}git".format(self.xmlns)) repo = ET.SubElement(tree, "{{{0}}}repository".format(self.xmlns)) repo.text = repoName ref = ET.SubElement(tree, "{{{0}}}ref".format(self.xmlns)) ref.text = refPath try: with open(refPath, "r") as f: sha = f.read() except FileNotFoundError: pass else: newRef = ET.SubElement(tree, "{{{0}}}new-ref".format(self.xmlns)) newRef.set("sha", sha) self._refToETree(newRef, refPath) self.pubsub.publish(self.FEED, self.PUBSUB, payload=tree, block=True)
def _refToETree(self, parent, ref): output = subprocess.check_output(["git", "cat-file", "-p", ref]).decode().split("\n") for i, line in enumerate(output): line = line.strip() if line.startswith("parent "): commit = ET.SubElement(parent, "{{{0}}}parent".format(self.xmlns)) elif line.startswith("author "): self._personRefToETree(parent, "author", line) elif line.startswith("committer "): self._personRefToETree(parent, "committer", line) elif not line: break message = ET.SubElement(parent, "{{{0}}}headline".format(self.xmlns)) try: message.text = output[i + 1] except IndexError: pass
def build_xmpp_message(xmppMessage, message): """ Construction d'un stanza à partir d'un objet Message :param xmppMessage: Message :param message: Message """ xmlMessage = ET.Element( "Sen1Message", { "xmlns": XmppMessageStanza.namespace, "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance", "xmlns:xs": "http://www.w3.org/2001/XMLSchema" }) xmppMessage.append(xmlMessage) ET.SubElement(xmlMessage, "username").text = message.username ET.SubElement(xmlMessage, "name").text = message.name ET.SubElement(xmlMessage, "metaname").text = message.metaname ET.SubElement(xmlMessage, "metavalue").text = message.metavalue ET.SubElement(xmlMessage, "unite").text = message.unite ET.SubElement(xmlMessage, "type").text = message.type ET.SubElement(xmlMessage, "applicationSrc").text = message.applicationSrc ET.SubElement(xmlMessage, "applicationDst").text = message.applicationDst # ajout des datas xmlDatas = ET.SubElement(xmlMessage, "Sen1Datas") for data in message.datas: xmlData = ET.SubElement(xmlDatas, "Sen1Data") ET.SubElement(xmlData, "value", { "xsi:type": "xs:string" }).text = data.value ET.SubElement(xmlData, "timestamp").text = data.timestamp.strftime( "%Y-%m-%dT%H:%M:%S") return xmppMessage