/usr/lib/python2.7/dist-packages/gozerbot/less.py is in gozerbot 0.99.1-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | # gozerbot/less.py
#
#
""" maintain bot output cache. """
__copyright__ = 'this file is in the public domain'
# ==============
# IMPORT SECTION
# gozerbot imports
from utils.limlist import Limlist
# END IMPORT
# ==========
# ============
# LOCK SECTION
# no locks
# END LOCK
# ========
class Less(object):
"""
output cache .. caches upto <nr> item of txt lines per nick.
:param nr: size of backlog
:type nr: integer
"""
def __init__(self, nr):
self.data = {}
self.index = {}
self.nr = nr
def add(self, nick, listoftxt):
"""
add listoftxt to nick's output .. set index for used by more
commands.
:param nick: nick to add txt to cache for
:type nick: string
:param listoftxt: list of txt to cache
:type listoftxt: list
.. literalinclude:: ../../gozerbot/less.py
:pyobject: Less.add
"""
nick = nick.lower()
# see if we already have cached output .. if not create limited list
if not self.data.has_key(nick):
self.data[nick] = Limlist(self.nr)
# add data
self.data[nick].insert(0, listoftxt)
self.index[nick] = 1
def get(self, nick, index1, index2):
"""
return less entry.
entry is self.data[nick][index1][index2]
:param nick: nick to get data for
:type nick: string
:param index1: number of txtlines back
:type index1: integer
:param index2: index into the txtlines
:type index2: integer
:rtype: string
.. literalinclude:: ../../gozerbot/less.py
:pyobject: Less.get
"""
nick = nick.lower()
try:
txt = self.data[nick][index1][index2]
except (KeyError, IndexError):
txt = None
return txt
def more(self, nick, index1):
"""
return more entry pointed to by index .. increase index.
:param nick: nick to fetch data for
:type nick: string
:param index1: index into cache data
:type index1: integer
:rtype: tuple .. (txt, index)
.. literalinclude:: ../../gozerbot/less.py
:pyobject: Less.more
"""
nick = nick.lower()
try:
nr = self.index[nick]
except KeyError:
nr = 1
try:
txt = self.data[nick][index1][nr]
size = len(self.data[nick][index1])-nr
self.index[nick] = nr+1
except (KeyError, IndexError):
txt = None
size = 0
return (txt, size-1)
def size(self, nick):
"""
return sizes of cached output.
:param nick: nick to get cache sizes for
:type nick: string
:rtype: list .. list of sizes
.. literalinclude:: ../../gozerbot/less.py
:pyobject: Less.size
"""
nick = nick.lower()
sizes = []
if not self.data.has_key(nick):
return sizes
for i in self.data[nick]:
sizes.append(len(i))
return sizes
# ============
# INIT SECTION
# no vars
# END INIT
# ========
|