summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-08-18 20:31:56 +0000
committerZac Medico <zmedico@gentoo.org>2009-08-18 20:31:56 +0000
commitdc52a3a999fd161aca5603640b52f42fbfdd4fc7 (patch)
tree692f399b3f94024b2b580a80837f247e8448b909
parent451180884b25f9795715878181c5e45bceb4959e (diff)
downloadportage-dc52a3a999fd161aca5603640b52f42fbfdd4fc7.tar.gz
portage-dc52a3a999fd161aca5603640b52f42fbfdd4fc7.tar.bz2
portage-dc52a3a999fd161aca5603640b52f42fbfdd4fc7.zip
Use _content_encoding and _fs_encoding, and use strict unicode exceptions
where appropriate. svn path=/main/trunk/; revision=14090
-rw-r--r--pym/portage/dbapi/vartree.py57
1 files changed, 37 insertions, 20 deletions
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index 40d20876d..9421da20c 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -37,6 +37,7 @@ from portage import listdir, dep_expand, digraph, flatten, key_expand, \
# This is a special version of the os module, wrapped for unicode support.
from portage import os
+from portage import _content_encoding
from portage import _fs_encoding
from portage import _merge_encoding
from portage import _os_merge
@@ -839,7 +840,8 @@ class vardbapi(dbapi):
counter, = self.aux_get(cpv, aux_keys)
except KeyError:
continue
- h.update(counter)
+ h.update(_unicode_encode(counter,
+ encoding=_content_encoding, errors='replace'))
return h.hexdigest()
def cpv_inject(self, mycpv):
@@ -1251,8 +1253,10 @@ class vardbapi(dbapi):
results.append(long(st.st_mtime))
continue
try:
- myf = codecs.open(_unicode_encode(os.path.join(mydir, x)),
- mode='r', encoding='utf_8', errors='replace')
+ myf = codecs.open(
+ _unicode_encode(os.path.join(mydir, x),
+ encoding=_fs_encoding, errors='strict'),
+ mode='r', encoding=_content_encoding, errors='replace')
try:
myd = myf.read()
finally:
@@ -1320,8 +1324,10 @@ class vardbapi(dbapi):
new_vdb = False
counter = -1
try:
- cfile = codecs.open(_unicode_encode(self._counter_path), mode='r',
- encoding='utf_8', errors='replace')
+ cfile = codecs.open(
+ _unicode_encode(self._counter_path,
+ encoding=_fs_encoding, errors='strict'),
+ mode='r', encoding=_content_encoding, errors='replace')
except EnvironmentError, e:
new_vdb = not bool(self.cpv_all())
if not new_vdb:
@@ -1456,7 +1462,8 @@ class vardbapi(dbapi):
h = self._new_hash()
# Always use a constant utf_8 encoding here, since
# the "default" encoding can change.
- h.update(portage._unicode_encode(s))
+ h.update(_unicode_encode(s,
+ encoding=_content_encoding, errors='replace'))
h = h.hexdigest()
h = h[-self._hex_chars:]
h = int(h, 16)
@@ -1904,8 +1911,9 @@ class dblink(object):
return self.contentscache
pkgfiles = {}
try:
- myc = codecs.open(_unicode_encode(contents_file), mode='r',
- encoding='utf_8', errors='replace')
+ myc = codecs.open(_unicode_encode(contents_file,
+ encoding=_content_encoding, errors='strict'),
+ mode='r', encoding=_content_encoding, errors='replace')
except EnvironmentError, e:
if e.errno != errno.ENOENT:
raise
@@ -3225,8 +3233,10 @@ class dblink(object):
for var_name in ('CHOST', 'SLOT'):
try:
val = codecs.open(_unicode_encode(
- os.path.join(inforoot, var_name)), mode='r',
- encoding='utf_8', errors='replace').readline().strip()
+ os.path.join(inforoot, var_name),
+ encoding=_fs_encoding, errors='strict'),
+ mode='r', encoding=_content_encoding, errors='replace'
+ ).readline().strip()
except EnvironmentError, e:
if e.errno != errno.ENOENT:
raise
@@ -3572,8 +3582,9 @@ class dblink(object):
# open CONTENTS file (possibly overwriting old one) for recording
outfile = codecs.open(_unicode_encode(
- os.path.join(self.dbtmpdir, 'CONTENTS')),
- mode='w', encoding='utf_8', errors='replace')
+ os.path.join(self.dbtmpdir, 'CONTENTS'),
+ encoding=_fs_encoding, errors='strict'),
+ mode='w', encoding=_content_encoding, errors='replace')
self.updateprotect()
@@ -4171,8 +4182,11 @@ class dblink(object):
"returns contents of a file with whitespace converted to spaces"
if not os.path.exists(self.dbdir+"/"+name):
return ""
- mydata = codecs.open(_unicode_encode(os.path.join(self.dbdir, name)),
- mode='r', encoding='utf_8', errors='replace').read().split()
+ mydata = codecs.open(
+ _unicode_encode(os.path.join(self.dbdir, name),
+ encoding=_fs_encoding, errors='strict'),
+ mode='r', encoding=_content_encoding, errors='replace'
+ ).read().split()
return " ".join(mydata)
def copyfile(self,fname):
@@ -4181,8 +4195,9 @@ class dblink(object):
def getfile(self,fname):
if not os.path.exists(self.dbdir+"/"+fname):
return ""
- return codecs.open(_unicode_encode(os.path.join(self.dbdir, fname)),
- mode='r', encoding='utf_8', errors='replace').read()
+ return codecs.open(_unicode_encode(os.path.join(self.dbdir, fname),
+ encoding=_fs_encoding, errors='strict'),
+ mode='r', encoding=_content_encoding, errors='replace').read()
def setfile(self,fname,data):
mode = 'w'
@@ -4194,8 +4209,9 @@ class dblink(object):
if not os.path.exists(self.dbdir+"/"+ename):
return []
mylines = codecs.open(_unicode_encode(
- os.path.join(self.dbdir, ename)), mode='r',
- encoding='utf_8', errors='replace').readlines()
+ os.path.join(self.dbdir, ename),
+ encoding=_fs_encoding, errors='strict'),
+ mode='r', encoding=_content_encoding, errors='replace').readlines()
myreturn = []
for x in mylines:
for y in x[:-1].split():
@@ -4204,8 +4220,9 @@ class dblink(object):
def setelements(self,mylist,ename):
myelement = codecs.open(_unicode_encode(
- os.path.join(self.dbdir, ename)), mode='w',
- encoding='utf_8', errors='replace')
+ os.path.join(self.dbdir, ename),
+ encoding=_fs_encoding, errors='strict'), mode='w',
+ encoding=_content_encoding, errors='replace')
for x in mylist:
myelement.write(x+"\n")
myelement.close()