From fc411d04e2f0973c84756b8bd5ef1a0b9a3e9ed4 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Sat, 4 Jan 2020 21:53:22 +1300 Subject: [PATCH] fix py2 encoding --- core/__init__.py | 23 ++++++++++++++++------- core/utils/encoding.py | 11 ++++++++--- eol.py | 2 +- 3 files changed, 25 insertions(+), 11 deletions(-) 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 8864c3a2..bd6183d5 100644 --- a/core/utils/encoding.py +++ b/core/utils/encoding.py @@ -5,15 +5,17 @@ from __future__ import ( unicode_literals, ) -from builtins import bytes - 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_in): # Special character hex range: @@ -26,7 +28,10 @@ def char_replace(name_in): encoding = None if isinstance(name_in, text_type): return encoded, name_in.encode(core.SYS_ENCODING) - name=bytes(name_in) + 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 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()