summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2013-03-01 22:18:50 +0100
committermathieui <mathieui@mathieui.net>2013-03-01 22:18:50 +0100
commit4383a6abfc765c7083949b03319d0f9574fdfab2 (patch)
treece548e0f0b308020c88cdd8d799453194dfa476e
parente1956533a6e04d7ba2afdbc841b48804a84120b3 (diff)
downloadpoezio-4383a6abfc765c7083949b03319d0f9574fdfab2.tar.gz
poezio-4383a6abfc765c7083949b03319d0f9574fdfab2.tar.bz2
poezio-4383a6abfc765c7083949b03319d0f9574fdfab2.tar.xz
poezio-4383a6abfc765c7083949b03319d0f9574fdfab2.zip
Test to use slots instead of namedtuplesslots_test
-rw-r--r--src/text_buffer.py71
-rw-r--r--src/windows.py9
2 files changed, 52 insertions, 28 deletions
diff --git a/src/text_buffer.py b/src/text_buffer.py
index 0b9fc319..53ce25b7 100644
--- a/src/text_buffer.py
+++ b/src/text_buffer.py
@@ -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):
"""
diff --git a/src/windows.py b/src/windows.py
index 2d32da30..4c8793d2 100644
--- a/src/windows.py
+++ b/src/windows.py
@@ -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()