log_line.py
changeset 92 74f6a0b01ddf
parent 91 df2a6780cdf9
child 97 6165f1ba458d
equal deleted inserted replaced
91:df2a6780cdf9 92:74f6a0b01ddf
    39 
    39 
    40         # log closed
    40         # log closed
    41         ('LOG_CLOSE',   0x03),
    41         ('LOG_CLOSE',   0x03),
    42 
    42 
    43         ## messages
    43         ## messages
    44         # normal message
    44         # <source> sent message <data> to <channel>
    45         ('MSG',         0x10),
    45         ('MSG',         0x10),
    46         
    46         
    47         # notice
    47         # <source> sent notice with message <data> to <channel>
    48         ('NOTICE',      0x11),
    48         ('NOTICE',      0x11),
    49 
    49 
    50         # CTCP action
    50         # <source> sent CTCP action with message <data> to <channel>
    51         ('ACTION',      0x12),
    51         ('ACTION',      0x12),
    52         
    52         
    53         ## user-channel stats
    53         ## user-channel stats
    54         # join
    54         # <source> joined <channel>
    55         ('JOIN',        0x21),
    55         ('JOIN',        0x21),
    56 
    56 
    57         # part
    57         # <source> left <channel> with message <data>
    58         ('PART',        0x22),
    58         ('PART',        0x22),
    59 
    59 
    60         # kick
    60         # <source> kicked <target> from <channel> with message <data>
    61         ('KICK',        0x25),
    61         ('KICK',        0x25),
    62      
    62      
    63         # channel modes
    63         # <source> changed modes on <channel> with modestring <data>
    64         ('MODE',        0x26),
    64         ('MODE',        0x26),
    65         
    65         
    66         ## user status
    66         ## user status
    67         # nick-change
    67         # <source> changed nickname to <target>
    68         ('NICK',        0x31),
    68         ('NICK',        0x31),
    69 
    69 
    70         # quit
    70         # <source> quit the network with quit-message <data>
    71         ('QUIT',        0x32),
    71         ('QUIT',        0x32),
    72 
    72 
    73         ## general channel status
    73         ## general channel status
    74         # topic changed
    74         # <source> changed the topic of <channel> to <data>
       
    75         # data may be None if the topic was unset
    75         ('TOPIC',       0x41),
    76         ('TOPIC',       0x41),
    76 
    77 
    77         ## our own actions
    78         ## our own actions
       
    79         # we (<source>) sent a notice with message <data> to <channel>
    78         ('SELF_NOTICE', 0x51),
    80         ('SELF_NOTICE', 0x51),
       
    81 
       
    82         # we (<source>) changed nickname to <target>
    79         ('SELF_NICK',   0x52),
    83         ('SELF_NICK',   0x52),
    80     ]
    84     ]
    81     
    85     
    82     @classmethod
    86     @classmethod
    83     def name_from_code (cls, code) :
    87     def name_from_code (cls, code) :
   106     type = None
   110     type = None
   107 
   111 
   108     # the UTC timestamp of the event
   112     # the UTC timestamp of the event
   109     timestamp = None
   113     timestamp = None
   110 
   114 
   111     # the event source, this should be a 
   115     # the source, this should be a (nickname, username, hostname, chanflags) tuple
   112     source = None
   116     source = None
   113 
   117 
   114     # possible event target, for certain types (kick, nick)
   118     # possible target nickname for certain types (kick, nick)
   115     target = None
   119     target = None
   116 
   120 
   117     # associated data (message, etc)
   121     # associated data (message, etc)
   118     data = None
   122     data = None
   119     
   123     
   137 
   141 
   138         return LogTypes.name_from_code(self.type)
   142         return LogTypes.name_from_code(self.type)
   139 
   143 
   140     def format_source (self) :
   144     def format_source (self) :
   141         """
   145         """
   142             Formats source as [<chanflags>][<nickname>][!<username>][@<hostname>], omitting those parts that are missing
   146             Formats source as [<chanflags>][<nickname>][!<username>][@<hostname>], omitting those parts that are missing.
       
   147 
       
   148             If all parts are None, this returns the empty string
   143         """
   149         """
   144 
   150 
   145         nick, user, host, flags = self.source
   151         nick, user, host, flags = self.source
   146 
   152 
   147         return "%s%s%s%s" % (
   153         return "%s%s%s%s" % (
   148             flags if flags and flags != ' ' else '',
   154             flags if flags and flags != ' ' else '',
   149             nick if nick else '',
   155             nick if nick else '',
   150             '!' + user if user else '',
   156             '!' + user if user else '',
   151             '@' + host if host else ''
   157             '@' + host if host else ''
   152         )
   158         )
       
   159    
       
   160     def __str__ (self) :
       
   161         return '\t'.join((
       
   162             self.channel.name,
       
   163             str(self.offset),
       
   164             self.format_type(),
       
   165             str(self.timestamp),
       
   166             self.format_source(),
       
   167             str(self.target),
       
   168             str(self.data)
       
   169         ))
   153 
   170 
   154     def __repr__ (self) :
   171     def __repr__ (self) :
   155         return "LogLine(%r, %s, %-12s, %s, %-35s, %-10s, %r)" % (
   172         return "LogLine(%r, %s, %-12s, %s, %-35s, %-10s, %r)" % (
   156             self.channel, self.offset, self.format_type(), self.timestamp, self.format_source(), self.target, self.data
   173             self.channel, self.offset, self.format_type(), self.timestamp, self.format_source(), self.target, self.data
   157         )
   174         )