1 |
commit: a828ef4cb5ee60e448a95bb746a55fb476b1c575 |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Oct 29 00:12:11 2011 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Oct 29 00:12:11 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=a828ef4c |
7 |
|
8 |
Use bytes instead of unicode with isinstance. |
9 |
|
10 |
This is preferred since the bytes type is available in all supported |
11 |
python versions, while the unicode type is only available in python2. |
12 |
|
13 |
--- |
14 |
bin/repoman | 2 +- |
15 |
bin/xpak-helper.py | 4 ++-- |
16 |
pym/portage/elog/mod_syslog.py | 2 +- |
17 |
pym/portage/util/__init__.py | 11 ++++++----- |
18 |
4 files changed, 10 insertions(+), 9 deletions(-) |
19 |
|
20 |
diff --git a/bin/repoman b/bin/repoman |
21 |
index 2099241..42a6154 100755 |
22 |
--- a/bin/repoman |
23 |
+++ b/bin/repoman |
24 |
@@ -156,7 +156,7 @@ def ParseArgs(argv, qahelp): |
25 |
(opts, args), just like a call to parser.parse_args() |
26 |
""" |
27 |
|
28 |
- if argv and sys.hexversion < 0x3000000 and not isinstance(argv[0], unicode): |
29 |
+ if argv and isinstance(argv[0], bytes): |
30 |
argv = [portage._unicode_decode(x) for x in argv] |
31 |
|
32 |
modes = { |
33 |
|
34 |
diff --git a/bin/xpak-helper.py b/bin/xpak-helper.py |
35 |
index 4766d99..ef74920 100755 |
36 |
--- a/bin/xpak-helper.py |
37 |
+++ b/bin/xpak-helper.py |
38 |
@@ -1,5 +1,5 @@ |
39 |
#!/usr/bin/python |
40 |
-# Copyright 2009 Gentoo Foundation |
41 |
+# Copyright 2009-2011 Gentoo Foundation |
42 |
# Distributed under the terms of the GNU General Public License v2 |
43 |
|
44 |
import optparse |
45 |
@@ -36,7 +36,7 @@ def command_recompose(args): |
46 |
|
47 |
def main(argv): |
48 |
|
49 |
- if argv and sys.hexversion < 0x3000000 and not isinstance(argv[0], unicode): |
50 |
+ if argv and isinstance(argv[0], bytes): |
51 |
for i, x in enumerate(argv): |
52 |
argv[i] = portage._unicode_decode(x, errors='strict') |
53 |
|
54 |
|
55 |
diff --git a/pym/portage/elog/mod_syslog.py b/pym/portage/elog/mod_syslog.py |
56 |
index 79b11a6..6455841 100644 |
57 |
--- a/pym/portage/elog/mod_syslog.py |
58 |
+++ b/pym/portage/elog/mod_syslog.py |
59 |
@@ -23,7 +23,7 @@ def process(mysettings, key, logentries, fulltext): |
60 |
for msgtype,msgcontent in logentries[phase]: |
61 |
for line in msgcontent: |
62 |
line = "%s: %s: %s" % (key, phase, line) |
63 |
- if sys.hexversion < 0x3000000 and isinstance(line, unicode): |
64 |
+ if sys.hexversion < 0x3000000 and not isinstance(line, bytes): |
65 |
# Avoid TypeError from syslog.syslog() |
66 |
line = line.encode(_encodings['content'], |
67 |
'backslashreplace') |
68 |
|
69 |
diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py |
70 |
index 20eecd6..54e6839 100644 |
71 |
--- a/pym/portage/util/__init__.py |
72 |
+++ b/pym/portage/util/__init__.py |
73 |
@@ -503,14 +503,15 @@ def writedict(mydict,myfilename,writekey=True): |
74 |
|
75 |
def shlex_split(s): |
76 |
""" |
77 |
- This is equivalent to shlex.split but it temporarily encodes unicode |
78 |
- strings to bytes since shlex.split() doesn't handle unicode strings. |
79 |
+ This is equivalent to shlex.split, but if the current interpreter is |
80 |
+ python2, it temporarily encodes unicode strings to bytes since python2's |
81 |
+ shlex.split() doesn't handle unicode strings. |
82 |
""" |
83 |
- is_unicode = sys.hexversion < 0x3000000 and isinstance(s, unicode) |
84 |
- if is_unicode: |
85 |
+ convert_to_bytes = sys.hexversion < 0x3000000 and not isinstance(s, bytes) |
86 |
+ if convert_to_bytes: |
87 |
s = _unicode_encode(s) |
88 |
rval = shlex.split(s) |
89 |
- if is_unicode: |
90 |
+ if convert_to_bytes: |
91 |
rval = [_unicode_decode(x) for x in rval] |
92 |
return rval |