diff options
author | Zac Medico <zmedico@gentoo.org> | 2011-10-28 17:12:11 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2011-10-28 17:12:11 -0700 |
commit | a828ef4cb5ee60e448a95bb746a55fb476b1c575 (patch) | |
tree | d9832e8bfae8c266da28d72e665f5d3c165e52f3 /pym | |
parent | 967bc855b7e4db529afbe8b7bf7f8ed7ea55858a (diff) | |
download | portage-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')
-rw-r--r-- | pym/portage/elog/mod_syslog.py | 2 | ||||
-rw-r--r-- | pym/portage/util/__init__.py | 11 |
2 files changed, 7 insertions, 6 deletions
diff --git a/pym/portage/elog/mod_syslog.py b/pym/portage/elog/mod_syslog.py index 79b11a68c..64558410d 100644 --- a/pym/portage/elog/mod_syslog.py +++ b/pym/portage/elog/mod_syslog.py @@ -23,7 +23,7 @@ def process(mysettings, key, logentries, fulltext): for msgtype,msgcontent in logentries[phase]: for line in msgcontent: line = "%s: %s: %s" % (key, phase, line) - if sys.hexversion < 0x3000000 and isinstance(line, unicode): + if sys.hexversion < 0x3000000 and not isinstance(line, bytes): # Avoid TypeError from syslog.syslog() line = line.encode(_encodings['content'], 'backslashreplace') 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 |