Use _encodings where appropriate.
authorZac Medico <zmedico@gentoo.org>
Fri, 21 Aug 2009 00:06:10 +0000 (00:06 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 21 Aug 2009 00:06:10 +0000 (00:06 -0000)
svn path=/main/trunk/; revision=14107

pym/portage/cache/flat_hash.py
pym/portage/cache/flat_list.py
pym/portage/cache/metadata.py

index 2467f68002f3673b901b60310c3c1937a72f87c9..259be4108b4dfbdad30eb3b9f4ca6c4c5ad51b9b 100644 (file)
@@ -9,6 +9,7 @@ from portage.cache import cache_errors
 import errno
 import stat
 from portage import os
+from portage import _encodings
 from portage import _unicode_encode
 
 class database(fs_template.FsBased):
@@ -29,8 +30,10 @@ class database(fs_template.FsBased):
        def _getitem(self, cpv):
                fp = os.path.join(self.location, cpv)
                try:
-                       myf = codecs.open(_unicode_encode(fp),
-                               mode='r', encoding='utf_8', errors='replace')
+                       myf = codecs.open(_unicode_encode(fp,
+                               encoding=_encodings['fs'], errors='strict'),
+                               mode='r', encoding=_encodings['repo.content'],
+                               errors='replace')
                        try:
                                d = self._parse_data(myf.readlines(), cpv)
                                if '_mtime_' not in d:
@@ -58,14 +61,18 @@ class database(fs_template.FsBased):
                s = cpv.rfind("/")
                fp = os.path.join(self.location,cpv[:s],".update.%i.%s" % (os.getpid(), cpv[s+1:]))
                try:
-                       myf = codecs.open(_unicode_encode(fp), mode='w',
-                               encoding='utf_8', errors='replace')
+                       myf = codecs.open(_unicode_encode(fp,
+                               encoding=_encodings['fs'], errors='strict'),
+                               mode='w', encoding=_encodings['repo.content'],
+                               errors='backslashreplace')
                except (IOError, OSError), e:
                        if errno.ENOENT == e.errno:
                                try:
                                        self._ensure_dirs(cpv)
-                                       myf = codecs.open(_unicode_encode(fp), mode='w',
-                                               encoding='utf_8', errors='replace')
+                                       myf = codecs.open(_unicode_encode(fp,
+                                               encoding=_encodings['fs'], errors='strict'),
+                                               mode='w', encoding=_encodings['repo.content'],
+                                               errors='backslashreplace')
                                except (OSError, IOError),e:
                                        raise cache_errors.CacheCorruption(cpv, e)
                        else:
index 9906dd22dbc5405fb2b2242fc747288d8e8298f9..1d4dbd28f759983d5d84e7abc8112d76a683ab08 100644 (file)
@@ -1,6 +1,7 @@
 from portage.cache import fs_template
 from portage.cache import cache_errors
 from portage import os
+from portage import _encodings
 from portage import _unicode_encode
 import codecs
 import errno
@@ -31,8 +32,10 @@ class database(fs_template.FsBased):
        def _getitem(self, cpv):
                d = {}
                try:
-                       myf = codecs.open(_unicode_encode(os.path.join(self._base, cpv)),
-                               mode='r', encoding='utf_8', errors='replace')
+                       myf = codecs.open(_unicode_encode(os.path.join(self._base, cpv),
+                               encoding=_encodings['fs'], errors='strict'),
+                               mode='r', encoding=_encodings['repo.content'],
+                               errors='replace')
                        for k,v in zip(self.auxdbkey_order, myf):
                                d[k] = v.rstrip("\n")
                except (OSError, IOError),e:
@@ -53,14 +56,18 @@ class database(fs_template.FsBased):
                s = cpv.rfind("/")
                fp=os.path.join(self._base,cpv[:s],".update.%i.%s" % (os.getpid(), cpv[s+1:]))
                try:
-                       myf = codecs.open(_unicode_encode(fp), mode='w',
-                               encoding='utf_8', errors='replace')
+                       myf = codecs.open(_unicode_encode(fp,
+                               encoding=_encodings['fs'], errors='strict'),
+                               mode='w', encoding=_encodings['repo.content'],
+                               errors='backslashreplace')
                except (OSError, IOError), e:
                        if errno.ENOENT == e.errno:
                                try:
                                        self._ensure_dirs(cpv)
-                                       myf = codecs.open(_unicode_encode(fp), mode='w',
-                                               encoding='utf_8', errors='replace')
+                                       myf = codecs.open(_unicode_encode(fp,
+                                               encoding=_encodings['fs'], errors='strict'),
+                                               mode='w', encoding=_encodings['repo.content'],
+                                               errors='backslashreplace')
                                except (OSError, IOError),e:
                                        raise cache_errors.CacheCorruption(cpv, e)
                        else:
index e91ed68d22ed82db393236307b37cc58676c38cb..ff1227bdb1017d9a39df59afa667ff8396c71b61 100644 (file)
@@ -6,6 +6,7 @@
 import errno
 import re
 from portage import os
+from portage import _encodings
 from portage import _unicode_encode
 from portage.cache import cache_errors, flat_hash
 import portage.eclass_cache
@@ -80,16 +81,18 @@ class database(flat_hash.database):
 
                new_content = []
                for k in self.auxdbkey_order:
-                       new_content.append(values.get(k, u''))
-                       new_content.append(u'\n')
+                       new_content.append(values.get(k, ''))
+                       new_content.append('\n')
                for i in xrange(magic_line_count - len(self.auxdbkey_order)):
-                       new_content.append(u'\n')
-               new_content = u''.join(new_content)
-               new_content = _unicode_encode(new_content)
+                       new_content.append('\n')
+               new_content = ''.join(new_content)
+               new_content = _unicode_encode(new_content,
+                       _encodings['repo.content'], errors='backslashreplace')
 
                new_fp = os.path.join(self.location, cpv)
                try:
-                       f = open(_unicode_encode(new_fp), 'rb')
+                       f = open(_unicode_encode(new_fp,
+                               encoding=_encodings['fs'], errors='strict'), 'rb')
                except EnvironmentError:
                        pass
                else:
@@ -117,12 +120,14 @@ class database(flat_hash.database):
                fp = os.path.join(self.location,cpv[:s],
                        ".update.%i.%s" % (os.getpid(), cpv[s+1:]))
                try:
-                       myf = open(_unicode_encode(fp), 'wb')
+                       myf = open(_unicode_encode(fp,
+                               encoding=_encodings['fs'], errors='strict'), 'wb')
                except EnvironmentError, e:
                        if errno.ENOENT == e.errno:
                                try:
                                        self._ensure_dirs(cpv)
-                                       myf = open(_unicode_encode(fp), 'wb')
+                                       myf = open(_unicode_encode(fp,
+                                               encoding=_encodings['fs'], errors='strict'), 'wb')
                                except EnvironmentError, e:
                                        raise cache_errors.CacheCorruption(cpv, e)
                        else: