summaryrefslogtreecommitdiffstats
path: root/pym
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-02-23 03:12:49 +0000
committerZac Medico <zmedico@gentoo.org>2009-02-23 03:12:49 +0000
commitb1487ac5dfe57cb16ec4575b7a2a8ac570fc2bc0 (patch)
treeb6a51a92d148fbdcea75a1bfffffb02f908ee67b /pym
parentaac0840c6a27e87a52c802d7a8d2e9412041cd45 (diff)
downloadportage-b1487ac5dfe57cb16ec4575b7a2a8ac570fc2bc0.tar.gz
portage-b1487ac5dfe57cb16ec4575b7a2a8ac570fc2bc0.tar.bz2
portage-b1487ac5dfe57cb16ec4575b7a2a8ac570fc2bc0.zip
When encoding strings inside vardbapi._counter_hash() and
vardbapi._owners_cache._hash_str(), use 'backslashreplace' in order to avoid potential UnicodeError exceptions. Use constant ascii and utf_8 codecs, respectively, since these codecs are guaranteed to be available by _ensure_default_encoding(). svn path=/main/trunk/; revision=12689
Diffstat (limited to 'pym')
-rw-r--r--pym/portage/dbapi/vartree.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index db05fca6b..c13af9263 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -792,7 +792,7 @@ class vardbapi(dbapi):
counter, = self.aux_get(cpv, aux_keys)
except KeyError:
continue
- h.update(counter.encode())
+ h.update(counter.encode('ascii', 'backslashreplace'))
return h.hexdigest()
def cpv_inject(self, mycpv):
@@ -1390,7 +1390,9 @@ class vardbapi(dbapi):
def _hash_str(self, s):
h = self._new_hash()
- h.update(s.encode())
+ # Always use a constant utf_8 encoding here, since
+ # the "default" encoding can change.
+ h.update(s.encode('utf_8', 'backslashreplace'))
h = h.hexdigest()
h = h[-self._hex_chars:]
h = int(h, 16)