Browse Source

Py3: Remove special_fixer and deunicode

Should not be needed anymore
pull/1253/head
Safihre 6 years ago
parent
commit
e5c1250310
  1. 5
      SABnzbd.py
  2. 1
      sabnzbd/__init__.py
  3. 4
      sabnzbd/api.py
  4. 89
      sabnzbd/encoding.py
  5. 4
      sabnzbd/filesystem.py
  6. 4
      sabnzbd/interface.py
  7. 6
      sabnzbd/newsunpack.py
  8. 4
      sabnzbd/utils/rarfile.py

5
SABnzbd.py

@ -60,7 +60,7 @@ import sabnzbd.scheduler as scheduler
import sabnzbd.config as config import sabnzbd.config as config
import sabnzbd.cfg import sabnzbd.cfg
import sabnzbd.downloader import sabnzbd.downloader
from sabnzbd.encoding import unicoder, deunicode from sabnzbd.encoding import unicoder
import sabnzbd.notifier as notifier import sabnzbd.notifier as notifier
import sabnzbd.zconfig import sabnzbd.zconfig
@ -273,7 +273,6 @@ def CheckColor(color, web_dir):
def fix_webname(name): def fix_webname(name):
if name: if name:
name = deunicode(name)
xname = name.title() xname = name.title()
else: else:
xname = '' xname = ''
@ -479,7 +478,7 @@ def get_webhost(cherryhost, cherryport, https_port):
cherryhost = '' cherryhost = ''
if cherryhost is None: if cherryhost is None:
cherryhost = deunicode(sabnzbd.cfg.cherryhost()) cherryhost = sabnzbd.cfg.cherryhost()
else: else:
sabnzbd.cfg.cherryhost.set(cherryhost) sabnzbd.cfg.cherryhost.set(cherryhost)

1
sabnzbd/__init__.py

@ -653,7 +653,6 @@ def add_nzbfile(nzbfile, pp=None, script=None, cat=None, priority=NORMAL_PRIORIT
except: except:
# Correct encoding after all! # Correct encoding after all!
filename = nzbfile.filename filename = nzbfile.filename
filename = encoding.special_fixer(filename)
keep = False keep = False
if not sabnzbd.WIN32: if not sabnzbd.WIN32:

4
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, \ from sabnzbd.filesystem import diskspace, get_ext, get_filename, globber, \
globber_full, clip_path, remove_all globber_full, clip_path, remove_all
from sabnzbd.filesystem import same_file 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.postproc import PostProcessor
from sabnzbd.articlecache import ArticleCache from sabnzbd.articlecache import ArticleCache
from sabnzbd.utils.servertests import test_nntp_server_dict from sabnzbd.utils.servertests import test_nntp_server_dict
@ -185,7 +185,7 @@ def _api_queue_rename(output, value, kwargs):
value2 = kwargs.get('value2') value2 = kwargs.get('value2')
value3 = kwargs.get('value3') value3 = kwargs.get('value3')
if value and value2: 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}) return report(output, keyword='', data={'status': ret})
else: else:
return report(output, _MSG_NO_VALUE2) return report(output, _MSG_NO_VALUE2)

89
sabnzbd/encoding.py

@ -106,27 +106,6 @@ def yenc_name_fixer(p):
return p.decode('cp1252', errors='replace').replace('?', '!') 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): def unicoder(p, force=False):
return p return p
""" Make sure a Unicode string is returned """ Make sure a Unicode string is returned
@ -197,71 +176,3 @@ class EmailFilter(Filter):
return '' return ''
else: else:
return str(str(val)) 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
#'<' : '&lt;', # Not yet, texts need to be cleaned from HTML first
'"': '&quot;',
"'": '&apos;'
}
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)

4
sabnzbd/filesystem.py

@ -32,7 +32,7 @@ import stat
import sabnzbd import sabnzbd
from sabnzbd.decorators import synchronized from sabnzbd.decorators import synchronized
from sabnzbd.constants import FUTURE_Q_FOLDER, JOB_ADMIN, GIGI 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): def get_ext(filename):
@ -434,6 +434,8 @@ def trim_win_path(path):
def fix_unix_encoding(folder): def fix_unix_encoding(folder):
""" Fix bad name encoding for Unix systems """ """ Fix bad name encoding for Unix systems """
# TODO: Remove?!
return
if not sabnzbd.WIN32 and not sabnzbd.DARWIN and gUTF: if not sabnzbd.WIN32 and not sabnzbd.DARWIN and gUTF:
for root, dirs, files in os.walk(folder.encode('utf-8')): for root, dirs, files in os.walk(folder.encode('utf-8')):
for name in files: for name in files:

4
sabnzbd/interface.py

@ -45,7 +45,7 @@ from sabnzbd.filesystem import real_path, long_path, globber, globber_full, remo
clip_path, same_file clip_path, same_file
from sabnzbd.newswrapper import GetServerParms from sabnzbd.newswrapper import GetServerParms
from sabnzbd.bpsmeter import BPSMeter 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.config as config
import sabnzbd.cfg as cfg import sabnzbd.cfg as cfg
import sabnzbd.notifier as notifier import sabnzbd.notifier as notifier
@ -874,7 +874,7 @@ class NzoPage(object):
if index is not None: if index is not None:
NzbQueue.do.switch(nzo_id, index) NzbQueue.do.switch(nzo_id, index)
if name is not None: 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'): 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) NzbQueue.do.change_cat(nzo_id, cat, priority)

6
sabnzbd/newsunpack.py

@ -31,7 +31,7 @@ import functools
from subprocess import Popen from subprocess import Popen
import sabnzbd 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 import sabnzbd.utils.rarfile as rarfile
from sabnzbd.misc import format_time_string, find_on_path, int_conv, \ from sabnzbd.misc import format_time_string, find_on_path, int_conv, \
get_all_passwords, calc_age, cmp get_all_passwords, calc_age, cmp
@ -1959,8 +1959,6 @@ def create_env(nzo=None, extra_env_fields={}):
# No modification # No modification
return None return None
# Have to make sure no Unicode slipped in somehow
env = { deunicode(k): deunicode(v) for k, v in env.items() }
return env return env
@ -2328,7 +2326,7 @@ def pre_queue(nzo, pp, cat):
for line in output.split('\n'): for line in output.split('\n'):
line = line.strip('\r\n \'"') line = line.strip('\r\n \'"')
if n < len(values) and line: if n < len(values) and line:
values[n] = deunicode(line) values[n] = line
n += 1 n += 1
accept = int_conv(values[0]) accept = int_conv(values[0])
if accept < 1: if accept < 1:

4
sabnzbd/utils/rarfile.py

@ -823,10 +823,8 @@ class RarFile(object):
"""Let 'unrar' test the archive. """Let 'unrar' test the archive.
""" """
# Modified for SABnzbd by clipping paths # Modified for SABnzbd by clipping paths
# and de-unicoding only here
from sabnzbd.filesystem import clip_path from sabnzbd.filesystem import clip_path
from sabnzbd.encoding import deunicode rarpath = clip_path(self._rarfile)
rarpath = deunicode(clip_path(self._rarfile))
cmd = [UNRAR_TOOL] + list(TEST_ARGS) cmd = [UNRAR_TOOL] + list(TEST_ARGS)
add_password_arg(cmd, self._password) add_password_arg(cmd, self._password)

Loading…
Cancel
Save