]> de.git.xonotic.org Git - xonotic/xonstat.git/blobdiff - xonstat/util.py
Remove Persona since it was shut down. :(
[xonotic/xonstat.git] / xonstat / util.py
index dc752f7c5bea2e65d2dd9ecdbd5694e04deaa2f7..4ed6aeea18640cfebb88e3aaf984853472bf5629 100644 (file)
@@ -1,6 +1,7 @@
 import sys
 import logging
 import pyramid.httpexceptions
 import sys
 import logging
 import pyramid.httpexceptions
+import pyramid.url
 import re
 from colorsys import rgb_to_hls, hls_to_rgb
 from cgi import escape as html_escape
 import re
 from colorsys import rgb_to_hls, hls_to_rgb
 from cgi import escape as html_escape
@@ -13,6 +14,17 @@ from xonstat.d0_blind_id import d0_blind_id_verify
 log = logging.getLogger(__name__)
 
 
 log = logging.getLogger(__name__)
 
 
+# Map of old weapons codes to new ones
+weapon_map = {
+  "grenadelauncher": "mortar", 
+  "laser": "blaster", 
+  "minstanex": "vaporizer", 
+  "nex": "vortex", 
+  "rocketlauncher": "devastator", 
+  "uzi": "machinegun", 
+}
+
+
 # Map of special chars to ascii from Darkplace's console.c.
 _qfont_ascii_table = [
  '\0', '#',  '#',  '#',  '#',  '.',  '#',  '#',
 # Map of special chars to ascii from Darkplace's console.c.
 _qfont_ascii_table = [
  '\0', '#',  '#',  '#',  '#',  '.',  '#',  '#',
@@ -55,7 +67,7 @@ _qfont_unicode_glyphs = [
    u'\u005F',       u'\u2747',       u'\u2020',       u'\u00B7',
    u'\U0001F52B',   u'\u0020',       u'\u0020',       u'\u25A0',
    u'\u2022',       u'\u2192',       u'\u2748',       u'\u2748',
    u'\u005F',       u'\u2747',       u'\u2020',       u'\u00B7',
    u'\U0001F52B',   u'\u0020',       u'\u0020',       u'\u25A0',
    u'\u2022',       u'\u2192',       u'\u2748',       u'\u2748',
-   u'\u005B',       u'\u005D',       u'\U0001F47D',   u'\U0001F60F',
+   u'\u005B',       u'\u005D',       u'\U0001F47D',   u'\U0001F603',
    u'\U0001F61E',   u'\U0001F635',   u'\U0001F615',   u'\U0001F60A',
    u'\u00AB',       u'\u00BB',       u'\u2022',       u'\u203E',
    u'\u2748',       u'\u25AC',       u'\u25AC',       u'\u25AC',
    u'\U0001F61E',   u'\U0001F635',   u'\U0001F615',   u'\U0001F60A',
    u'\u00AB',       u'\u00BB',       u'\u2022',       u'\u203E',
    u'\u2748',       u'\u25AC',       u'\u25AC',       u'\u25AC',
@@ -87,7 +99,7 @@ _qfont_unicode_glyphs = [
    u'\u00A1',       u'\u004F',       u'\u0055',       u'\u0049',
    u'\u0043',       u'\u00A9',       u'\u00AE',       u'\u25A0',
    u'\u00BF',       u'\u25B6',       u'\u2748',       u'\u2748',
    u'\u00A1',       u'\u004F',       u'\u0055',       u'\u0049',
    u'\u0043',       u'\u00A9',       u'\u00AE',       u'\u25A0',
    u'\u00BF',       u'\u25B6',       u'\u2748',       u'\u2748',
-   u'\u2772',       u'\u2773',       u'\U0001F47D',   u'\U0001F60F',
+   u'\u2772',       u'\u2773',       u'\U0001F47D',   u'\U0001F603',
    u'\U0001F61E',   u'\U0001F635',   u'\U0001F615',   u'\U0001F60A',
    u'\u00AB',       u'\u00BB',       u'\u2747',       u'\u0078',
    u'\u2748',       u'\u2014',       u'\u2014',       u'\u2014',
    u'\U0001F61E',   u'\U0001F635',   u'\U0001F615',   u'\U0001F60A',
    u'\u00AB',       u'\u00BB',       u'\u2747',       u'\u0078',
    u'\u2748',       u'\u2014',       u'\u2014',       u'\u2014',
@@ -140,10 +152,10 @@ _hex_colors = re.compile(r'\^x([\dA-Fa-f])([\dA-Fa-f])([\dA-Fa-f])')
 _contrast_threshold = 0.5
 
 
 _contrast_threshold = 0.5
 
 
-def qfont_decode(qstr='', for_html=False):
+def qfont_decode(qstr='', glyph_translation=False):
     """ Convert the qfont characters in a string to ascii.
 
     """ Convert the qfont characters in a string to ascii.
 
-        for_html - determines whether to convert the unicode characters to
+        glyph_translation - determines whether to convert the unicode characters to
                    their ascii counterparts (if False, the default) or to
                    the mapped glyph in the Xolonium font (if True).
     """
                    their ascii counterparts (if False, the default) or to
                    the mapped glyph in the Xolonium font (if True).
     """
@@ -152,7 +164,7 @@ def qfont_decode(qstr='', for_html=False):
     chars = []
     for c in qstr:
         if u'\ue000' <= c <= u'\ue0ff':
     chars = []
     for c in qstr:
         if u'\ue000' <= c <= u'\ue0ff':
-            if for_html:
+            if glyph_translation:
                 c = _qfont_unicode_glyphs[ord(c) - 0xe000]
             else:
                 c = _qfont_ascii_table[ord(c) - 0xe000]
                 c = _qfont_unicode_glyphs[ord(c) - 0xe000]
             else:
                 c = _qfont_ascii_table[ord(c) - 0xe000]
@@ -186,7 +198,7 @@ def hex_repl(match):
 
 
 def html_colors(qstr='', limit=None):
 
 
 def html_colors(qstr='', limit=None):
-    qstr = html_escape(qfont_decode(qstr, for_html=True))
+    qstr = html_escape(qfont_decode(qstr, glyph_translation=True))
     qstr = qstr.replace('^^', '^')
 
     if limit is not None and limit > 0:
     qstr = qstr.replace('^^', '^')
 
     if limit is not None and limit > 0:
@@ -217,7 +229,7 @@ def limit_printable_characters(qstr, limit):
 
 
 def page_url(page):
 
 
 def page_url(page):
-    return current_route_url(request, page=page, _query=request.GET)
+    return pyramid.url.current_route_url(request, page=page, _query=request.GET)
 
 
 def pretty_date(time=False):
 
 
 def pretty_date(time=False):