summaryrefslogtreecommitdiff
path: root/src/text_buffer.py
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 /src/text_buffer.py
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
Diffstat (limited to 'src/text_buffer.py')
-rw-r--r--src/text_buffer.py71
1 files changed, 44 insertions, 27 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):
"""