mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-22 06:13:19 -07:00
Remove PY2 checks
This commit is contained in:
parent
b1a8a89cf6
commit
683411bfe1
3 changed files with 31 additions and 108 deletions
|
@ -37,9 +37,6 @@ CONFIG_TV_FILE = os.path.join(APP_ROOT, 'autoProcessTv.cfg')
|
||||||
TEST_FILE = os.path.join(APP_ROOT, 'tests', 'test.mp4')
|
TEST_FILE = os.path.join(APP_ROOT, 'tests', 'test.mp4')
|
||||||
MYAPP = None
|
MYAPP = None
|
||||||
|
|
||||||
import six
|
|
||||||
from six.moves import reload_module
|
|
||||||
|
|
||||||
from core import logger, main_db, version_check, databases, transcoder
|
from core import logger, main_db, version_check, databases, transcoder
|
||||||
from core.configuration import config
|
from core.configuration import config
|
||||||
from core.plugins.downloaders.configuration import (
|
from core.plugins.downloaders.configuration import (
|
||||||
|
@ -305,23 +302,6 @@ def configure_locale():
|
||||||
if not SYS_ENCODING or SYS_ENCODING in ('ANSI_X3.4-1968', 'US-ASCII', 'ASCII'):
|
if not SYS_ENCODING or SYS_ENCODING in ('ANSI_X3.4-1968', 'US-ASCII', 'ASCII'):
|
||||||
SYS_ENCODING = 'UTF-8'
|
SYS_ENCODING = 'UTF-8'
|
||||||
|
|
||||||
if six.PY2:
|
|
||||||
if not hasattr(sys, 'setdefaultencoding'):
|
|
||||||
reload_module(sys)
|
|
||||||
|
|
||||||
try:
|
|
||||||
# pylint: disable=E1101
|
|
||||||
# On non-unicode builds this will raise an AttributeError, if encoding type is not valid it throws a LookupError
|
|
||||||
sys.setdefaultencoding(SYS_ENCODING)
|
|
||||||
except Exception:
|
|
||||||
print('Sorry, you MUST add the nzbToMedia folder to the PYTHONPATH environment variable'
|
|
||||||
'\nor find another way to force Python to use {codec} for string encoding.'.format
|
|
||||||
(codec=SYS_ENCODING))
|
|
||||||
if 'NZBOP_SCRIPTDIR' in os.environ:
|
|
||||||
sys.exit(NZBGET_POSTPROCESS_ERROR)
|
|
||||||
else:
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def configure_migration():
|
def configure_migration():
|
||||||
global CONFIG_FILE
|
global CONFIG_FILE
|
||||||
|
|
|
@ -2,36 +2,11 @@ import re
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from six import text_type, PY2
|
from six import text_type
|
||||||
|
|
||||||
import core
|
import core
|
||||||
from core import logger
|
from core import logger
|
||||||
|
|
||||||
if PY2:
|
|
||||||
class Row(sqlite3.Row, object):
|
|
||||||
"""
|
|
||||||
Row factory that uses Byte Strings for keys.
|
|
||||||
|
|
||||||
The sqlite3.Row in Python 2 does not support unicode keys.
|
|
||||||
This overrides __getitem__ to attempt to encode the key to bytes first.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __getitem__(self, item):
|
|
||||||
"""
|
|
||||||
Get an item from the row by index or key.
|
|
||||||
|
|
||||||
:param item: Index or Key of item to return.
|
|
||||||
:return: An item from the sqlite3.Row.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
# sqlite3.Row column names should be Bytes in Python 2
|
|
||||||
item = item.encode()
|
|
||||||
except AttributeError:
|
|
||||||
pass # assume item is a numeric index
|
|
||||||
|
|
||||||
return super(Row, self).__getitem__(item)
|
|
||||||
else:
|
|
||||||
from sqlite3 import Row
|
|
||||||
|
|
||||||
def db_filename(filename='nzbtomedia.db', suffix=None):
|
def db_filename(filename='nzbtomedia.db', suffix=None):
|
||||||
"""
|
"""
|
||||||
|
@ -53,7 +28,7 @@ class DBConnection:
|
||||||
|
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.connection = sqlite3.connect(db_filename(filename), 20)
|
self.connection = sqlite3.connect(db_filename(filename), 20)
|
||||||
self.connection.row_factory = Row
|
self.connection.row_factory = sqlite3.Row
|
||||||
|
|
||||||
def check_db_version(self):
|
def check_db_version(self):
|
||||||
result = None
|
result = None
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
import os
|
import os
|
||||||
|
from builtins import bytes
|
||||||
|
|
||||||
from six import text_type
|
from six import text_type
|
||||||
from six import PY2
|
|
||||||
|
|
||||||
import core
|
import core
|
||||||
from core import logger
|
from core import logger
|
||||||
|
|
||||||
if not PY2:
|
|
||||||
from builtins import bytes
|
|
||||||
|
|
||||||
|
|
||||||
def char_replace(name_in):
|
def char_replace(name_in):
|
||||||
# Special character hex range:
|
# Special character hex range:
|
||||||
|
@ -21,35 +18,6 @@ def char_replace(name_in):
|
||||||
encoding = None
|
encoding = None
|
||||||
if isinstance(name_in, text_type):
|
if isinstance(name_in, text_type):
|
||||||
return encoded, name_in
|
return encoded, name_in
|
||||||
if PY2:
|
|
||||||
name = name_in
|
|
||||||
for Idx in range(len(name)):
|
|
||||||
# print('Trying to intuit the encoding')
|
|
||||||
# /!\ detection is done 2char by 2char for UTF-8 special character
|
|
||||||
if (len(name) != 1) & (Idx < (len(name) - 1)):
|
|
||||||
# Detect UTF-8
|
|
||||||
if ((name[Idx] == '\xC2') | (name[Idx] == '\xC3')) & (
|
|
||||||
(name[Idx + 1] >= '\xA0') & (name[Idx + 1] <= '\xFF')):
|
|
||||||
encoding = 'utf-8'
|
|
||||||
break
|
|
||||||
# Detect CP850
|
|
||||||
elif (name[Idx] >= '\x80') & (name[Idx] <= '\xA5'):
|
|
||||||
encoding = 'cp850'
|
|
||||||
break
|
|
||||||
# Detect ISO-8859-15
|
|
||||||
elif (name[Idx] >= '\xA6') & (name[Idx] <= '\xFF'):
|
|
||||||
encoding = 'iso-8859-15'
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
# Detect CP850
|
|
||||||
if (name[Idx] >= '\x80') & (name[Idx] <= '\xA5'):
|
|
||||||
encoding = 'cp850'
|
|
||||||
break
|
|
||||||
# Detect ISO-8859-15
|
|
||||||
elif (name[Idx] >= '\xA6') & (name[Idx] <= '\xFF'):
|
|
||||||
encoding = 'iso-8859-15'
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
name = bytes(name_in)
|
name = bytes(name_in)
|
||||||
for Idx in range(len(name)):
|
for Idx in range(len(name)):
|
||||||
# print('Trying to intuit the encoding')
|
# print('Trying to intuit the encoding')
|
||||||
|
@ -80,7 +48,7 @@ def char_replace(name_in):
|
||||||
if encoding:
|
if encoding:
|
||||||
encoded = True
|
encoded = True
|
||||||
name = name.decode(encoding)
|
name = name.decode(encoding)
|
||||||
elif not PY2:
|
else:
|
||||||
name = name.decode()
|
name = name.decode()
|
||||||
return encoded, name
|
return encoded, name
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue