Пример #1
0
 def syndicateSomething(self, p_url, p_items=[], lang=None):
     s = self.getSite()
     if lang is None: lang = self.gl_get_selected_language()
     namespaces = self.getNamespaceItemsList()
     nsmap = {}
     header = []
     for n in namespaces:
         if n.prefix != '':
             nsmap[n.prefix] = n.value
         else:
             nsmap[None] = n.value
         header.append(str(n))
     rdf_namespace = nsmap['rdf']
     dc_namespace = nsmap['dc']
     Rdf = ElementMaker(namespace=rdf_namespace, nsmap=nsmap)
     Dc = ElementMaker(namespace=dc_namespace, nsmap=nsmap)
     E = ElementMaker(None, nsmap=nsmap)
     xml = Rdf.RDF(
       E.channel(
         E.title(s.title),
         E.link(p_url),
         E.description(html2text(s.description, trim_length=None)),
         Dc.description(s.description),
         Dc.identifier(p_url),
         Dc.date(self.utShowFullDateTimeHTML(self.utGetTodayDate())),
         Dc.publisher(s.publisher),
         Dc.creator(s.creator),
         Dc.subject(s.title),
         Dc.subject(s.site_subtitle),
         Dc.language(lang),
         Dc.source(s.publisher),
         E.items(),
         {'{%s}about'%rdf_namespace : s.absolute_url()}
       )
     )
     channel = xml[0];  items = channel[-1]
     seq = etree.SubElement(items, '{%s}Seq'%rdf_namespace)
     for i in p_items:
         x = etree.SubElement(seq, '{%s}li'%rdf_namespace, resource=i.absolute_url())
     if self.hasImage():
         image = E.image(
             E.title(s.title),
             E.url(self.getImagePath()),
             E.link(s.absolute_url()),
             E.description(self.utToUtf8(s.description))
            )
         xml.append(image)
     received_items = ''.join([i.syndicateThis() for i in p_items])
     received = '<rdf:RDF %s>%s</rdf:RDF>' % (''.join(header), received_items)
     xml_received = etree.XML(received, etree.XMLParser(strip_cdata = False))
     xml.extend(xml_received)
     self.REQUEST.RESPONSE.setHeader('content-type', 'text/xml')
     return etree.tostring(xml, xml_declaration=True, encoding="utf-8")
Пример #2
0
 def syndicateSomething(self, p_url, p_items=[], lang=None):
     s = self.getSite()
     if lang is None: lang = self.gl_get_selected_language()
     namespaces = self.getNamespaceItemsList()
     nsmap = {}
     header = []
     for n in namespaces:
         if n.prefix != '':
             nsmap[n.prefix] = n.value
         else:
             nsmap[None] = n.value
         header.append(str(n))
     rdf_namespace = nsmap['rdf']
     dc_namespace = nsmap['dc']
     Rdf = ElementMaker(namespace=rdf_namespace, nsmap=nsmap)
     Dc = ElementMaker(namespace=dc_namespace, nsmap=nsmap)
     E = ElementMaker(None, nsmap=nsmap)
     xml = Rdf.RDF(
         E.channel(
             E.title(s.title), E.link(p_url),
             E.description(html2text(s.description, trim_length=None)),
             Dc.description(s.description), Dc.identifier(p_url),
             Dc.date(self.utShowFullDateTimeHTML(self.utGetTodayDate())),
             Dc.publisher(s.publisher), Dc.creator(s.creator),
             Dc.subject(s.title), Dc.subject(s.site_subtitle),
             Dc.language(lang), Dc.source(s.publisher), E.items(),
             {'{%s}about' % rdf_namespace: s.absolute_url()}))
     channel = xml[0]
     items = channel[-1]
     seq = etree.SubElement(items, '{%s}Seq' % rdf_namespace)
     for i in p_items:
         x = etree.SubElement(seq,
                              '{%s}li' % rdf_namespace,
                              resource=i.absolute_url())
     if self.hasImage():
         image = E.image(E.title(s.title), E.url(self.getImagePath()),
                         E.link(s.absolute_url()),
                         E.description(self.utToUtf8(s.description)))
         xml.append(image)
     received_items = ''.join([i.syndicateThis() for i in p_items])
     received = '<rdf:RDF %s>%s</rdf:RDF>' % (''.join(header),
                                              received_items)
     xml_received = etree.XML(received, etree.XMLParser(strip_cdata=False))
     xml.extend(xml_received)
     self.REQUEST.RESPONSE.setHeader('content-type', 'text/xml')
     return etree.tostring(xml, xml_declaration=True, encoding="utf-8")
Пример #3
0
 def test_long_trim(self):
     self.assertEqual(html2text('short text',
                                trim_length=100, ellipsis=True),
                      'short text')
Пример #4
0
 def test_ellipsis(self):
     self.assertEqual(html2text("some long text here", trim_length=12),
                      "some long te")
     self.assertEqual(html2text("some long text here",
                                trim_length=12, ellipsis=True),
                      u"some long \u2026")
Пример #5
0
 def test_strip_whitespace(self):
     self.assertEqual(html2text(' something   '), 'something')
Пример #6
0
 def test_trim(self):
     self.assertEqual(html2text("<b>hello</b> world!", trim_length=4),
                      "hell")
     self.assertEqual(html2text("blah blah some text", trim_length=4),
                      "blah")
Пример #7
0
 def test_strip_tags(self):
     self.assertEqual(html2text('<input type="text">'), "")
     self.assertEqual(html2text('<script>alert(1)</script>'), "alert(1)")
Пример #8
0
 def test_blank(self):
     self.assertEqual(html2text(""), "")
Пример #9
0
 def plaintext_summary(self, chars=100):
     return html2text(self.body, chars)
Пример #10
0
 def test_ellipsis(self):
     self.assertEqual(html2text("some long text here", trim_length=12),
                      "some long te")
     self.assertEqual(
         html2text("some long text here", trim_length=12, ellipsis=True),
         u"some long \u2026")
Пример #11
0
 def test_strip_whitespace(self):
     self.assertEqual(html2text(' something   '), 'something')
Пример #12
0
 def test_trim(self):
     self.assertEqual(html2text("<b>hello</b> world!", trim_length=4),
                      "hell")
     self.assertEqual(html2text("blah blah some text", trim_length=4),
                      "blah")
Пример #13
0
 def plaintext_summary(self, chars=1024):
     return html2text(self.body, chars, ellipsis=True)
Пример #14
0
 def test_blank(self):
     self.assertEqual(html2text(""), "")
Пример #15
0
 def test_long_trim(self):
     self.assertEqual(
         html2text('short text', trim_length=100, ellipsis=True),
         'short text')
Пример #16
0
 def test_strip_tags(self):
     self.assertEqual(html2text('<input type="text">'), "")
     self.assertEqual(html2text('<script>alert(1)</script>'), "alert(1)")
Пример #17
0
 def plaintext_summary(self, chars=1024):
     return html2text(self.body, chars, ellipsis=True)