From 20870d0781e53eefab9aa4b87b04dd9ddc56d82f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= Date: Tue, 1 May 2018 12:30:45 +0200 Subject: [PATCH] utils.astring: Add preferred ENCODING MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no right encoding, but the `locale.getpreferredencoding` suits most cases. Let's avoid the usually unnecessary `locale` import and people struggling to remember the most appropriate method and store it in `avocado.utils.astring`. Signed-off-by: Lukáš Doktor --- avocado/utils/astring.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/avocado/utils/astring.py b/avocado/utils/astring.py index b06c41ec..24a6f042 100644 --- a/avocado/utils/astring.py +++ b/avocado/utils/astring.py @@ -26,6 +26,7 @@ And not notice until their code starts failing. """ import itertools +import locale import re import sys import string @@ -35,6 +36,12 @@ from six.moves import zip from six.moves import xrange as range +#: On import evaluated value representing the system encoding +#: based on system locales using :func:`locale.getpreferredencoding`. +#: Use this value wisely as some files are dumped in different +#: encoding. +ENCODING = locale.getpreferredencoding() + #: String containing all fs-unfriendly chars (Windows-fat/Linux-ext3) FS_UNSAFE_CHARS = '<>:"/\\|?*;' -- GitLab