Skip to content

Commit

Permalink
fix for python2 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ITProKyle committed Jan 7, 2020
1 parent 3f24c92 commit 7cab74d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/hcl/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@
def iteritems(d):
return iter(d.iteritems())

string_types = (str, unicode)


else:

def iteritems(d):
return iter(d.items())

string_types = (str, bytes)


class HclParser(object):

Expand Down Expand Up @@ -389,9 +393,13 @@ def flatten(self, value):
return ",".join(self.flatten(v) for v in value)
if isinstance(value, tuple):
return " ".join(self.flatten(v) for v in value)
if isinstance(value, str):
if value.isnumeric(): # return numbers as is
return value
if isinstance(value, string_types):
if sys.version_info[0] < 3:
if value.isdigit(): # python2 support, return numbers as is
return value
else:
if value.isnumeric(): # return numbers as is
return value
return (
'"' + value + '"' # wrap string literals in double quotes
if value not in ['+', '-'] and '.' not in value
Expand Down

0 comments on commit 7cab74d

Please sign in to comment.