* Update encoding to use bytes for strings. (#1690)
* fix ffmpeg install issues for test
Co-authored-by: Jonathan Springer <jonpspri@gmail.com>
This commit is contained in:
Clinton Hall 2020-01-04 22:01:13 +13:00 committed by GitHub
parent aeb3e0fd6d
commit a5e76fc56f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 18 deletions

View file

@ -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

View file

@ -983,6 +983,7 @@ def check_python():
# Log warning if within grace period
days_left = eol.lifetime()
if days_left > 0:
logger.info(
'Python v{major}.{minor} will reach end of life in {x} days.'.format(
major=sys.version_info[0],
@ -990,6 +991,14 @@ def check_python():
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.')

View file

@ -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:

2
eol.py
View file

@ -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()