# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from __future__ import print_function
+from __future__ import unicode_literals
import os
import sys
import configparser as ConfigParser
import shutil
import re
-
-# Add a shim for Python 2's unicode() helper.
-try:
- unicode
-except NameError:
- # Python 3 does everything by unicode now.
- unicode = str
+import io
+import locale
+
+if sys.version_info.major == 2:
+ # hack to make writing unicode to standard output/error work on Python 2
+ OUT_ENCODING = sys.stdout.encoding or locale.getpreferredencoding() or \
+ os.getenv('PYTHONIOENCODING', 'utf-8')
+ sys.stdout = io.open(sys.stdout.fileno(), mode='w',
+ encoding=OUT_ENCODING, errors='replace')
+ sys.stderr = io.open(sys.stderr.fileno(), mode='w',
+ encoding=OUT_ENCODING, errors='replace')
# Default Patchwork remote XML-RPC server URL
# This script will check the PW_XMLRPC_URL environment variable
for id in ids:
person = rpc.person_get(id)
print('Patches submitted by %s <%s>:' %
- (unicode(person['name']).encode('utf-8'),
- unicode(person['email']).encode('utf-8')))
+ (person['name'], person['email']))
f = filter
f.add("submitter_id", id)
patches = rpc.patch_list(f.d)
print(s)
print('-' * len(s))
for key, value in sorted(check.items()):
- print("- %- 14s: %s" % (key, unicode(value)))
+ print("- %- 14s: %s" % (key, value))
def action_check_create(rpc, patch_id, context, state, url, description):
print(s)
print('-' * len(s))
for key, value in sorted(patch.items()):
- print("- %- 14s: %s" % (key, unicode(value)))
+ print("- %- 14s: %s" % (key, value))
def action_get(rpc, patch_id):
i += 1
try:
- f = open(fname, "w")
+ f = io.open(fname, "w", encoding="utf-8")
except:
sys.stderr.write("Unable to open %s for writing\n" % fname)
sys.exit(1)
s = rpc.patch_get_mbox(patch_id)
if len(s) > 0:
proc = subprocess.Popen(apply_cmd, stdin=subprocess.PIPE)
- proc.communicate(unicode(s).encode('utf-8'))
+ proc.communicate(s.encode('utf-8'))
return proc.returncode
else:
sys.stderr.write("Error: No patch content found\n")
for patch_id in non_empty(h, patch_ids):
s = rpc.patch_get_mbox(patch_id)
if len(s) > 0:
- i.append(unicode(s))
+ i.append(s)
if len(i) > 0:
pager.communicate(input="\n".join(i).encode("utf-8"))
pager.stdin.close()
for patch_id in non_empty(h, patch_ids):
s = rpc.patch_get_mbox(patch_id)
if len(s) > 0:
- print(unicode(s))
+ print(s)
elif action == 'info':
for patch_id in non_empty(h, patch_ids):