Exemple #1
0
    def test01(self):
        
        doc=Document("Invoice no %d" % 123)
        doc.h1(doc.title)
        doc.par("Tallinn, 10. juuni 2006. a.",align="RIGHT")
        doc.report(InvoiceReport())
        
        if True:
            spoolFile = self.addTempFile("84.html",showOutput=True)
            doc.saveas(spoolFile)
        
        
        self.assertEquivalentHtml(doc.toxml(), """
<html><head>
<title>Invoice no 123</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="KEYWORDS" content="">
<meta name="GENERATOR" content="lino.htgen">
<meta name="author" content="">
<meta name="date" content="None"><head>
<BODY>
<H1>Invoice no 123</H1>
<P align="RIGHT">Tallinn, 10. juuni 2006. a.</P>
<TABLE>
<COLGROUP><COL width="11*"/><COL width="27*"/><COL width="12*"/></COLGROUP>
<THEAD><TR>
<TH align="LEFT" valign="TOP">Item no.</TH>
<TH align="LEFT" valign="TOP">Description</TH>
<TH align="RIGHT" valign="TOP">Price</TH>
</TR></THEAD>
<TBODY>
<TR>
<TD align="LEFT" valign="TOP">pcd.fsc</TD>
<TD align="LEFT" valign="TOP">Fujitsu-Siemens Esprimo</TD>
<TD align="RIGHT" valign="TOP">756,50</TD>
</TR>
<TR>
<TD align="LEFT" valign="TOP">mon.lcd.fsc</TD>
<TD align="LEFT" valign="TOP">Fujitsu-Siemens Monitor 19&quot;</TD>
<TD align="RIGHT" valign="TOP">370,80</TD>
</TR>
<TR>
<TD align="LEFT" valign="TOP">acc.cdr</TD>
<TD align="LEFT" valign="TOP">CDRW 10 pcs</TD>
<TD align="RIGHT" valign="TOP">12,20</TD>
</TR>
</TBODY></TABLE></BODY>
</html>""")
import sys
from lino.htgen import Document
if len(sys.argv) != 2:
    print "input filename required"
    exit(-1)
s = open(sys.argv[1], "r").read().decode("latin1")
d = Document()
d.memo(s)
print d.toxml().encode('ascii', 'xmlcharrefreplace')
Exemple #3
0
"""
Parse a .mht file as created by MS Word when clicking "File / Save as" 
and "Single file Web page". 
Print a simplified HTML version of the content of this file.

"""
import sys
import os.path
import email
from lino.htgen import Document
if len(sys.argv) != 2:
        print "input filename required"
        exit(-1)
filename=sys.argv[1]
basename,ext=os.path.splitext(filename)
d=Document()
if ext.lower() == ".mht":
  msg=email.message_from_file(open(filename,"r"))
  for part in msg.walk():
    if part.get_content_type() == "text/html":
      print part.get_payload(decode=True)
      #d.load_html(part.get_payload(decode=True))
else:      
  d.load_html(open(filename,"r").read())
    
# d.toxml() would also print <HTML> and <HEAD> and <BODY> tags,
# d.body.toxml() would also print <BODY> and </BODY> tags,
# but I want only the text between <BODY> and </BODY>
for p in d.body.content:
  print p.toxml().encode('ascii', 'xmlcharrefreplace')
Exemple #4
0
def render_node(request, node):
    d=Document(node.title)
    d.h1(d.title)
    d.memo(node.abstract)
    d.memo(node.body)
    return HttpResponse(d.toxml())
Exemple #5
0
import sys
from lino.htgen import Document
if len(sys.argv) != 2:
        print "input filename required"
        exit(-1)
s=open(sys.argv[1],"r").read().decode("latin1")
d=Document()
d.memo(s)
print d.toxml().encode('ascii', 'xmlcharrefreplace')


Exemple #6
0
"""
Parse a .mht file as created by MS Word when clicking "File / Save as" 
and "Single file Web page". 
Print a simplified HTML version of the content of this file.

"""
import sys
import os.path
import email
from lino.htgen import Document
if len(sys.argv) != 2:
    print "input filename required"
    exit(-1)
filename = sys.argv[1]
basename, ext = os.path.splitext(filename)
d = Document()
if ext.lower() == ".mht":
    msg = email.message_from_file(open(filename, "r"))
    for part in msg.walk():
        if part.get_content_type() == "text/html":
            print part.get_payload(decode=True)
            #d.load_html(part.get_payload(decode=True))
else:
    d.load_html(open(filename, "r").read())

# d.toxml() would also print <HTML> and <HEAD> and <BODY> tags,
# d.body.toxml() would also print <BODY> and </BODY> tags,
# but I want only the text between <BODY> and </BODY>
for p in d.body.content:
    print p.toxml().encode('ascii', 'xmlcharrefreplace')
Exemple #7
0
def render_node(request, node):
    d = Document(node.title)
    d.h1(d.title)
    d.memo(node.abstract)
    d.memo(node.body)
    return HttpResponse(d.toxml())
Exemple #8
0
 def memo2xml(self, memo, xml):
     doc = Document()
     doc.memo(memo)
     self.assertEquivalent(doc.body.toxml(), xml)
Exemple #9
0
 def memo2xml(self,memo,xml):
     doc=Document()
     doc.memo(memo)
     self.assertEquivalent(doc.body.toxml(),xml)
Exemple #10
0
    def test01(self):

        doc = Document("Invoice no %d" % 123)
        doc.h1(doc.title)
        doc.par("Tallinn, 10. juuni 2006. a.", align="RIGHT")
        doc.report(InvoiceReport())

        if True:
            spoolFile = self.addTempFile("84.html", showOutput=True)
            doc.saveas(spoolFile)

        self.assertEquivalentHtml(
            doc.toxml(), """
<html><head>
<title>Invoice no 123</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="KEYWORDS" content="">
<meta name="GENERATOR" content="lino.htgen">
<meta name="author" content="">
<meta name="date" content="None"><head>
<BODY>
<H1>Invoice no 123</H1>
<P align="RIGHT">Tallinn, 10. juuni 2006. a.</P>
<TABLE>
<COLGROUP><COL width="11*"/><COL width="27*"/><COL width="12*"/></COLGROUP>
<THEAD><TR>
<TH align="LEFT" valign="TOP">Item no.</TH>
<TH align="LEFT" valign="TOP">Description</TH>
<TH align="RIGHT" valign="TOP">Price</TH>
</TR></THEAD>
<TBODY>
<TR>
<TD align="LEFT" valign="TOP">pcd.fsc</TD>
<TD align="LEFT" valign="TOP">Fujitsu-Siemens Esprimo</TD>
<TD align="RIGHT" valign="TOP">756,50</TD>
</TR>
<TR>
<TD align="LEFT" valign="TOP">mon.lcd.fsc</TD>
<TD align="LEFT" valign="TOP">Fujitsu-Siemens Monitor 19&quot;</TD>
<TD align="RIGHT" valign="TOP">370,80</TD>
</TR>
<TR>
<TD align="LEFT" valign="TOP">acc.cdr</TD>
<TD align="LEFT" valign="TOP">CDRW 10 pcs</TD>
<TD align="RIGHT" valign="TOP">12,20</TD>
</TR>
</TBODY></TABLE></BODY>
</html>""")