From 698e8791d7724f02ff211aff5b57ca349d0b3688 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Sat, 13 Nov 2021 00:28:52 -0800 Subject: [PATCH] Remove Python 3.6 specific unicode environment checks --- debian/copyright | 5 -- src/ocrmypdf/_unicodefun.py | 118 ------------------------------------ src/ocrmypdf/_validation.py | 3 - 3 files changed, 126 deletions(-) delete mode 100644 src/ocrmypdf/_unicodefun.py diff --git a/debian/copyright b/debian/copyright index a48ac1dc..32d68b01 100644 --- a/debian/copyright +++ b/debian/copyright @@ -60,11 +60,6 @@ Copyright: (C) 2010 Jonathan Brinley (C) 2015-16 James R. Barlow License: Expat -Files: src/ocrmypdf/_unicodefun.py -Copyright: (C) 2014 Armin Ronacher - (C) 2017 James R. Barlow -License: BSD-3-clause - Files: tests/plugins/* Copyright: (C) 2016, 2017, 2016-2018 James R. Barlow License: Expat diff --git a/src/ocrmypdf/_unicodefun.py b/src/ocrmypdf/_unicodefun.py deleted file mode 100644 index fbef01cb..00000000 --- a/src/ocrmypdf/_unicodefun.py +++ /dev/null @@ -1,118 +0,0 @@ -# Copyright (c) 2014, Armin Ronacher -# -# Copyright (c) 2017, James R Barlow -# -# Some rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials provided -# with the distribution. -# -# * The names of the contributors may not be used to endorse or -# promote products derived from this software without specific -# prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -import codecs -import os -import sys - - -def verify_python3_env(): # pragma: no cover - """Ensures that the environment is good for unicode on Python 3.""" - - # PEP 538 changes in Python 3.7 should make this wrangling unnecessary - if sys.version_info[0:3] >= (3, 7, 0): - return - - try: - import locale - - fs_enc = codecs.lookup(locale.getpreferredencoding()).name - except Exception: - fs_enc = 'ascii' - if fs_enc != 'ascii': - return - - extra = '' - if os.name == 'posix': - import subprocess - - rv = subprocess.run( - ['locale', '-a'], stdout=subprocess.PIPE, stderr=subprocess.PIPE - ).stdout - good_locales = set() - has_c_utf8 = False - - # Make sure we're operating on text here. - if isinstance(rv, bytes): - rv = rv.decode('ascii', 'replace') - - for line in rv.splitlines(): - locale = line.strip() - if locale.lower().endswith(('.utf-8', '.utf8')): - good_locales.add(locale) - if locale.lower() in ('c.utf8', 'c.utf-8'): - has_c_utf8 = True - - extra += '\n\n' - if not good_locales: - extra += ( - 'Additional information: on this system no suitable UTF-8\n' - 'locales were discovered. This most likely requires resolving\n' - 'by reconfiguring the locale system.' - ) - elif has_c_utf8: - extra += ( - 'This system supports the C.UTF-8 locale which is recommended.\n' - 'You might be able to resolve your issue by exporting the\n' - 'following environment variables:\n\n' - ' export LC_ALL=C.UTF-8\n' - ' export LANG=C.UTF-8' - ) - else: - extra += ( - 'This system lists a couple of UTF-8 supporting locales that\n' - 'you can pick from. The following suitable locales were\n' - 'discovered: %s' - ) % ', '.join(sorted(good_locales)) - - bad_locale = None - for locale in os.environ.get('LC_ALL'), os.environ.get('LANG'): - if locale and locale.lower().endswith(('.utf-8', '.utf8')): - bad_locale = locale - if locale is not None: - break - if bad_locale is not None: - extra += ( - '\nocrmypdf discovered that you exported a UTF-8 locale\n' - 'but the locale system could not pick up from it because\n' - 'it does not exist. The exported locale is "%s" but it\n' - 'is not supported' - ) % bad_locale - - raise RuntimeError( - 'ocrmypdf will abort further execution because Python 3 ' - 'was configured to use ASCII as encoding for the ' - 'environment.' + extra - ) diff --git a/src/ocrmypdf/_validation.py b/src/ocrmypdf/_validation.py index d45bee4d..b6022dd2 100644 --- a/src/ocrmypdf/_validation.py +++ b/src/ocrmypdf/_validation.py @@ -19,7 +19,6 @@ import pikepdf import PIL from ocrmypdf._exec import jbig2enc, pngquant, unpaper -from ocrmypdf._unicodefun import verify_python3_env from ocrmypdf.exceptions import ( BadArgsError, InputFileError, @@ -39,8 +38,6 @@ log = logging.getLogger(__name__) # -------- -# Critical environment tests -verify_python3_env() def check_platform():