def testNakedAmpersands(self): txt = "1 & 2" parser = ParaParser() parser.caseSensitive = True frags = ParaParser().parse(txt, self.style)[1] #print 'parsed OK, frags=', frags from reportlab.platypus.paragraph import Paragraph p = Paragraph(txt, self.style)
def testPlainUnicode(self): "See if simple unicode goes through" txt = u"Hello World" stuff = ParaParser().parse(txt, self.style) assert type(stuff) is TupleType assert len(stuff) == 3 assert stuff[1][0].text == u'Hello World'
def testPlainUnicode(self): "See if simple unicode goes through" txt = "Hello World" stuff = ParaParser().parse(txt, self.style) assert isinstance(stuff,tuple) assert len(stuff) == 3 assert stuff[1][0].text == 'Hello World'
def testEntity(self): "Numeric entities should be unescaped by parser" txt = "Hello © copyright" fragList = ParaParser().parse(txt, self.style)[1] vals = [b'Hello ', b'\xc2\xa9', b' copyright'] if sys.version_info[0] == 3: vals = [val.decode('utf-8') for val in vals] self.assertEquals([x.text for x in fragList], vals)
def testEntityUnicode(self): "Numeric entities should be unescaped by parser" txt = u"Hello © copyright" fragList = ParaParser().parse(txt, self.style)[1] self.assertEquals(map(lambda x: x.text, fragList), [u'Hello ', u'\xa9', u' copyright'])
def parseIt(txt, style=self.style): fragList = ParaParser().parse(txt, self.style)[1]
def testBoldUnicode(self): txt = u"Hello <b>Bold</b> World" fragList = ParaParser().parse(txt, self.style)[1] self.assertEquals(map(lambda x: x.text, fragList), [u'Hello ', u'Bold', u' World']) self.assertEquals(fragList[1].fontName, 'Times-Bold')
def testEm(self): txt = "Hello <em>Em</em> World" fragList = ParaParser().parse(txt, self.style)[1] self.assertEquals(map(lambda x: x.text, fragList), ['Hello ', 'Em', ' World']) self.assertEquals(fragList[1].fontName, 'Times-Italic')
def testEscaped(self): "Escaped high-bit stuff should go straight through" txt = "Hello \xc2\xa9 copyright" fragList = ParaParser().parse(txt, self.style)[1] assert fragList[0].text == txt
def testPlain(self): txt = "Hello World" stuff = ParaParser().parse(txt, self.style) assert type(stuff) is TupleType assert len(stuff) == 3 assert stuff[1][0].text == 'Hello World'
def testStrong(self): txt = "Hello <strong>Strong</strong> World" fragList = ParaParser().parse(txt, self.style)[1] self.assertEquals(map(lambda x: x.text, fragList), ['Hello ', 'Strong', ' World']) self.assertEquals(fragList[1].fontName, 'Times-Bold')
def testEm(self): txt = "Hello <em>Em</em> World" fragList = ParaParser().parse(txt, self.style)[1] self.assertEqual([x.text for x in fragList], ['Hello ','Em',' World']) self.assertEqual(fragList[1].fontName, 'Times-Italic')
def testBr(self): txt = u"Hello <br/> World" fragList = ParaParser().parse(txt, self.style)[1] self.assertEquals(map(lambda x: x.text, fragList), [u'Hello ', u'', u' World']) self.assertEquals(fragList[1].lineBreak, True)
def testPlain(self): txt = "Hello World" stuff = ParaParser().parse(txt, self.style) assert isinstance(stuff,tuple) assert len(stuff) == 3 assert stuff[1][0].text == 'Hello World'
def testItalic(self): txt = "Hello <i>Italic</i> World" fragList = ParaParser().parse(txt, self.style)[1] self.assertEquals([x.text for x in fragList], ['Hello ', 'Italic', ' World']) self.assertEquals(fragList[1].fontName, 'Times-Italic')
def testBold(self): txt = "Hello <b>Bold</b> World" fragList = ParaParser().parse(txt, self.style)[1] self.assertEquals([x.text for x in fragList], ['Hello ', 'Bold', ' World']) self.assertEquals(fragList[1].fontName, 'Times-Bold')
def testBr(self): txt = u"Hello <br/> World" fragList = ParaParser().parse(txt, self.style)[1] self.assertEquals([x.text for x in fragList], [u'Hello ', u'', u' World']) self.assertEquals(fragList[1].lineBreak, True)
def testEntity(self): "Numeric entities should be unescaped by parser" txt = b"Hello © copyright" fragList = ParaParser().parse(txt, self.style)[1] self.assertEquals([x.text for x in fragList], [u'Hello ', u'\xa9', u' copyright'])
class FragLine(ABag): """class FragLine contains a styled line (ie a line with more than one style) extraSpace unused space for justification only wordCount 1+spaces in line for justification purposes words [ParaFrags] style text lumps to be concatenated together fontSize maximum fontSize seen on the line; not used at present, but could be used for line spacing. """ #our one and only parser # XXXXX if the parser has any internal state using only one is probably a BAD idea! _parser = ParaParser() def _lineClean(L): return join(filter(truth, split(strip(L)))) def cleanBlockQuotedText(text, joiner=' '): """This is an internal utility which takes triple- quoted text form within the document and returns (hopefully) the paragraph the user intended originally.""" L = filter(truth, map(_lineClean, split(text, '\n'))) return join(L, joiner) def setXPos(tx, dx):
def testStrong(self): txt = "Hello <strong>Strong</strong> World" fragList = ParaParser().parse(txt, self.style)[1] self.assertEqual([x.text for x in fragList], ['Hello ','Strong',' World']) self.assertEqual(fragList[1].fontName, 'Times-Bold')