Skip to content

Commit 05a622c

Browse files
committed
More compatibility with python 3
1 parent 1b88d67 commit 05a622c

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

hierarchical_yaml/config_generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import json
1717
from .interpolation import InterpolationResolver, InterpolationValidator
1818
from .remote_state import S3TerraformRemoteStateRetriever
19-
from .python_compat import iteritems
19+
from .python_compat import iteritems, primitive_types
2020

2121
class ConfigProcessor(object):
2222

@@ -139,7 +139,7 @@ def merge_yamls(values, yaml_content):
139139
if key in values and type(values[key]) != type(value):
140140
raise Exception("Failed to merge key '{}', because of mismatch in type: {} vs {}"
141141
.format(key, type(values[key]), type(value)))
142-
if key in values and not isinstance(value, (basestring, int, bool)):
142+
if key in values and not isinstance(value, primitive_types):
143143
values[key] = ConfigGenerator.merge_value(values[key], value)
144144
else:
145145
values[key] = value

hierarchical_yaml/interpolation.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010

1111
import re
1212
from .inject_secrets import SecretInjector
13+
from .python_compat import iteritems, string_types, primitive_types
1314

1415

1516
def is_interpolation(value):
16-
return isinstance(value, (basestring)) and '{{' in value and '}}' in value
17+
return isinstance(value, string_types) and '{{' in value and '}}' in value
18+
1719

1820
def is_full_interpolation(value):
1921
return is_interpolation(value) and value.startswith('{{') and value.endswith('}}')
2022

23+
2124
def remove_white_spaces(value):
2225
return re.sub(r"\s+", "", value)
2326

@@ -59,7 +62,7 @@ def __init__(self):
5962
pass
6063

6164
def loop_all_items(self, data, process_func):
62-
if isinstance(data, basestring):
65+
if isinstance(data, string_types):
6366
return process_func(data)
6467
if isinstance(data, list):
6568
items = []
@@ -134,13 +137,13 @@ def __init__(self):
134137

135138
def resolve(self, line, data):
136139
"""
137-
:param input: {{env.name}}
140+
:param line: {{env.name}}
138141
:param data: (env: name: dev)
139142
:return: dev
140143
"""
141144

142145
self.parse_leaves(data, "")
143-
for key, value in self.results.iteritems():
146+
for key, value in iteritems(self.results):
144147
placeholder = "{{" + key + "}}"
145148
if placeholder not in line:
146149
continue
@@ -151,7 +154,7 @@ def resolve(self, line, data):
151154
return line
152155

153156
def parse_leaves(self, data, partial_key):
154-
if isinstance(data, (basestring, int, bool)):
157+
if isinstance(data, primitive_types):
155158
self.results[partial_key] = data
156159
return
157160
if isinstance(data, dict):

hierarchical_yaml/python_compat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
iteritems = lambda d: iter(d.items())
1717
integer_types = (int,)
1818
string_types = (str,)
19+
primitive_types = (str, int, bool)
1920
else:
2021
iteritems = lambda d: d.iteritems()
2122
integer_types = (int, long)
2223
string_types = (str, unicode)
24+
primitive_types = (str, unicode, int, long, bool)

0 commit comments

Comments
 (0)