Exemple #1
0
 def test_sup(self):
     """
     Try to read a paragraph containing supscript
     """
     xhtml = "<div><p><sup>super</sup></p></div>"
     doc = XHTMLReader.read(xhtml)
     text = doc.content[0].content[0]
     assert text['super']
Exemple #2
0
 def test_bold(self):
     """
     Try to read a paragraph containing bold text
     """
     xhtml = "<div><p><b>bold</b></p></div>"
     doc = XHTMLReader.read(xhtml)
     text = doc.content[0].content[0]
     assert text['bold']
Exemple #3
0
 def test_italic(self):
     """
     Try to read a paragraph containing italic text
     """
     xhtml = "<div><p><i>italic</i></p></div>"
     doc = XHTMLReader.read(xhtml)
     text = doc.content[0].content[0]
     assert text['italic']
Exemple #4
0
 def test_basic(self):
     """
     Try to read an empty xhtml document
     """
     xhtml = "<div></div>"
     doc = XHTMLReader.read(xhtml)
     self.assert_(isinstance(doc, pyth.document.Document))
     self.assert_(not doc.content)
Exemple #5
0
 def test_basic(self):
     """
     Try to read an empty xhtml document
     """
     xhtml = "<div></div>"
     doc = XHTMLReader.read(xhtml)
     self.assert_(isinstance(doc, pyth.document.Document))
     self.assert_(not doc.content)
Exemple #6
0
 def test_underline_styling(self):
     """
     Try to read a paragraph containing underline via CSS
     """
     xhtml = '<div><p style="text-decoration: underline;">underline</p></div>'
     doc = XHTMLReader.read(xhtml)
     text = doc.content[0].content[0]
     assert text['underline']
Exemple #7
0
 def test_sup(self):
     """
     Try to read a paragraph containing supscript
     """
     xhtml = "<div><p><sup>super</sup></p></div>"
     doc = XHTMLReader.read(xhtml)
     text = doc.content[0].content[0]
     assert text['super']
Exemple #8
0
 def test_url(self):
     """
     Try to read a paragraph containing an url
     """
     xhtml = '<div><p><a href="http://google.com">link</a></p></div>'
     doc = XHTMLReader.read(xhtml)
     text = doc.content[0].content[0]
     assert text['url'] == "http://google.com"
Exemple #9
0
 def test_italic(self):
     """
     Try to read a paragraph containing italic text
     """
     xhtml = "<div><p><i>italic</i></p></div>"
     doc = XHTMLReader.read(xhtml)
     text = doc.content[0].content[0]
     assert text['italic']
Exemple #10
0
 def test_bold(self):
     """
     Try to read a paragraph containing bold text
     """
     xhtml = "<div><p><b>bold</b></p></div>"
     doc = XHTMLReader.read(xhtml)
     text = doc.content[0].content[0]
     assert text['bold']
Exemple #11
0
 def test_url(self):
     """
     Try to read a paragraph containing an url
     """
     xhtml = '<div><p><a href="http://google.com">link</a></p></div>'
     doc = XHTMLReader.read(xhtml)
     text = doc.content[0].content[0]
     assert text['url'] == "http://google.com"
Exemple #12
0
 def test_underline(self):
     """
     Try to read a paragraph containing underline
     """
     xhtml = "<div><p><u>sub</u></p></div>"
     doc = XHTMLReader.read(xhtml)
     text = doc.content[0].content[0]
     assert text['underline']
Exemple #13
0
def create_rtf(matiere):
    
    httpResponse = render_to_response('coeur/matiere_rtf.html', {'matiere'      : matiere,
                                                     })
    filename = '/tmp/rtf/%s %s.rtf' % (matiere.promotion, matiere.titre)
    f = open(filename, 'w')
    doc = XHTMLReader.read(httpResponse.content, "")
    Rtf15Writer.write(doc , f)
    
    return filename
Exemple #14
0
 def test_paragraphs(self):
     """
     Try to read a simple xhtml document containing tree paragraphs
     """
     xhtml = "<div><p>p0</p><p>p1</p><p>p2</p></div>"
     doc = XHTMLReader.read(xhtml)
     self.assert_(len(doc.content) == 3)
     for i, p in enumerate(doc.content):
         self.assert_(isinstance(p, pyth.document.Paragraph))
         self.assert_(len(p.content) == 1)
         self.assert_(isinstance(p.content[0], pyth.document.Text))
         text = p.content[0]
         self.assert_(len(text.content) == 1)
         self.assert_(text.content[0] == 'p%d' % i)
Exemple #15
0
 def test_paragraphs(self):
     """
     Try to read a simple xhtml document containing tree paragraphs
     """
     xhtml = "<div><p>p0</p><p>p1</p><p>p2</p></div>"
     doc = XHTMLReader.read(xhtml)
     self.assert_(len(doc.content) == 3)
     for i, p in enumerate(doc.content):
         self.assert_(isinstance(p, pyth.document.Paragraph))
         self.assert_(len(p.content) == 1)
         self.assert_(isinstance(p.content[0], pyth.document.Text))
         text = p.content[0]
         self.assert_(len(text.content) == 1)
         self.assert_(text.content[0] == 'p%d' % i)
Exemple #16
0
 def test_inline_png(self):
     pixels = 50
     twips = pixels * 15
     height = width = str(twips)  # in retrospect choosing a square image wasn't a great idea :)
     with open('tests/html/sample-with-image.html', 'rb') as xhtml:
         doc = XHTMLReader.read(xhtml)
         image = next(node.content[0] for node in doc.content if isinstance(node.content[0], pyth.document.Image))
         self.assertEquals(image.content[0][1:4], u'PNG')
         self.assertEquals(image['pngblip'], True)
         self.assertEquals(image['pich'], height)
         self.assertEquals(image['pichgoal'], height)
         self.assertEquals(image['picw'], width)
         self.assertEquals(image['picwgoal'], width)
         self.assertEquals(image['picscaley'], '100')
         self.assertEquals(image['picscalex'], '100')
Exemple #17
0
from pyth.plugins.xhtml.reader import XHTMLReader
from pyth.plugins.rtf15.writer import Rtf15Writer
import sys

if len(sys.argv) > 1:
    filename = sys.argv[1]
else:
    filename = "tests/html/sample-with-image.html"
source = open(filename, "rb")
doc = XHTMLReader.read(source)

print Rtf15Writer.write(doc).getvalue()
Exemple #18
0
    <p>
      example<span style="vertical-align: super"> super </span>
      example<span style="vertical-align: sub"> sub </span>
    </p>
    a list
    <ul>
      <li>hello
      test</li>
      <li>bonjour</li>
      <li>guten tag</li>
    </ul>
    <p>
      <a href=http://www.google.com>a link
      </a> single space here.
      <br/>a br tag
    </p>
  </div>
""")

css = """
  .important {font-weight: bold}
  p.bold {font-weight: bold}
  .other {font-weight: normal; color: blue}
"""

if __name__ == '__main__':
    # Parse the document and then reconstruct it using the xhtml
    # writer.
    doc = XHTMLReader.read(content, css)
    print XHTMLWriter.write(doc).getvalue()