5
""" maintain bot output cache. """
7
__copyright__ = 'this file is in the public domain'
13
from utils.limlist import Limlist
29
output cache .. caches upto <nr> item of txt lines per nick.
31
:param nr: size of backlog
36
def __init__(self, nr):
41
def add(self, nick, listoftxt):
44
add listoftxt to nick's output .. set index for used by more
47
:param nick: nick to add txt to cache for
49
:param listoftxt: list of txt to cache
52
.. literalinclude:: ../../gozerbot/less.py
59
# see if we already have cached output .. if not create limited list
60
if not self.data.has_key(nick):
61
self.data[nick] = Limlist(self.nr)
64
self.data[nick].insert(0, listoftxt)
67
def get(self, nick, index1, index2):
72
entry is self.data[nick][index1][index2]
74
:param nick: nick to get data for
76
:param index1: number of txtlines back
78
:param index2: index into the txtlines
82
.. literalinclude:: ../../gozerbot/less.py
90
txt = self.data[nick][index1][index2]
91
except (KeyError, IndexError):
95
def more(self, nick, index1):
98
return more entry pointed to by index .. increase index.
100
:param nick: nick to fetch data for
102
:param index1: index into cache data
103
:type index1: integer
104
:rtype: tuple .. (txt, index)
106
.. literalinclude:: ../../gozerbot/less.py
114
nr = self.index[nick]
119
txt = self.data[nick][index1][nr]
120
size = len(self.data[nick][index1])-nr
121
self.index[nick] = nr+1
122
except (KeyError, IndexError):
128
def size(self, nick):
131
return sizes of cached output.
133
:param nick: nick to get cache sizes for
135
:rtype: list .. list of sizes
137
.. literalinclude:: ../../gozerbot/less.py
145
if not self.data.has_key(nick):
148
for i in self.data[nick]:
b'\\ No newline at end of file'