Skip to content

Commit 86650bb

Browse files
committed
[gyb] Python 2 and 3 compatible StringIO import
The `StringIO` and `cStringIO` modules are gone in Python 3. The recommendation is to import the `io` module on Python 3. Therefore, this patch first attempts to import the Python 2 module, `cStringIO`, and if that fails then attempts to import the Python 3 module, `io`. **NOTE**: There are still other Python 3.x fixes necessary to make `gyb` run on a Python 3.x interpreter. This is just one small incremental patch on the way there.
1 parent 7700b3b commit 86650bb

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

utils/gyb.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
from __future__ import print_function
66

77
import re
8-
from cStringIO import StringIO
8+
try:
9+
from cStringIO import StringIO
10+
except ImportError:
11+
from io import StringIO
912
import tokenize
1013
import textwrap
1114
from bisect import bisect

0 commit comments

Comments
 (0)