summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pym/portage/dbapi/__init__.py2
-rw-r--r--pym/portage/dbapi/bintree.py34
-rw-r--r--pym/portage/dbapi/porttree.py17
-rw-r--r--pym/portage/dbapi/vartree.py49
4 files changed, 51 insertions, 51 deletions
diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py
index 08b7a3b9b..ebcd785a0 100644
--- a/pym/portage/dbapi/__init__.py
+++ b/pym/portage/dbapi/__init__.py
@@ -4,7 +4,6 @@
__all__ = ["dbapi"]
-import os
import re
import portage
@@ -16,6 +15,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
'portage.versions:catpkgsplit,vercmp',
)
+from portage import os
from portage import auxdbkeys, dep_expand
from portage.localization import _
diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py
index 1a5592688..ed5e44430 100644
--- a/pym/portage/dbapi/bintree.py
+++ b/pym/portage/dbapi/bintree.py
@@ -20,11 +20,14 @@ from portage.exception import InvalidPackageName, \
from portage.localization import _
from portage import dep_expand, listdir, _check_distfile, _movefile
+from portage import os
+from portage import _unicode_decode
+from portage import _unicode_encode
import codecs
-import os, errno, stat
+import errno
import re
-import sys
+import stat
from itertools import chain, izip
class bindbapi(fakedbapi):
@@ -70,8 +73,8 @@ class bindbapi(fakedbapi):
tbz2 = portage.xpak.tbz2(tbz2_path)
def getitem(k):
v = tbz2.getfile(k)
- if v is not None and not isinstance(v, unicode):
- v = unicode(v, encoding='utf_8', errors='replace')
+ if v is not None:
+ v = _unicode_decode(v)
return v
else:
getitem = self.bintree._remotepkgs[mycpv].get
@@ -105,21 +108,10 @@ class bindbapi(fakedbapi):
mytbz2 = portage.xpak.tbz2(tbz2path)
mydata = mytbz2.get_data()
- if sys.hexversion < 0x3000000:
- for k, v in values.iteritems():
- if isinstance(k, unicode):
- k = k.encode('utf_8', 'replace')
- if isinstance(v, unicode):
- v = v.encode('utf_8', 'replace')
- mydata[k] = v
-
- else:
- for k, v in values.iteritems():
- if isinstance(k, str):
- k = k.encode('utf_8', 'replace')
- if isinstance(v, str):
- v = v.encode('utf_8', 'replace')
- mydata[k] = v
+ for k, v in values.iteritems():
+ k = _unicode_encode(k)
+ v = _unicode_encode(v)
+ mydata[k] = v
for k, v in mydata.items():
if not v:
@@ -660,7 +652,7 @@ class binarytree(object):
urldata[1] + urldata[2], "Packages")
pkgindex = self._new_pkgindex()
try:
- f = codecs.open(pkgindex_file,
+ f = codecs.open(_unicode_encode(pkgindex_file),
encoding='utf_8', errors='replace')
try:
pkgindex.read(f)
@@ -1102,7 +1094,7 @@ class binarytree(object):
def _load_pkgindex(self):
pkgindex = self._new_pkgindex()
try:
- f = codecs.open(self._pkgindex_file,
+ f = codecs.open(_unicode_encode(self._pkgindex_file),
encoding='utf_8', errors='replace')
except EnvironmentError:
pass
diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py
index 7ee889a7c..56ed44945 100644
--- a/pym/portage/dbapi/porttree.py
+++ b/pym/portage/dbapi/porttree.py
@@ -26,8 +26,12 @@ from portage.manifest import Manifest
from portage import eclass_cache, auxdbkeys, doebuild, flatten, \
listdir, dep_expand, eapi_is_supported, key_expand, dep_check, \
_eapi_is_deprecated
+from portage import _unicode_encode
+from portage import os
-import codecs, logging, os, stat
+import codecs
+import logging
+import stat
from itertools import izip
def _src_uri_validate(cpv, eapi, src_uri):
@@ -167,7 +171,8 @@ class portdbapi(dbapi):
continue
repo_name_path = os.path.join(path, REPO_NAME_LOC)
try:
- repo_name = codecs.open(repo_name_path, mode='r',
+ repo_name = codecs.open(
+ _unicode_encode(repo_name_path), mode='r',
encoding='utf_8', errors='replace').readline().strip()
except EnvironmentError:
# warn about missing repo_name at some other time, since we
@@ -615,8 +620,9 @@ class portdbapi(dbapi):
os.path.basename(myebuild))
if eapi is None and \
'parse-eapi-ebuild-head' in self.doebuild_settings.features:
- eapi = portage._parse_eapi_ebuild_head(codecs.open(myebuild,
- mode='r', encoding='utf_8', errors='replace'))
+ eapi = portage._parse_eapi_ebuild_head(codecs.open(
+ _unicode_encode(myebuild), mode='r',
+ encoding='utf_8', errors='replace'))
if eapi is not None:
self.doebuild_settings.configdict['pkg']['EAPI'] = eapi
@@ -878,9 +884,6 @@ class portdbapi(dbapi):
except OSError:
continue
for x in file_list:
- if not isinstance(x, unicode):
- x = unicode(x, encoding='utf_8', errors='replace')
-
pf = None
if glep55:
pf, eapi = portage._split_ebuild_name_glep55(x)
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index fd8383938..0b4cf2bde 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 _unicode_encode
from portage.cache.mappings import slot_dict_class
@@ -72,7 +73,8 @@ class PreservedLibsRegistry(object):
""" Reload the registry data from file """
self._data = None
try:
- self._data = pickle.load(open(self._filename, 'rb'))
+ self._data = pickle.load(
+ open(_unicode_encode(self._filename), 'rb'))
except (ValueError, pickle.UnpicklingError), e:
writemsg_level(_("!!! Error loading '%s': %s\n") % \
(self._filename, e), level=logging.ERROR, noiselevel=-1)
@@ -1079,7 +1081,8 @@ class vardbapi(dbapi):
# python-2.x, but buffering makes it much worse.
open_kwargs["buffering"] = 0
try:
- f = open(self._aux_cache_filename, mode='rb', **open_kwargs)
+ f = open(_unicode_encode(self._aux_cache_filename),
+ mode='rb', **open_kwargs)
mypickle = pickle.Unpickler(f)
try:
mypickle.find_global = None
@@ -1225,7 +1228,7 @@ class vardbapi(dbapi):
results.append(long(st.st_mtime))
continue
try:
- myf = codecs.open(os.path.join(mydir, x),
+ myf = codecs.open(_unicode_encode(os.path.join(mydir, x)),
mode='r', encoding='utf_8', errors='replace')
try:
myd = myf.read()
@@ -1294,7 +1297,8 @@ class vardbapi(dbapi):
new_vdb = False
counter = -1
try:
- cfile = open(self._counter_path, "r")
+ cfile = codecs.open(_unicode_encode(self._counter_path), mode='r',
+ encoding='utf_8', errors='replace')
except EnvironmentError, e:
new_vdb = not bool(self.cpv_all())
if not new_vdb:
@@ -1877,7 +1881,7 @@ class dblink(object):
return self.contentscache
pkgfiles = {}
try:
- myc = codecs.open(contents_file, mode='r',
+ myc = codecs.open(_unicode_encode(contents_file), mode='r',
encoding='utf_8', errors='replace')
except EnvironmentError, e:
if e.errno != errno.ENOENT:
@@ -3164,7 +3168,9 @@ class dblink(object):
slot = ''
for var_name in ('CHOST', 'SLOT'):
try:
- val = open(os.path.join(inforoot, var_name)).readline().strip()
+ val = codecs.open(_unicode_encode(
+ os.path.join(inforoot, var_name)), mode='r',
+ encoding='utf_8', errors='replace').readline().strip()
except EnvironmentError, e:
if e.errno != errno.ENOENT:
raise
@@ -3454,12 +3460,12 @@ class dblink(object):
# write local package counter for recording
counter = self.vartree.dbapi.counter_tick(self.myroot, mycpv=self.mycpv)
- lcfile = open(os.path.join(self.dbtmpdir, "COUNTER"),"w")
- lcfile.write(str(counter))
- lcfile.close()
+ open(_unicode_encode(os.path.join(self.dbtmpdir, 'COUNTER')),
+ 'w').write(str(counter))
# open CONTENTS file (possibly overwriting old one) for recording
- outfile = codecs.open(os.path.join(self.dbtmpdir, 'CONTENTS'),
+ outfile = codecs.open(_unicode_encode(
+ os.path.join(self.dbtmpdir, 'CONTENTS')),
mode='w', encoding='utf_8', errors='replace')
self.updateprotect()
@@ -4054,9 +4060,8 @@ class dblink(object):
"returns contents of a file with whitespace converted to spaces"
if not os.path.exists(self.dbdir+"/"+name):
return ""
- myfile = open(self.dbdir+"/"+name,"r")
- mydata = myfile.read().split()
- myfile.close()
+ mydata = codecs.open(_unicode_encode(os.path.join(self.dbdir, name)),
+ mode='r', encoding='utf_8', errors='replace').read().split()
return " ".join(mydata)
def copyfile(self,fname):
@@ -4065,10 +4070,8 @@ class dblink(object):
def getfile(self,fname):
if not os.path.exists(self.dbdir+"/"+fname):
return ""
- myfile = open(self.dbdir+"/"+fname,"r")
- mydata = myfile.read()
- myfile.close()
- return mydata
+ return codecs.open(_unicode_encode(os.path.join(self.dbdir, fname)),
+ mode='r', encoding='utf_8', errors='replace').read()
def setfile(self,fname,data):
mode = 'w'
@@ -4079,17 +4082,19 @@ class dblink(object):
def getelements(self,ename):
if not os.path.exists(self.dbdir+"/"+ename):
return []
- myelement = open(self.dbdir+"/"+ename,"r")
- mylines = myelement.readlines()
+ mylines = codecs.open(_unicode_encode(
+ os.path.join(self.dbdir, ename)), mode='r',
+ encoding='utf_8', errors='replace').readlines()
myreturn = []
for x in mylines:
for y in x[:-1].split():
myreturn.append(y)
- myelement.close()
return myreturn
def setelements(self,mylist,ename):
- myelement = open(self.dbdir+"/"+ename,"w")
+ myelement = codecs.open(_unicode_encode(
+ os.path.join(self.dbdir, ename)), mode='w',
+ encoding='utf_8', errors='replace')
for x in mylist:
myelement.write(x+"\n")
myelement.close()
@@ -4166,7 +4171,7 @@ def tar_contents(contents, root, tar, protect=None, onProgress=None):
tarinfo.size = 0
tar.addfile(tarinfo)
else:
- f = open(path, 'rb')
+ f = open(_unicode_encode(path), 'rb')
try:
tar.addfile(tarinfo, f)
finally: