From: Zac Medico Date: Sat, 22 Jun 2013 17:49:36 +0000 (-0700) Subject: find_binary: return bytes when input is bytes X-Git-Tag: v2.2.0_alpha185~13 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=30fe6f117ce0350c6b6d1279bae63508a8abbf59;p=portage.git find_binary: return bytes when input is bytes --- diff --git a/pym/portage/process.py b/pym/portage/process.py index 24e347c26..7104552c4 100644 --- a/pym/portage/process.py +++ b/pym/portage/process.py @@ -9,6 +9,7 @@ import platform import signal import sys import traceback +import os as _os from portage import os from portage import _encodings @@ -520,8 +521,16 @@ def find_binary(binary): @rtype: None or string @return: full path to binary or None if the binary could not be located. """ - 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): + paths = os.environ.get("PATH", "") + if sys.hexversion >= 0x3000000 and isinstance(binary, bytes): + # return bytes when input is bytes + paths = paths.encode(sys.getfilesystemencoding(), 'surrogateescape') + paths = paths.split(b':') + else: + paths = paths.split(':') + + for path in paths: + filename = _os.path.join(path, binary) + if _os.access(filename, os.X_OK) and _os.path.isfile(filename): return filename return None