From f7ff7a7bd96090a46dfbddf905866630fcfbe94c Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Thu, 24 Sep 2009 17:22:25 +0000 Subject: [PATCH] Merged from trunk -r14358:14368 | 14361 | Fix decodeint() for py3k compat, since bytes are a sequence | | zmedico | of integers instead of characters. | | 14362 | Temporarily disable use of pty in py3k since it triggers an | | zmedico | unresolved issue, http://bugs.python.org/issue5380. With | | | this workaround, | | | portage.tests.ebuild.test_spawn.SpawnTestCase.testLogfile() | | | does not raise IOError. | | 14363 | Don't encode the env in py3k since it expects strings for | | zmedico | the env that's passed into os.execve(). | | 14364 | Make find_binary() use os.environ.get instead of os.getenv, | | zmedico | since os.getenv isn't behaving correctly in py3k (maybe a | | | unicode wrapper issue?). | | 14365 | Fix PORTAGE_WORKDIR_MODE parsing code so it doesn't store | | zmedico | python's octal syntax in the environment variable. | | 14366 | In _unicode_func_wrapper, only encode keyword argument | | zmedico | values, and not the keys. | | 14367 | Encode/decode names from the xpak index where appropriate. | | zmedico | | | 14368 | Fix sorted() keyword arg for py3k. | | zmedico | | svn path=/main/branches/prefix/; revision=14403 --- pym/portage/__init__.py | 9 ++++++--- pym/portage/getbinpkg.py | 3 ++- pym/portage/process.py | 25 ++++++++++--------------- pym/portage/xpak.py | 17 ++++++++++++----- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 57976895d..836666428 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -183,8 +183,7 @@ class _unicode_func_wrapper(object): for x in args] if kwargs: wrapped_kwargs = dict( - (_unicode_encode(k, encoding=encoding, errors='strict'), - _unicode_encode(v, encoding=encoding, errors='strict')) + (k, _unicode_encode(v, encoding=encoding, errors='strict')) for k, v in kwargs.items()) else: wrapped_kwargs = {} @@ -3763,6 +3762,10 @@ if platform.system() in ["SunOS"]: else: _disable_openpty = False +if sys.hexversion >= 0x3000000: + # This is a temporary workaround for http://bugs.python.org/issue5380. + _disable_openpty = True + def _create_pty_or_pipe(copy_term_size=None): """ Try to create a pty and if then fails then create a normal @@ -6307,7 +6310,7 @@ def _prepare_workdir(mysettings): writemsg("%s\n" % e) writemsg(_("!!! Unable to parse PORTAGE_WORKDIR_MODE='%s', using %s.\n") % \ (mysettings["PORTAGE_WORKDIR_MODE"], oct(workdir_mode))) - mysettings["PORTAGE_WORKDIR_MODE"] = oct(workdir_mode) + mysettings["PORTAGE_WORKDIR_MODE"] = oct(workdir_mode).replace('o', '') try: apply_secpass_permissions(mysettings["WORKDIR"], uid=portage_uid, gid=portage_gid, mode=workdir_mode) diff --git a/pym/portage/getbinpkg.py b/pym/portage/getbinpkg.py index af010577a..62e76b4f3 100644 --- a/pym/portage/getbinpkg.py +++ b/pym/portage/getbinpkg.py @@ -822,7 +822,8 @@ class PackageIndex(object): keys.sort() self._writepkgindex(pkgfile, [(k, self.header[k]) \ for k in keys if self.header[k]]) - for metadata in sorted(self.packages, _cmp_cpv): + for metadata in sorted(self.packages, + key=portage.util.cmp_sort_key(_cmp_cpv)): metadata = metadata.copy() cpv = metadata["CPV"] if self._inherited_keys: diff --git a/pym/portage/process.py b/pym/portage/process.py index 428c66f4c..e7f09cd2d 100644 --- a/pym/portage/process.py +++ b/pym/portage/process.py @@ -188,13 +188,14 @@ def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False, if isinstance(mycommand, basestring): mycommand = mycommand.split() - # Avoid a potential UnicodeEncodeError from os.execve(). - env_bytes = {} - for k, v in env.items(): - env_bytes[_unicode_encode(k, encoding=_encodings['content'])] = \ - _unicode_encode(v, encoding=_encodings['content']) - env = env_bytes - del env_bytes + if sys.hexversion < 0x3000000: + # Avoid a potential UnicodeEncodeError from os.execve(). + env_bytes = {} + for k, v in env.items(): + env_bytes[_unicode_encode(k, encoding=_encodings['content'])] = \ + _unicode_encode(v, encoding=_encodings['content']) + env = env_bytes + del env_bytes # If an absolute path to an executable file isn't given # search for it unless we've been told not to. @@ -373,13 +374,8 @@ def _exec(binary, mycommand, opt_name, fd_pipes, env, gid, groups, uid, umask, if pre_exec: pre_exec() - # Decode all keys for compatibility with Python 3. - env_decoded = {} - for k, v in env.items(): - env_decoded[_unicode_decode(k)] = v - # And switch to the new process. - os.execve(binary, myargs, env_decoded) + os.execve(binary, myargs, env) def find_binary(binary): """ @@ -390,8 +386,7 @@ def find_binary(binary): @rtype: None or string @returns: full path to binary or None if the binary could not be located. """ - - for path in os.getenv("PATH", "").split(":"): + for path in os.environ.get("PATH", "").split(":"): filename = "%s/%s" % (path, binary) if os.access(filename, os.X_OK) and os.path.isfile(filename): return filename diff --git a/pym/portage/xpak.py b/pym/portage/xpak.py index b5878befb..b753f2490 100644 --- a/pym/portage/xpak.py +++ b/pym/portage/xpak.py @@ -19,6 +19,7 @@ import array import errno import shutil +import sys from portage import os from portage import normalize_path @@ -65,11 +66,13 @@ def encodeint(myint): def decodeint(mystring): """Takes a 4 byte string and converts it into a 4 byte integer. Returns an integer.""" - myint=0 - myint=myint+ord(mystring[3]) - myint=myint+(ord(mystring[2]) << 8) - myint=myint+(ord(mystring[1]) << 16) - myint=myint+(ord(mystring[0]) << 24) + if sys.hexversion < 0x3000000: + mystring = [ord(x) for x in mystring] + myint = 0 + myint += mystring[3] + myint += mystring[2] << 8 + myint += mystring[1] << 16 + myint += mystring[0] << 24 return myint def xpak(rootdir,outfile=None): @@ -206,6 +209,8 @@ def getindex_mem(myindex): def searchindex(myindex,myitem): """(index,item) -- Finds the offset and length of the file 'item' in the datasegment via the index 'index' provided.""" + myitem = _unicode_encode(myitem, + encoding=_encodings['repo.content'], errors='backslashreplace') mylen=len(myitem) myindexlen=len(myindex) startpos=0 @@ -413,6 +418,8 @@ class tbz2(object): datapos=decodeint(self.index[startpos+4+namelen:startpos+8+namelen]); datalen=decodeint(self.index[startpos+8+namelen:startpos+12+namelen]); myname=self.index[startpos+4:startpos+4+namelen] + myname = _unicode_decode(myname, + encoding=_encodings['repo.content'], errors='replace') dirname=os.path.dirname(myname) if dirname: if not os.path.exists(dirname): -- 2.26.2