Patchwork [2,of,2,hglib] hglib: use io.BytesIO when available (issue4520)

login
register
mail settings
Submitter Brett Cannon
Date March 13, 2015, 3:37 p.m.
Message ID <8d7bf729a4db5f9386b9.1426261066@bcannon-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/8055/
State Accepted
Headers show

Comments

Brett Cannon - March 13, 2015, 3:37 p.m.
# HG changeset patch
# User Brett Cannon <brett@python.org>
# Date 1426260892 14400
#      Fri Mar 13 11:34:52 2015 -0400
# Node ID 8d7bf729a4db5f9386b947344df1deca5c37e58d
# Parent  f3c430afa59888273201c715123649ee6ec48b3a
hglib: use io.BytesIO when available (issue4520)

Since cStringIO.StringIO is not available in Python 3, try to use
io.BytesIO when available.
Matt Mackall - March 13, 2015, 5:30 p.m.
On Fri, 2015-03-13 at 11:37 -0400, Brett Cannon wrote:
> # HG changeset patch
> # User Brett Cannon <brett@python.org>
> # Date 1426260892 14400
> #      Fri Mar 13 11:34:52 2015 -0400
> # Node ID 8d7bf729a4db5f9386b947344df1deca5c37e58d
> # Parent  f3c430afa59888273201c715123649ee6ec48b3a
> hglib: use io.BytesIO when available (issue4520)

These are queued, thanks. I've made a follow-up patch that hides all the
import magic in util.

Patch

diff -r f3c430afa598 -r 8d7bf729a4db hglib/client.py
--- a/hglib/client.py	Fri Mar 13 11:31:54 2015 -0400
+++ b/hglib/client.py	Fri Mar 13 11:34:52 2015 -0400
@@ -1,5 +1,8 @@ 
 import subprocess, os, struct, re, datetime
-from cStringIO import StringIO as BytesIO
+try:
+    from io import BytesIO
+except ImportError:
+    from cStringIO import StringIO as BytesIO
 import hglib, error, util, templates, merge, context
 
 from util import b, cmdbuilder
diff -r f3c430afa598 -r 8d7bf729a4db hglib/util.py
--- a/hglib/util.py	Fri Mar 13 11:31:54 2015 -0400
+++ b/hglib/util.py	Fri Mar 13 11:34:52 2015 -0400
@@ -1,5 +1,8 @@ 
 import itertools, error, os, subprocess, sys
-from cStringIO import StringIO as BytesIO
+try:
+    from io import BytesIO
+except ImportError:
+    from cStringIO import StringIO as BytesIO
 
 if sys.version_info[0] > 2:
     def b(s):
diff -r f3c430afa598 -r 8d7bf729a4db tests/test-import.py
--- a/tests/test-import.py	Fri Mar 13 11:31:54 2015 -0400
+++ b/tests/test-import.py	Fri Mar 13 11:34:52 2015 -0400
@@ -1,5 +1,8 @@ 
 import common, os
-from cStringIO import StringIO as BytesIO
+try:
+    from io import BytesIO
+except ImportError:
+    from cStringIO import StringIO as BytesIO
 import hglib
 from hglib.util import b