From a5e76fc56fbb2a7fab7d0e01d58326f4e4ea10db Mon Sep 17 00:00:00 2001 From: Clinton Hall Date: Sat, 4 Jan 2020 22:01:13 +1300 Subject: [PATCH] Py2fix (#1693) * Update encoding to use bytes for strings. (#1690) * fix ffmpeg install issues for test Co-authored-by: Jonathan Springer --- azure-pipelines.yml | 4 +++- core/__init__.py | 23 ++++++++++++++++------- core/utils/encoding.py | 27 ++++++++++++++++++--------- eol.py | 2 +- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 948047c9..e776ae09 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -26,7 +26,9 @@ jobs: maxParallel: 5 steps: - - script: sudo apt-get install ffmpeg + - script: | + sudo apt-get update + sudo apt-get install ffmpeg displayName: 'Install ffmpeg' - task: UsePythonVersion@0 diff --git a/core/__init__.py b/core/__init__.py index 3dff1f4c..25f18c6d 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -983,13 +983,22 @@ def check_python(): # Log warning if within grace period days_left = eol.lifetime() - logger.info( - 'Python v{major}.{minor} will reach end of life in {x} days.'.format( - major=sys.version_info[0], - minor=sys.version_info[1], - x=days_left, - ), - ) + if days_left > 0: + logger.info( + 'Python v{major}.{minor} will reach end of life in {x} days.'.format( + major=sys.version_info[0], + minor=sys.version_info[1], + x=days_left, + ), + ) + else: + logger.info( + 'Python v{major}.{minor} reached end of life {x} days ago.'.format( + major=sys.version_info[0], + minor=sys.version_info[1], + x=-days_left, + ), + ) if days_left <= grace_period: logger.warning('Please upgrade to a more recent Python version.') diff --git a/core/utils/encoding.py b/core/utils/encoding.py index bcc4994f..bd6183d5 100644 --- a/core/utils/encoding.py +++ b/core/utils/encoding.py @@ -8,12 +8,16 @@ from __future__ import ( import os from six import text_type +from six import PY2 import core from core import logger +if not PY2: + from builtins import bytes -def char_replace(name): + +def char_replace(name_in): # Special character hex range: # CP850: 0x80-0xA5 (fortunately not used in ISO-8859-15) # UTF-8: 1st hex code 0xC2-0xC3 followed by a 2nd hex code 0xA1-0xFF @@ -22,31 +26,36 @@ def char_replace(name): # If there is special character, detects if it is a UTF-8, CP850 or ISO-8859-15 encoding encoded = False encoding = None - if isinstance(name, text_type): - return encoded, name.encode(core.SYS_ENCODING) + if isinstance(name_in, text_type): + return encoded, name_in.encode(core.SYS_ENCODING) + if PY2: + name = name_in + else: + name = bytes(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')): + if ((name[Idx] == 0xC2) | (name[Idx] == 0xC3)) & ( + (name[Idx + 1] >= 0xA0) & (name[Idx + 1] <= 0xFF)): encoding = 'utf-8' break # Detect CP850 - elif (name[Idx] >= '\x80') & (name[Idx] <= '\xA5'): + elif (name[Idx] >= 0x80) & (name[Idx] <= 0xA5): encoding = 'cp850' break # Detect ISO-8859-15 - elif (name[Idx] >= '\xA6') & (name[Idx] <= '\xFF'): + elif (name[Idx] >= 0xA6) & (name[Idx] <= 0xFF): encoding = 'iso-8859-15' break else: # Detect CP850 - if (name[Idx] >= '\x80') & (name[Idx] <= '\xA5'): + if (name[Idx] >= 0x80) & (name[Idx] <= 0xA5): encoding = 'cp850' break # Detect ISO-8859-15 - elif (name[Idx] >= '\xA6') & (name[Idx] <= '\xFF'): + elif (name[Idx] >= 0xA6) & (name[Idx] <= 0xFF): encoding = 'iso-8859-15' break if encoding and not encoding == core.SYS_ENCODING: diff --git a/eol.py b/eol.py index fa328fdd..7c46aa4d 100644 --- a/eol.py +++ b/eol.py @@ -96,7 +96,7 @@ def check(version=None, grace_period=0): :return: None """ try: - raise_for_status(version, grace_period) + warn_for_status(version, grace_period) except LifetimeError as error: print('Please use a newer version of Python.') print_statuses()