validate_desktop_entry: handle Python 3.1
authorZac Medico <zmedico@gentoo.org>
Tue, 1 May 2012 21:21:44 +0000 (14:21 -0700)
committerZac Medico <zmedico@gentoo.org>
Tue, 1 May 2012 21:21:44 +0000 (14:21 -0700)
pym/portage/util/_desktop_entry.py

index 101965f6a23891a4cb0b3c7b1141946e31871d73..790178013769833409645a314ad782ad47376c64 100644 (file)
@@ -3,6 +3,7 @@
 
 import io
 import subprocess
+import sys
 
 try:
        from configparser import Error as ConfigParserError, RawConfigParser
@@ -41,7 +42,11 @@ _ignored_service_errors = (
 )
 
 def validate_desktop_entry(path):
-       proc = subprocess.Popen([b"desktop-file-validate", _unicode_encode(path)],
+       args = ["desktop-file-validate", path]
+       if sys.hexversion < 0x3000000 or sys.hexversion >= 0x3020000:
+               # Python 3.1 does not support bytes in Popen args.
+               args = [_unicode_encode(x, errors='strict') for x in args]
+       proc = subprocess.Popen(args,
                stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        output_lines = _unicode_decode(proc.communicate()[0]).splitlines()
        proc.wait()