log_line.py
changeset 90 275a675712f1
parent 86 645cf9c4441e
child 91 df2a6780cdf9
--- a/log_line.py	Wed Feb 11 00:33:21 2009 +0200
+++ b/log_line.py	Wed Feb 11 00:47:02 2009 +0200
@@ -130,8 +130,29 @@
         self.target = target
         self.data = data
     
-    def __repr__ (self) :
-        return "channel=%s, offset=%s, type=%s, timestamp=%s, source=%s, target=%s, data=%s" % (
-            self.channel, self.offset, LogTypes.name_from_code(self.type), self.timestamp, self.source, self.target, self.data
+    def format_type (self) :
+        """
+            Formats type as a string code
+        """
+
+        return LogTypes.name_from_code(self.type)
+
+    def format_source (self) :
+        """
+            Formats source as <nickname>:<chanflags>!<username>@<hostname>, omitting those parts that are missing
+        """
+
+        nick, user, host, flags = self.source
+
+        return "%s%s%s%s" % (
+            nick if nick else '',
+            ':' + flags if flags else '',
+            '!' + user if user else '',
+            '@' + host if host else ''
         )
 
+    def __repr__ (self) :
+        return "LogLine(%r, %s, %-12s, %s, %-35s, %-10s, %r)" % (
+            self.channel, self.offset, self.format_type(), self.timestamp, self.format_source(), self.target, self.data
+        )
+