Commit 4383a6ab authored by mathieui's avatar mathieui

Test to use slots instead of namedtuples

parent e1956533
......@@ -19,35 +19,52 @@ from config import config
from theming import get_theme
message_fields = 'txt nick_color time str_time nickname user identifier highlight me old_message revisions'
Message = collections.namedtuple('Message', message_fields)
class CorrectionError(Exception): pass
class Message(object):
__slots__ = ('txt', 'nick_color', 'time', 'str_time', 'nickname', 'user',
'identifier', 'highlight', 'me', 'old_message', 'revisions')
#'txt nick_color time str_time nickname user identifier highlight me old_message revisions'
def __init__(self, txt, nick_color, time, str_time, nickname, user, identifier, highlight, me, old_message, revisions):
self.txt = txt
self.nick_color = nick_color
self.time = time
self.str_time = str_time
self.nickname = nickname
self.user = user
self.identifier = identifier
self.highlight = highlight
self.me = me
self.old_message = old_message
self.revisions = revisions
@classmethod
def other_elems(obj):
acc = ['Message(']
fields = message_fields.split()
fields.remove('old_message')
for field in fields:
acc.append('%s=%s' % (field, getattr(self, field)))
return (', '.join(acc) + ', old_message=')
def __repr__(self):
init = other_elems(self)
acc = []
next = self.old_message
rev = 0
while next:
acc.append(self.other_elems(next))
next = next.old_message
rev += 1
acc.append('None')
while rev:
acc.append(')')
rev -= 1
return ''.join(acc)
__str__ = __repr__
def other_elems(self):
acc = ['Message(']
fields = message_fields.split()
fields.remove('old_message')
for field in fields:
acc.append('%s=%s' % (field, getattr(self, field)))
return (', '.join(acc) + ', old_message=')
def repr_message(self):
init = other_elems(self)
acc = []
next = self.old_message
rev = 0
while next:
acc.append(other_elems(next))
next = next.old_message
rev += 1
acc.append('None')
while rev:
acc.append(')')
rev -= 1
return ''.join(acc)
Message.__repr__ = repr_message
Message.__str__ = repr_message
class CorrectionError(Exception): pass
class TextBuffer(object):
"""
......
......@@ -43,7 +43,14 @@ allowed_color_digits = ('0', '1', '2', '3', '4', '5', '6', '7')
# msg is a reference to the corresponding Message tuple. text_start and text_end are the position
# delimiting the text in this line.
# first is a bool telling if this is the first line of the message.
Line = collections.namedtuple('Line', 'msg start_pos end_pos')
class Line(object):
__slots__ = ('msg', 'start_pos', 'end_pos')
def __init__(self, msg, start_pos, end_pos):
self.msg = msg
self.start_pos = start_pos
self.end_pos = end_pos
g_lock = RLock()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment