Skip to content

Commit

Permalink
es_jsonschema: fix python compatibility
Browse files Browse the repository at this point in the history
* Fixes Python 3 compatibility of templating a mapping functions.

Signed-off-by: Nicolas Harraudeau <nicolas.harraudeau@cern.ch>
  • Loading branch information
Nicolas Harraudeau committed Nov 19, 2015
1 parent 411626d commit 5377e9f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 6 additions & 5 deletions es_jsonschema/mapping.py
Expand Up @@ -25,8 +25,9 @@
"""Elastic Search integration. mapping funtion."""

import jsonschema
from six import iteritems

from es_jsonschema.errors import JsonSchemaSupportError
from .errors import JsonSchemaSupportError


class ElasticMappingGeneratorConfig(object):
Expand Down Expand Up @@ -326,7 +327,7 @@ def __gen_type_properties(json_schema, path, resolver, config, es_mapping):
es_mapping['properties'] = es_properties
# build the elasticsearch mapping corresponding to each json schema
# property
for prop, prop_schema in json_schema['properties'].iteritems():
for prop, prop_schema in iteritems(json_schema['properties']):
es_properties[prop] = \
__gen_type_properties(prop_schema,
path + '/' + prop,
Expand All @@ -335,7 +336,7 @@ def __gen_type_properties(json_schema, path, resolver, config, es_mapping):
# visit the dependencies defining additional properties
if 'dependencies' in json_schema:
deps_path = path + '/dependencies'
for prop, deps in json_schema['dependencies'].iteritems():
for prop, deps in iteritems(json_schema['dependencies']):
# if this is a "schema dependency", extend our current es
# mapping with it
if isinstance(deps, dict):
Expand All @@ -344,7 +345,7 @@ def __gen_type_properties(json_schema, path, resolver, config, es_mapping):
else:
es_mapping['type'] = es_type
if es_type_props:
for type_prop, type_prop_value in es_type_props.iteritems():
for type_prop, type_prop_value in iteritems(es_type_props):
es_mapping[type_prop] = type_prop_value

# pop the current jsonschema context
Expand All @@ -362,4 +363,4 @@ def clean_mapping(mapping):
"""
return {key: (value if not isinstance(value, dict)
else clean_mapping(value))
for (key, value) in mapping.iteritems() if value is not None}
for (key, value) in iteritems(mapping) if value is not None}
5 changes: 3 additions & 2 deletions es_jsonschema/templating.py
Expand Up @@ -27,6 +27,7 @@
import json

import jinja2
from six import iteritems

from .mapping import clean_mapping

Expand Down Expand Up @@ -55,14 +56,14 @@ def __mapping_to_jinja_rec(es_mapping, path='', indent=2, start_indent=''):
result += '{i}{{% block {path} %}}\n' \
.format(i=start_indent, path=path)
root_idx = 0
for key, value in es_mapping.iteritems():
for key, value in iteritems(es_mapping):
if key == 'properties':
indent1 = start_indent + ' ' * indent
result += '{i}"properties": {{\n'.format(i=start_indent)
result += '{i}{{% block {path}__PROPERTIES__ %}}\n' \
.format(i=indent1, path=path)
prop_idx = 0
for prop_name, prop_schema in value.iteritems():
for prop_name, prop_schema in iteritems(value):
result += '{i}"{name}": {{\n'.format(i=indent1, name=prop_name)

result += __mapping_to_jinja_rec(prop_schema,
Expand Down

0 comments on commit 5377e9f

Please sign in to comment.