public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] portage r14003 - main/trunk/pym/portage/dbapi
@ 2009-08-11 23:43 Zac Medico (zmedico)
  0 siblings, 0 replies; only message in thread
From: Zac Medico (zmedico) @ 2009-08-11 23:43 UTC (permalink / raw
  To: gentoo-commits

Author: zmedico
Date: 2009-08-11 23:43:10 +0000 (Tue, 11 Aug 2009)
New Revision: 14003

Modified:
   main/trunk/pym/portage/dbapi/__init__.py
   main/trunk/pym/portage/dbapi/bintree.py
   main/trunk/pym/portage/dbapi/porttree.py
   main/trunk/pym/portage/dbapi/vartree.py
Log:
Update imports to import portage.os (with unicode wrappers), and use
_unicode_encode() and _unicode_decode() where appropriate.


Modified: main/trunk/pym/portage/dbapi/__init__.py
===================================================================
--- main/trunk/pym/portage/dbapi/__init__.py	2009-08-11 23:00:42 UTC (rev 14002)
+++ main/trunk/pym/portage/dbapi/__init__.py	2009-08-11 23:43:10 UTC (rev 14003)
@@ -4,7 +4,6 @@
 
 __all__ = ["dbapi"]
 
-import os
 import re
 
 import portage
@@ -16,6 +15,7 @@
 	'portage.versions:catpkgsplit,vercmp',
 )
 
+from portage import os
 from portage import auxdbkeys, dep_expand
 from portage.localization import _
 

Modified: main/trunk/pym/portage/dbapi/bintree.py
===================================================================
--- main/trunk/pym/portage/dbapi/bintree.py	2009-08-11 23:00:42 UTC (rev 14002)
+++ main/trunk/pym/portage/dbapi/bintree.py	2009-08-11 23:43:10 UTC (rev 14003)
@@ -20,11 +20,14 @@
 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 @@
 			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,22 +108,11 @@
 		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
+		for k, v in values.iteritems():
+			k = _unicode_encode(k)
+			v = _unicode_encode(v)
+			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 mydata.items():
 			if not v:
 				del mydata[k]
@@ -660,7 +652,7 @@
 				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 @@
 	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

Modified: main/trunk/pym/portage/dbapi/porttree.py
===================================================================
--- main/trunk/pym/portage/dbapi/porttree.py	2009-08-11 23:00:42 UTC (rev 14002)
+++ main/trunk/pym/portage/dbapi/porttree.py	2009-08-11 23:43:10 UTC (rev 14003)
@@ -26,8 +26,12 @@
 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 @@
 				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 @@
 					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 @@
 			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)

Modified: main/trunk/pym/portage/dbapi/vartree.py
===================================================================
--- main/trunk/pym/portage/dbapi/vartree.py	2009-08-11 23:00:42 UTC (rev 14002)
+++ main/trunk/pym/portage/dbapi/vartree.py	2009-08-11 23:43:10 UTC (rev 14003)
@@ -37,6 +37,7 @@
 
 # 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 @@
 		""" 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 @@
 			# 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 @@
 				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 @@
 		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 @@
 			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 @@
 		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 @@
 
 		# 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 @@
 		"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 @@
 	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 @@
 	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 @@
 				tarinfo.size = 0
 				tar.addfile(tarinfo)
 			else:
-				f = open(path, 'rb')
+				f = open(_unicode_encode(path), 'rb')
 				try:
 					tar.addfile(tarinfo, f)
 				finally:




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-08-11 23:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-11 23:43 [gentoo-commits] portage r14003 - main/trunk/pym/portage/dbapi Zac Medico (zmedico)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox