Skip to content

Commit

Permalink
ini file reading works across 2.7 and 3.4
Browse files Browse the repository at this point in the history
We now import BytesIO or StringIO as ini_file_io depending on the
import statement we used for configparser.

This allows us to give a string to python3 as a file-like object.
  • Loading branch information
Bob Gregory authored and Joseph Solomon committed Oct 23, 2015
1 parent 846249b commit 5ad9d6e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions shinto_cli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _parse_ini(data_string):
$ j2 config.j2 data.ini
$ cat data.ini | j2 --format=ini config.j2
"""
from io import BytesIO
from io import StringIO

# Override
class MyConfigParser(ConfigParser.ConfigParser):
Expand All @@ -41,7 +41,7 @@ def as_dict(self):

# Parse
ini = MyConfigParser()
ini.readfp(BytesIO(data_string))
ini.readfp(ini_file_io(data_string))

# Export
return ini.as_dict()
Expand Down Expand Up @@ -152,8 +152,10 @@ def _parse_env(data_string):
# INI: Python 2 | Python 3
try:
import ConfigParser
from io import BytesIO as ini_file_io
except ImportError:
import configparser as ConfigParser
from io import StringIO as ini_file_io

# YAML
try:
Expand Down

0 comments on commit 5ad9d6e

Please sign in to comment.