From 945464ab91f07aa8af47884e2246ccb638a8144f Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 14 Aug 2009 23:51:29 +0000 Subject: [PATCH] Add a portage._content_encoding constant, set to utf_8. svn path=/main/trunk/; revision=14056 --- pym/portage/__init__.py | 17 ++++++++++------- pym/portage/manifest.py | 7 ++++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 8f59a3978..9b7c6c01f 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -118,12 +118,20 @@ except ImportError, e: sys.stderr.write(" "+str(e)+"\n\n") raise -def _unicode_encode(s, encoding='utf_8', errors='replace'): +# Assume utf_8 encoding for content of all files. +_content_encoding = 'utf_8' + +# Assume utf_8 fs encoding everywhere except in merge code. +_fs_encoding = 'utf_8' + +_merge_encoding = sys.getfilesystemencoding() + +def _unicode_encode(s, encoding=_content_encoding, errors='replace'): if isinstance(s, unicode): s = s.encode(encoding, errors) return s -def _unicode_decode(s, encoding='utf_8', errors='replace'): +def _unicode_decode(s, encoding=_content_encoding, errors='replace'): if not isinstance(s, unicode): if sys.hexversion < 0x3000000: if isinstance(s, basestring): @@ -197,11 +205,6 @@ class _unicode_module_wrapper(object): result = _unicode_func_wrapper(result, encoding=encoding) return result -# Assume utf_8 fs encoding everywhere except in merge code. -_fs_encoding = 'utf_8' - -_merge_encoding = sys.getfilesystemencoding() - import os as _os _os_overrides = { id(_os.fdopen) : _os.fdopen, diff --git a/pym/portage/manifest.py b/pym/portage/manifest.py index 403e01115..cc02ddfcc 100644 --- a/pym/portage/manifest.py +++ b/pym/portage/manifest.py @@ -12,6 +12,7 @@ portage.proxy.lazyimport.lazyimport(globals(), ) from portage import os +from portage import _content_encoding from portage import _fs_encoding from portage import _unicode_decode from portage import _unicode_encode @@ -144,7 +145,7 @@ class Manifest(object): try: fd = codecs.open(_unicode_encode(file_path, encoding=_fs_encoding, errors='strict'), mode='r', - encoding='utf_8', errors='replace') + encoding=_content_encoding, errors='replace') if myhashdict is None: myhashdict = {} self._parseDigests(fd, myhashdict=myhashdict, **kwargs) @@ -232,7 +233,7 @@ class Manifest(object): try: f = codecs.open(_unicode_encode(self.getFullname(), encoding=_fs_encoding, errors='strict'), - mode='r', encoding='utf_8', errors='replace') + mode='r', encoding=_content_encoding, errors='replace') oldentries = list(self._parseManifestLines(f)) f.close() if len(oldentries) == len(myentries): @@ -522,7 +523,7 @@ class Manifest(object): return rVal myfile = codecs.open(_unicode_encode(mfname, encoding=_fs_encoding, errors='strict'), - mode='r', encoding='utf_8', errors='replace') + mode='r', encoding=_content_encoding, errors='replace') lines = myfile.readlines() myfile.close() for l in lines: -- 2.26.2