10000 Handle StringIO for Python2 properly · abhinavcoder/python@408d405 · GitHub
[go: up one dir, main page]

Skip to content

Commit 408d405

Browse files
committed
Handle StringIO for Python2 properly
1 parent 8d41478 commit 408d405

File tree

10000

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

kubernetes/utils/create_from_yaml.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
import io
1514
import re
15+
import sys
16+
17+
if sys.version_info.major > 2:
18+
from StringIO import StringIO
19+
else:
20+
from io import StringIO
1621

1722
from os import path
1823

@@ -56,7 +61,11 @@ def create_from_yaml(
5661
"""
5762
if path.exists(yaml_file):
5863
with open(path.abspath(yaml_file)) as f:
59-
yaml_file = io.StringIO(f.read())
64+
content = f.read()
65+
try:
66+
yaml_file = StringIO(content)
67+
except TypeError:
68+
yaml_file = StringIO(content.decode('utf-8'))
6069

6170
yml_document_all = yaml.safe_load_all(yaml_file)
6271
# Load all documents from a single YAML file

0 commit comments

Comments
 (0)
0