55See the file 'doc/COPYING' for copying permission
66"""
77
8+ import cgi
89import codecs
910import os
1011import threading
1112
12- from xml .dom .minidom import getDOMImplementation
13-
1413from lib .core .common import Backend
1514from lib .core .common import dataToDumpFile
1615from lib .core .common import dataToStdout
@@ -442,8 +441,11 @@ def dbTableValues(self, tableValues):
442441
443442 rtable = replication .createTable (table , cols )
444443 elif conf .dumpFormat == DUMP_FORMAT .HTML :
445- documentNode = getDOMImplementation ().createDocument (None , "table" , None )
446- tableNode = documentNode .documentElement
444+ dataToDumpFile (dumpFP , "<!DOCTYPE html>\n <html>\n <head>\n " )
445+ dataToDumpFile (dumpFP , "<meta http-equiv=\" Content-type\" content=\" text/html;charset=%s\" >\n " % UNICODE_ENCODING )
446+ dataToDumpFile (dumpFP , "<title>%s</title>\n " % ("%s%s" % ("%s." % db if METADB_SUFFIX not in db else "" , table )))
447+ dataToDumpFile (dumpFP , HTML_DUMP_CSS_STYLE )
448+ dataToDumpFile (dumpFP , "\n </head>\n <body>\n <table>\n <thead>\n <tr>\n " )
447449
448450 if count == 1 :
449451 self ._write ("[1 entry]" )
@@ -452,14 +454,6 @@ def dbTableValues(self, tableValues):
452454
453455 self ._write (separator )
454456
455- if conf .dumpFormat == DUMP_FORMAT .HTML :
456- headNode = documentNode .createElement ("thead" )
457- rowNode = documentNode .createElement ("tr" )
458- tableNode .appendChild (headNode )
459- headNode .appendChild (rowNode )
460- bodyNode = documentNode .createElement ("tbody" )
461- tableNode .appendChild (bodyNode )
462-
463457 for column in columns :
464458 if column != "__infos__" :
465459 info = tableValues [column ]
@@ -477,12 +471,13 @@ def dbTableValues(self, tableValues):
477471 else :
478472 dataToDumpFile (dumpFP , "%s%s" % (safeCSValue (column ), conf .csvDel ))
479473 elif conf .dumpFormat == DUMP_FORMAT .HTML :
480- entryNode = documentNode .createElement ("td" )
481- rowNode .appendChild (entryNode )
482- entryNode .appendChild (documentNode .createTextNode (column ))
474+ dataToDumpFile (dumpFP , "<th>%s</th>" % cgi .escape (column ).encode ("ascii" , "xmlcharrefreplace" ))
483475
484476 field += 1
485477
478+ if conf .dumpFormat == DUMP_FORMAT .HTML :
479+ dataToDumpFile (dumpFP , "\n </tr>\n </thead>\n <tbody>\n " )
480+
486481 self ._write ("|\n %s" % separator )
487482
488483 if conf .dumpFormat == DUMP_FORMAT .CSV :
@@ -503,8 +498,7 @@ def dbTableValues(self, tableValues):
503498 values = []
504499
505500 if conf .dumpFormat == DUMP_FORMAT .HTML :
506- rowNode = documentNode .createElement ("tr" )
507- bodyNode .appendChild (rowNode )
501+ dataToDumpFile (dumpFP , "<tr>" )
508502
509503 for column in columns :
510504 if column != "__infos__" :
@@ -547,9 +541,7 @@ def dbTableValues(self, tableValues):
547541 else :
548542 dataToDumpFile (dumpFP , "%s%s" % (safeCSValue (value ), conf .csvDel ))
549543 elif conf .dumpFormat == DUMP_FORMAT .HTML :
550- entryNode = documentNode .createElement ("td" )
551- rowNode .appendChild (entryNode )
552- entryNode .appendChild (documentNode .createTextNode (value ))
544+ dataToDumpFile (dumpFP , "<td>%s</td>" % cgi .escape (value ).encode ("ascii" , "xmlcharrefreplace" ))
553545
554546 field += 1
555547
@@ -560,6 +552,8 @@ def dbTableValues(self, tableValues):
560552 pass
561553 elif conf .dumpFormat == DUMP_FORMAT .CSV :
562554 dataToDumpFile (dumpFP , "\n " )
555+ elif conf .dumpFormat == DUMP_FORMAT .HTML :
556+ dataToDumpFile (dumpFP , "</tr>\n " )
563557
564558 self ._write ("|" , console = console )
565559
@@ -571,13 +565,7 @@ def dbTableValues(self, tableValues):
571565
572566 elif conf .dumpFormat in (DUMP_FORMAT .CSV , DUMP_FORMAT .HTML ):
573567 if conf .dumpFormat == DUMP_FORMAT .HTML :
574- dataToDumpFile (dumpFP , "<!DOCTYPE html>\n <html>\n <head>\n " )
575- dataToDumpFile (dumpFP , "<meta http-equiv=\" Content-type\" content=\" text/html;charset=%s\" >\n " % UNICODE_ENCODING )
576- dataToDumpFile (dumpFP , "<title>%s</title>\n " % ("%s%s" % ("%s." % db if METADB_SUFFIX not in db else "" , table )))
577- dataToDumpFile (dumpFP , HTML_DUMP_CSS_STYLE )
578- dataToDumpFile (dumpFP , "\n </head>\n " )
579- dataToDumpFile (dumpFP , tableNode .toxml ())
580- dataToDumpFile (dumpFP , "\n </html>" )
568+ dataToDumpFile (dumpFP , "</tbody>\n </table>\n </body>\n </html>" )
581569 else :
582570 dataToDumpFile (dumpFP , "\n " )
583571 dumpFP .close ()
0 commit comments