Browse Source

Do HTML quoting for " and ' characters in skin texts.

Improve skin text translation cache implementation.
tags/0.7.0Beta6
shypike 13 years ago
parent
commit
9610a5a0dd
  1. 2
      SABnzbd.py
  2. 3
      sabnzbd/__init__.py
  3. 26
      sabnzbd/api.py
  4. 16
      sabnzbd/encoding.py
  5. 2
      sabnzbd/interface.py
  6. 3
      sabnzbd/osxmenu.py
  7. 2
      sabnzbd/sabtray.py
  8. 2
      sabnzbd/wizard.py

2
SABnzbd.py

@ -1483,6 +1483,8 @@ def main():
# Wait for server to become ready
cherrypy.engine.wait(cherrypy.process.wspbus.states.STARTED)
sabnzbd.WEBUI_READY = True
if enable_https:
browser_url = "https://%s:%s/sabnzbd" % (browserhost, cherryport)
else:

3
sabnzbd/__init__.py

@ -129,6 +129,7 @@ PAUSED_ALL = False
OLD_QUEUE = False
SCHED_RESTART = False # Set when restarted through scheduler
WINTRAY = None # Thread for the Windows SysTray icon
WEBUI_READY = False
__INITIALIZED__ = False
__SHUTTING_DOWN__ = False
@ -259,7 +260,7 @@ def initialize(pause_downloader = False, clean_up = False, evalSched=False, repa
### Set language files
lang.set_locale_info('SABnzbd', DIR_LANGUAGE)
lang.set_language(cfg.language())
sabnzbd.api.cache_skin_trans()
sabnzbd.api.clear_trans_cache()
### Check for old queue (when a new queue is not present)
if not os.path.exists(os.path.join(cfg.cache_dir.get_path(), QUEUE_FILE_NAME)):

26
sabnzbd/api.py

@ -53,7 +53,7 @@ from sabnzbd.utils.pathbrowser import folders_at_path
from sabnzbd.misc import loadavg, to_units, diskfree, disktotal, get_ext, \
get_filename, int_conv, globber, time_format, remove_all, \
starts_with_path
from sabnzbd.encoding import xml_name, unicoder, special_fixer, platform_encode
from sabnzbd.encoding import xml_name, unicoder, special_fixer, platform_encode, html_escape
from sabnzbd.postproc import PostProcessor
from sabnzbd.articlecache import ArticleCache
from sabnzbd.utils.servertests import test_nntp_server_dict
@ -1517,21 +1517,25 @@ _SKIN_CACHE = {} # Stores pre-translated acronyms
def Ttemplate(txt):
""" Translation function for Skin texts
"""
return _SKIN_CACHE.get(txt, txt)
global _SKIN_CACHE
if txt in _SKIN_CACHE:
return _SKIN_CACHE[txt]
else:
tra = html_escape(Tx(SKIN_TEXT.get(txt, txt)))
_SKIN_CACHE[txt] = tra
return tra
def cache_skin_trans():
""" Build cache for skin translations
def clear_trans_cache():
""" Clean cache for skin translations
"""
global _SKIN_CACHE
for txt in SKIN_TEXT:
_SKIN_CACHE[txt] = Tx(SKIN_TEXT.get(txt, txt))
# One dummy entry needed for check_trans()
dummy = _SKIN_CACHE
_SKIN_CACHE = {}
del dummy
logging.debug('Cleared translation cache')
def check_trans():
""" Check whether language has been initialized
"""
global _SKIN_CACHE
return bool(_SKIN_CACHE)
def build_header(prim, webdir=''):
try:

16
sabnzbd/encoding.py

@ -323,4 +323,20 @@ def fixup_ff4(p):
return ''.join(name)
_HTML_TABLE = {
#'&' : '&', # Not yet, texts need to be cleaned from HTML first
#'>' : '>', # Not yet, texts need to be cleaned from HTML first
#'<' : '&lt;', # Not yet, texts need to be cleaned from HTML first
'"' : '&#34;',
"'" : '&#39;'
}
def html_escape(txt):
""" Replace HTML metacharacters with &-constructs """
# Replacement for inefficient xml.sax.saxutils.escape function
if [True for ch in _HTML_TABLE if ch in txt]:
return ''.join((_HTML_TABLE.get(ch, ch) for ch in txt))
else:
return txt
auto_fsys()

2
sabnzbd/interface.py

@ -1369,7 +1369,7 @@ class ConfigGeneral(object):
if language and language != cfg.language():
cfg.language.set(language)
set_language(language)
sabnzbd.api.cache_skin_trans()
sabnzbd.api.clear_trans_cache()
cleanup_list = kwargs.get('cleanup_list')
if cleanup_list and sabnzbd.WIN32:

3
sabnzbd/osxmenu.py

@ -50,7 +50,6 @@ import sabnzbd.dirscanner as dirscanner
from sabnzbd.bpsmeter import BPSMeter
from sabnzbd.newzbin import Bookmarks
from sabnzbd.database import get_history_handle
from sabnzbd.api import check_trans
status_icons = {'idle':'../Resources/sab_idle.png','pause':'../Resources/sab_pause.png','clicked':'../Resources/sab_clicked.png'}
start_time = NSDate.date()
@ -93,7 +92,7 @@ class SABnzbdDelegate(NSObject):
#cherrypy.engine.wait(cherrypy.process.wspbus.states.STARTED)
# Wait for translated texts to be loaded
while not check_trans() and not sabnzbd.SABSTOP:
while not sabnzbd.WEBUI_READY and not sabnzbd.SABSTOP:
time.sleep(0.5)
if (debug == 1) : NSLog("[osx] language file not loaded, waiting")

2
sabnzbd/sabtray.py

@ -45,7 +45,7 @@ class SABTrayThread(SysTrayIconThread):
def __init__(self):
# Wait for translated texts to be loaded
while not api.check_trans():
while not sabnzbd.WEBUI_READY:
sleep(0.2)
logging.debug('language file not loaded, waiting')

2
sabnzbd/wizard.py

@ -77,7 +77,7 @@ class Wizard(object):
language = kwargs.get('lang')
cfg.language.set(language)
set_language(language)
sabnzbd.api.cache_skin_trans()
sabnzbd.api.clear_trans_cache()
# Always setup Plush
sabnzbd.interface.change_web_dir('Plush - Gold')

Loading…
Cancel
Save