clean up repr(LogLine) output
authorTero Marttila <terom@fixme.fi>
Wed, 11 Feb 2009 00:47:02 +0200
changeset 90 275a675712f1
parent 89 2dc6de43f317
child 91 df2a6780cdf9
clean up repr(LogLine) output
log_channel.py
log_line.py
--- a/log_channel.py	Wed Feb 11 00:33:21 2009 +0200
+++ b/log_channel.py	Wed Feb 11 00:47:02 2009 +0200
@@ -38,3 +38,17 @@
 
         return log_search.index.search_simple(self, query)
 
+    def __str__ (self) :
+        """
+            Returns self.title
+        """
+
+        return self.title
+
+    def __repr__ (self) :
+        """
+            Uses self.id
+        """
+
+        return "LogChannel(%s)" % (self.id, )
+
--- 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
+        )
+