diff --git a/SABnzbd.py b/SABnzbd.py index bb7e1b1..3f080de 100755 --- a/SABnzbd.py +++ b/SABnzbd.py @@ -60,7 +60,7 @@ import sabnzbd.scheduler as scheduler import sabnzbd.config as config import sabnzbd.cfg import sabnzbd.downloader -from sabnzbd.encoding import unicoder, deunicode +from sabnzbd.encoding import unicoder import sabnzbd.notifier as notifier import sabnzbd.zconfig @@ -273,7 +273,6 @@ def CheckColor(color, web_dir): def fix_webname(name): if name: - name = deunicode(name) xname = name.title() else: xname = '' @@ -479,7 +478,7 @@ def get_webhost(cherryhost, cherryport, https_port): cherryhost = '' if cherryhost is None: - cherryhost = deunicode(sabnzbd.cfg.cherryhost()) + cherryhost = sabnzbd.cfg.cherryhost() else: sabnzbd.cfg.cherryhost.set(cherryhost) diff --git a/sabnzbd/__init__.py b/sabnzbd/__init__.py index 03ef13d..fd7d4be 100644 --- a/sabnzbd/__init__.py +++ b/sabnzbd/__init__.py @@ -653,7 +653,6 @@ def add_nzbfile(nzbfile, pp=None, script=None, cat=None, priority=NORMAL_PRIORIT except: # Correct encoding after all! filename = nzbfile.filename - filename = encoding.special_fixer(filename) keep = False if not sabnzbd.WIN32: diff --git a/sabnzbd/api.py b/sabnzbd/api.py index 0de0a1e..be103ab 100644 --- a/sabnzbd/api.py +++ b/sabnzbd/api.py @@ -53,7 +53,7 @@ from sabnzbd.misc import loadavg, to_units, int_conv, time_format, \ from sabnzbd.filesystem import diskspace, get_ext, get_filename, globber, \ globber_full, clip_path, remove_all from sabnzbd.filesystem import same_file -from sabnzbd.encoding import xml_name, unicoder, special_fixer, platform_encode +from sabnzbd.encoding import xml_name, unicoder, platform_encode from sabnzbd.postproc import PostProcessor from sabnzbd.articlecache import ArticleCache from sabnzbd.utils.servertests import test_nntp_server_dict @@ -185,7 +185,7 @@ def _api_queue_rename(output, value, kwargs): value2 = kwargs.get('value2') value3 = kwargs.get('value3') if value and value2: - ret = NzbQueue.do.change_name(value, special_fixer(value2), special_fixer(value3)) + ret = NzbQueue.do.change_name(value, value2, value3) return report(output, keyword='', data={'status': ret}) else: return report(output, _MSG_NO_VALUE2) diff --git a/sabnzbd/encoding.py b/sabnzbd/encoding.py index e99f2da..a566f5e 100644 --- a/sabnzbd/encoding.py +++ b/sabnzbd/encoding.py @@ -106,27 +106,6 @@ def yenc_name_fixer(p): return p.decode('cp1252', errors='replace').replace('?', '!') -def special_fixer(p): - """ Return string appropriate for the platform. - Also takes care of the situation where a non-Windows/UTF-8 system - receives a latin-1 encoded name. - """ - if p: - # Remove \" constructions from incoming headers - p = p.replace(r'\"', r'"') - if not p or isinstance(p, str): - return p - try: - # First see if it isn't just UTF-8 - p.decode('utf-8') - if sabnzbd.DARWIN and '&#' in p: - p = fixup_ff4(p) - return p.decode('utf-8') - except: - # Now assume it's 8bit ASCII - return p.decode(codepage) - - def unicoder(p, force=False): return p """ Make sure a Unicode string is returned @@ -197,71 +176,3 @@ class EmailFilter(Filter): return '' else: return str(str(val)) - - -def fixup_ff4(p): - return p - """ Fix incompatibility between CherryPy and Firefox-4 on OSX, - where a filename contains &#xx; encodings - """ - name = [] - num = 0 - start = amp = False - for ch in p: - if start: - if ch.isdigit(): - num += ch - elif ch == ';': - name.append(chr(int(num)).encode('utf8')) - start = False - else: - name.append('&#%s%s' % (num, ch)) - start = False - elif ch == '&': - amp = True - elif amp: - amp = False - if ch == '#': - start = True - num = '' - else: - name.append('&' + ch) - else: - name.append(ch) - 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 - #'<' : '<', # Not yet, texts need to be cleaned from HTML first - '"': '"', - "'": ''' -} - - -def deunicode(p): - return p - """ Return the correct 8bit ASCII encoding for the platform: - Latin-1 for Windows/Posix-non-UTF and UTF-8 for OSX/Posix-UTF - """ - if isinstance(p, str): - if gUTF: - return p.encode('utf-8') - else: - return p.encode(codepage, 'replace') - elif isinstance(p, str): - if gUTF: - try: - p.decode('utf-8') - return p - except: - return p.decode(codepage).encode('utf-8') - else: - try: - return p.decode('utf-8').encode(codepage, 'replace') - except: - return p - else: - return str(p) - diff --git a/sabnzbd/filesystem.py b/sabnzbd/filesystem.py index f1473ac..c812124 100644 --- a/sabnzbd/filesystem.py +++ b/sabnzbd/filesystem.py @@ -32,7 +32,7 @@ import stat import sabnzbd from sabnzbd.decorators import synchronized from sabnzbd.constants import FUTURE_Q_FOLDER, JOB_ADMIN, GIGI -from sabnzbd.encoding import special_fixer, gUTF +from sabnzbd.encoding import gUTF def get_ext(filename): @@ -434,6 +434,8 @@ def trim_win_path(path): def fix_unix_encoding(folder): """ Fix bad name encoding for Unix systems """ + # TODO: Remove?! + return if not sabnzbd.WIN32 and not sabnzbd.DARWIN and gUTF: for root, dirs, files in os.walk(folder.encode('utf-8')): for name in files: diff --git a/sabnzbd/interface.py b/sabnzbd/interface.py index 1b82f2c..1c5991a 100644 --- a/sabnzbd/interface.py +++ b/sabnzbd/interface.py @@ -45,7 +45,7 @@ from sabnzbd.filesystem import real_path, long_path, globber, globber_full, remo clip_path, same_file from sabnzbd.newswrapper import GetServerParms from sabnzbd.bpsmeter import BPSMeter -from sabnzbd.encoding import xml_name, LatinFilter, special_fixer, platform_encode +from sabnzbd.encoding import xml_name, LatinFilter, platform_encode import sabnzbd.config as config import sabnzbd.cfg as cfg import sabnzbd.notifier as notifier @@ -874,7 +874,7 @@ class NzoPage(object): if index is not None: NzbQueue.do.switch(nzo_id, index) if name is not None: - NzbQueue.do.change_name(nzo_id, special_fixer(name), password) + NzbQueue.do.change_name(nzo_id, name, password) if cat is not None and nzo.cat is not cat and not (nzo.cat == '*' and cat == 'Default'): NzbQueue.do.change_cat(nzo_id, cat, priority) diff --git a/sabnzbd/newsunpack.py b/sabnzbd/newsunpack.py index f3bf93c..b06268e 100644 --- a/sabnzbd/newsunpack.py +++ b/sabnzbd/newsunpack.py @@ -31,7 +31,7 @@ import functools from subprocess import Popen import sabnzbd -from sabnzbd.encoding import platform_encode, deunicode, platform_btou +from sabnzbd.encoding import platform_encode, platform_btou import sabnzbd.utils.rarfile as rarfile from sabnzbd.misc import format_time_string, find_on_path, int_conv, \ get_all_passwords, calc_age, cmp @@ -1959,8 +1959,6 @@ def create_env(nzo=None, extra_env_fields={}): # No modification return None - # Have to make sure no Unicode slipped in somehow - env = { deunicode(k): deunicode(v) for k, v in env.items() } return env @@ -2328,7 +2326,7 @@ def pre_queue(nzo, pp, cat): for line in output.split('\n'): line = line.strip('\r\n \'"') if n < len(values) and line: - values[n] = deunicode(line) + values[n] = line n += 1 accept = int_conv(values[0]) if accept < 1: diff --git a/sabnzbd/utils/rarfile.py b/sabnzbd/utils/rarfile.py index 263d059..d271f5f 100644 --- a/sabnzbd/utils/rarfile.py +++ b/sabnzbd/utils/rarfile.py @@ -823,10 +823,8 @@ class RarFile(object): """Let 'unrar' test the archive. """ # Modified for SABnzbd by clipping paths - # and de-unicoding only here from sabnzbd.filesystem import clip_path - from sabnzbd.encoding import deunicode - rarpath = deunicode(clip_path(self._rarfile)) + rarpath = clip_path(self._rarfile) cmd = [UNRAR_TOOL] + list(TEST_ARGS) add_password_arg(cmd, self._password)