refactor HtmlSession to expose CSS (startlog)

This commit is contained in:
pi-rho 2013-01-26 18:55:59 -06:00
parent 8b6893022c
commit d429c3c3f9
1 changed files with 10 additions and 3 deletions

View File

@ -775,7 +775,14 @@ class Session(object):
class HtmlSession(Session): class HtmlSession(Session):
def __init__(self, frame, packetClass=Packet, debug=True): def __init__(self, frame, packetClass=Packet, debug=True):
Session.__init__(self, frame, packetClass) Session.__init__(self, frame, packetClass)
self.sessfd = None
self.debug = debug self.debug = debug
self.startlog()
def startlog(self, client="#a8a8a8", server="white"):
if self.sessfd is not None:
self.sessfd.close()
self.sessfd = self.open_out('session.html') self.sessfd = self.open_out('session.html')
self.sessfd.write('''<?xml version="1.0" encoding="UTF-8"?> self.sessfd.write('''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html <!DOCTYPE html
@ -786,12 +793,12 @@ class HtmlSession(Session):
<title>%s</title> <title>%s</title>
<style type="text/css"> <style type="text/css">
.time { float: right; margin-left: 1em; font-size: 75%%; } .time { float: right; margin-left: 1em; font-size: 75%%; }
.server { background-color: white; color: black; } .server { background-color: %s; color: black; }
.client { background-color: #a8a8a8; color: black; } .client { background-color: %s; color: black; }
</style> </style>
</head> </head>
<body> <body>
''' % self.__class__.__name__) ''' % (self.__class__.__name__, server, client))
self.sessfd.write('<h1>%s</h1>\n' % self.__class__.__name__) self.sessfd.write('<h1>%s</h1>\n' % self.__class__.__name__)
self.sessfd.write('<pre>') self.sessfd.write('<pre>')