summaryrefslogtreecommitdiffstats
path: root/pym/portage/util/__init__.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-10-28 17:12:11 -0700
committerZac Medico <zmedico@gentoo.org>2011-10-28 17:12:11 -0700
commita828ef4cb5ee60e448a95bb746a55fb476b1c575 (patch)
treed9832e8bfae8c266da28d72e665f5d3c165e52f3 /pym/portage/util/__init__.py
parent967bc855b7e4db529afbe8b7bf7f8ed7ea55858a (diff)
downloadportage-a828ef4cb5ee60e448a95bb746a55fb476b1c575.tar.gz
portage-a828ef4cb5ee60e448a95bb746a55fb476b1c575.tar.bz2
portage-a828ef4cb5ee60e448a95bb746a55fb476b1c575.zip
Use bytes instead of unicode with isinstance.
This is preferred since the bytes type is available in all supported python versions, while the unicode type is only available in python2.
Diffstat (limited to 'pym/portage/util/__init__.py')
-rw-r--r--pym/portage/util/__init__.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py
index 20eecd65a..54e683985 100644
--- a/pym/portage/util/__init__.py
+++ b/pym/portage/util/__init__.py
@@ -503,14 +503,15 @@ def writedict(mydict,myfilename,writekey=True):
def shlex_split(s):
"""
- This is equivalent to shlex.split but it temporarily encodes unicode
- strings to bytes since shlex.split() doesn't handle unicode strings.
+ This is equivalent to shlex.split, but if the current interpreter is
+ python2, it temporarily encodes unicode strings to bytes since python2's
+ shlex.split() doesn't handle unicode strings.
"""
- is_unicode = sys.hexversion < 0x3000000 and isinstance(s, unicode)
- if is_unicode:
+ convert_to_bytes = sys.hexversion < 0x3000000 and not isinstance(s, bytes)
+ if convert_to_bytes:
s = _unicode_encode(s)
rval = shlex.split(s)
- if is_unicode:
+ if convert_to_bytes:
rval = [_unicode_decode(x) for x in rval]
return rval