# define objects for all tables
class Player(object):
- def nick_html_colors(self):
+ def nick_html_colors(self, limit=None):
if self.nick is None:
return "Anonymous Player"
else:
- return html_colors(self.nick)
+ return html_colors(self.nick, limit)
def nick_strip_colors(self):
if self.nick is None:
class Game(object):
- def __init__(self, game_id=None, start_dt=None, game_type_cd=None,
+ def __init__(self, game_id=None, start_dt=None, game_type_cd=None,
server_id=None, map_id=None, winner=None):
self.game_id = game_id
self.start_dt = start_dt
else:
return strip_colors(self.nick)
- def nick_html_colors(self):
+ def nick_html_colors(self, limit=None):
if self.nick is None:
return "Anonymous Player"
else:
- return html_colors(self.nick)
+ return html_colors(self.nick, limit)
def team_html_color(self):
if self.team == 5:
class PlayerRank(object):
- def nick_html_colors(self):
+ def nick_html_colors(self, limit=None):
if self.nick is None:
return "Anonymous Player"
else:
- return html_colors(self.nick)
+ return html_colors(self.nick, limit)
def __repr__(self):
return "<PlayerRank(pid=%s, gametype=%s, rank=%s)>" % (self.player_id, self.game_type_cd, self.rank)
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', '{', '|', '}', '~', '<',
-
+
'<', '=', '>', '#', '#', '.', '#', '#',
'#', '#', ' ', '#', ' ', '>', '.', '.',
'[', ']', '0', '1', '2', '3', '4', '5',
return '<span style="color:rgb(%d,%d,%d)">' % (255 * r, 255 * g, 255 * b)
-def html_colors(qstr=''):
- qstr = html_escape(qfont_decode(qstr).replace('^^', '^'))
+def html_colors(qstr='', limit=None):
+ qstr = html_escape(qfont_decode(qstr))
+ qstr = qstr.replace('^^', '^')
+
+ if limit is not None and limit > 0:
+ qstr = limit_printable_characters(qstr, limit)
+
html = _dec_colors.sub(lambda match: _dec_spans[int(match.group(1))], qstr)
html = _hex_colors.sub(hex_repl, html)
return html + "</span>" * len(_all_colors.findall(qstr))
+def limit_printable_characters(qstr, limit):
+ # initialize assuming all printable characters
+ pc = [1 for i in range(len(qstr))]
+
+ groups = _all_colors.finditer(qstr)
+ for g in groups:
+ pc[g.start():g.end()] = [0 for i in range(g.end() - g.start())]
+
+ # printable characters in the string is less than or equal to what was requested
+ if limit >= len(qstr) or sum(pc) <= limit:
+ return qstr
+ else:
+ sumpc = 0
+ for i,v in enumerate(pc):
+ sumpc += v
+ if sumpc == limit:
+ return qstr[0:i+1]
+
+
def page_url(page):
return current_route_url(request, page=page, _query=request.GET)