summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pym/portage/__init__.py24
-rw-r--r--pym/portage/_ensure_encodings.py132
-rw-r--r--pym/portage/tests/lazyimport/test_lazy_import_portage_baseline.py2
3 files changed, 1 insertions, 157 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index bc2eedb18..47e2e48e6 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -327,30 +327,6 @@ _python_interpreter = os.path.realpath(sys.executable)
_bin_path = PORTAGE_BIN_PATH
_pym_path = PORTAGE_PYM_PATH
-def _ensure_default_encoding():
-
- default_encoding = sys.getdefaultencoding().lower().replace('-', '_')
- filesystem_encoding = _encodings['merge'].lower().replace('-', '_')
- required_encodings = set(['ascii', 'utf_8'])
- required_encodings.add(default_encoding)
- required_encodings.add(filesystem_encoding)
- missing_encodings = set()
- for codec_name in required_encodings:
- try:
- codecs.lookup(codec_name)
- except LookupError:
- missing_encodings.add(codec_name)
-
- if not missing_encodings:
- return
-
- from portage import _ensure_encodings
- _ensure_encodings._setup_encodings(default_encoding,
- filesystem_encoding, missing_encodings)
-
-# Do this ASAP since writemsg() might not work without it.
-_ensure_default_encoding()
-
def _shell_quote(s):
"""
Quote a string in double-quotes and use backslashes to
diff --git a/pym/portage/_ensure_encodings.py b/pym/portage/_ensure_encodings.py
deleted file mode 100644
index 5e62843f1..000000000
--- a/pym/portage/_ensure_encodings.py
+++ /dev/null
@@ -1,132 +0,0 @@
-# Copyright 2010 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-
-import codecs
-
-_codec_map = None
-
-def _setup_encodings(default_encoding, filesystem_encoding, missing_encodings):
- """
- The <python-2.6.4 that's inside stage 1 or 2 is built with a minimal
- configuration which does not include the /usr/lib/pythonX.Y/encodings
- directory. This results in error like the following:
-
- LookupError: no codec search functions registered: can't find encoding
-
- In order to solve this problem, detect it early and manually register
- a search function for the ascii and utf_8 codecs. Starting with python-3.0
- this problem is more noticeable because of stricter handling of encoding
- and decoding between strings of characters and bytes.
- """
-
- global _codec_map
- _codec_map = _gen_missing_encodings(missing_encodings)
-
- default_fallback = 'utf_8'
-
- if default_encoding in missing_encodings and \
- default_encoding not in _codec_map:
- # Make the fallback codec correspond to whatever name happens
- # to be returned by sys.getfilesystemencoding().
-
- try:
- _codec_map[default_encoding] = codecs.lookup(default_fallback)
- except LookupError:
- _codec_map[default_encoding] = _codec_map[default_fallback]
-
- if filesystem_encoding in missing_encodings and \
- filesystem_encoding not in _codec_map:
- # Make the fallback codec correspond to whatever name happens
- # to be returned by sys.getdefaultencoding().
-
- try:
- _codec_map[filesystem_encoding] = codecs.lookup(default_fallback)
- except LookupError:
- _codec_map[filesystem_encoding] = _codec_map[default_fallback]
-
- codecs.register(_search_function)
-
-def _gen_missing_encodings(missing_encodings):
-
- codec_map = {}
-
- if 'ascii' in missing_encodings:
-
- class AsciiIncrementalEncoder(codecs.IncrementalEncoder):
- def encode(self, input, final=False):
- return codecs.ascii_encode(input, self.errors)[0]
-
- class AsciiIncrementalDecoder(codecs.IncrementalDecoder):
- def decode(self, input, final=False):
- return codecs.ascii_decode(input, self.errors)[0]
-
- class AsciiStreamWriter(codecs.StreamWriter):
- encode = codecs.ascii_encode
-
- class AsciiStreamReader(codecs.StreamReader):
- decode = codecs.ascii_decode
-
- codec_info = codecs.CodecInfo(
- name='ascii',
- encode=codecs.ascii_encode,
- decode=codecs.ascii_decode,
- incrementalencoder=AsciiIncrementalEncoder,
- incrementaldecoder=AsciiIncrementalDecoder,
- streamwriter=AsciiStreamWriter,
- streamreader=AsciiStreamReader,
- )
-
- for alias in ('ascii', '646', 'ansi_x3.4_1968', 'ansi_x3_4_1968',
- 'ansi_x3.4_1986', 'cp367', 'csascii', 'ibm367', 'iso646_us',
- 'iso_646.irv_1991', 'iso_ir_6', 'us', 'us_ascii'):
- codec_map[alias] = codec_info
-
- if 'utf_8' in missing_encodings:
-
- def utf8decode(input, errors='strict'):
- return codecs.utf_8_decode(input, errors, True)
-
- class Utf8IncrementalEncoder(codecs.IncrementalEncoder):
- def encode(self, input, final=False):
- return codecs.utf_8_encode(input, self.errors)[0]
-
- class Utf8IncrementalDecoder(codecs.BufferedIncrementalDecoder):
- _buffer_decode = codecs.utf_8_decode
-
- class Utf8StreamWriter(codecs.StreamWriter):
- encode = codecs.utf_8_encode
-
- class Utf8StreamReader(codecs.StreamReader):
- decode = codecs.utf_8_decode
-
- codec_info = codecs.CodecInfo(
- name='utf-8',
- encode=codecs.utf_8_encode,
- decode=utf8decode,
- incrementalencoder=Utf8IncrementalEncoder,
- incrementaldecoder=Utf8IncrementalDecoder,
- streamreader=Utf8StreamReader,
- streamwriter=Utf8StreamWriter,
- )
-
- for alias in ('utf_8', 'u8', 'utf', 'utf8', 'utf8_ucs2', 'utf8_ucs4'):
- codec_map[alias] = codec_info
-
- return codec_map
-
-def _search_function(name):
- global _codec_map
- name = name.lower()
- name = name.replace('-', '_')
- codec_info = _codec_map.get(name)
- if codec_info is not None:
- return codecs.CodecInfo(
- name=codec_info.name,
- encode=codec_info.encode,
- decode=codec_info.decode,
- incrementalencoder=codec_info.incrementalencoder,
- incrementaldecoder=codec_info.incrementaldecoder,
- streamreader=codec_info.streamreader,
- streamwriter=codec_info.streamwriter,
- )
- return None
diff --git a/pym/portage/tests/lazyimport/test_lazy_import_portage_baseline.py b/pym/portage/tests/lazyimport/test_lazy_import_portage_baseline.py
index 28cf28436..08ccfa7ff 100644
--- a/pym/portage/tests/lazyimport/test_lazy_import_portage_baseline.py
+++ b/pym/portage/tests/lazyimport/test_lazy_import_portage_baseline.py
@@ -18,7 +18,7 @@ class LazyImportPortageBaselineTestCase(TestCase):
_baseline_imports = frozenset([
'portage.const', 'portage.localization',
'portage.proxy', 'portage.proxy.lazyimport',
- 'portage.proxy.objectproxy', 'portage._ensure_encodings',
+ 'portage.proxy.objectproxy',
'portage._selinux',
])