Fix bug in python3.4: 'dict_keys' object does not support indexing 41/16641/2
authorshangxdy <shang.xiaodong@zte.com.cn>
Sat, 9 Jul 2016 17:09:02 +0000 (01:09 +0800)
committershangxdy <shang.xiaodong@zte.com.cn>
Sat, 9 Jul 2016 17:20:58 +0000 (01:20 +0800)
In python3.4, dictory's function of key() return value is a dict_key object, not list, so the follow code will be error:
    dict x = {1:11, 2:22, 3;33}
    y= x.keys()[0]
 the error is TypeError: 'dict_keys' object does not support indexing, the correct expression is below:
    y = list(x.keys())[0]

So parser's code will be modified refer to above.

Change-Id: I41e0c28167c7823fc735aaf3afc78c1a9a15e9e0
JIRA: PARSER-64
Signed-off-by: shangxdy <shang.xiaodong@zte.com.cn>
tosca2heat/tosca-parser/toscaparser/elements/entity_type.py
tosca2heat/tosca-parser/toscaparser/tosca_template.py

index 5947b1c..9b9787b 100644 (file)
@@ -108,8 +108,9 @@ class EntityType(object):
                             if isinstance(value, list):
                                 for p_value in parent_value:
                                     if isinstance(p_value, dict):
-                                        if p_value.keys()[0] not in [
-                                            item.keys()[0] for item in value]:
+                                        if list(p_value.keys())[0] not in [
+                                            list(item.keys())[0] for item in
+                                            value]:
                                             value.append(p_value)
                                     else:
                                         if p_value not in value:
index 01e6c73..8753a2c 100644 (file)
@@ -210,7 +210,7 @@ class ToscaTemplate(object):
 
     def _handle_nested_topo_tpls(self, nested_topo_tpls):
         for tpl in nested_topo_tpls:
-            filename, tosca_tpl = tpl.items()[0]
+            filename, tosca_tpl = list(tpl.items())[0]
             if tosca_tpl.get(TOPOLOGY_TEMPLATE):
                 nested_template = ToscaTemplate(
                     path=filename, parsed_params=self.parsed_params,