# Path: grafana_dashboards/errors.py
# class DashboardBuilderException(Exception):
# class DuplicateKeyError(DashboardBuilderException):
# class WrongComponentAttributeCountError(DashboardBuilderException):
# class UnregisteredComponentError(DashboardBuilderException):
# 
# Path: grafana_dashboards/common.py
# def get_component_type(clazz):
#     """
# 
#     :type clazz: type
#     """
#     return _all_cap_re.sub(r'\1-\2', _first_cap_re.sub(r'\1-\2', clazz.__name__)).lower()
# 
# Path: grafana_dashboards/context.py
# class Context(object):
# 
#     _pattern = re.compile('{.*}')
# 
#     def __init__(self, context=None):
#         super(Context, self).__init__()
#         if not context:
#             self._context = None
#         else:
#             self._context = DictDefaultingToPlaceholder(context)
# 
#     def expand_placeholders(self, to_expand):
#         """
# 
#         :rtype : dict
#         """
#         if not self._context:
#             return to_expand
# 
#         if isinstance(to_expand, basestring):
#             (result, to_expand) = self._expand(to_expand)
#             while result != to_expand:
#                 (result, to_expand) = self._expand(result)
#             if isinstance(result, basestring):
#                 return string.Formatter().vformat(result, (), self._context)
#             else:
#                 return result
#         elif isinstance(to_expand, list):
#             return [self.expand_placeholders(value) for value in to_expand]
#         elif isinstance(to_expand, dict):
#             return dict([(key, self.expand_placeholders(value)) for (key, value) in to_expand.items()])
#         else:
#             return to_expand
# 
#     def _expand(self, to_expand):
#         if not isinstance(to_expand, basestring):
#             return to_expand, to_expand
#         elif self._pattern.match(to_expand) and to_expand[1:-1] in self._context:
#             return self._context[to_expand[1:-1]], to_expand
#         escaped = to_expand.replace('{{', '{{{{').replace('}}', '}}}}')
#         return string.Formatter().vformat(escaped, (), self._context), to_expand
# 
#     def __str__(self):
#         return str(self._context)
# 
#     @staticmethod
#     def create_context(data, keys_to_expand=None):
#         return (Context(Context(context).expand_placeholders(context))
#                 for context in ContextExpander(keys_to_expand).create_context(None, data))


import logging
import string
from grafana_dashboards import errors
from grafana_dashboards.common import get_component_type
from grafana_dashboards.context import Context
        for field in self._copy_fields:
            if field in data:
                json[field] = data[field]
        return json


class JsonListGenerator(JsonGenerator):
    def __init__(self, data, registry, item_base_class):
        super(JsonListGenerator, self).__init__(data, registry)
        self.component_item_types = [get_component_type(clazz) for clazz in _get_subclasses(item_base_class)]

    def gen_json_from_data(self, data, context):
        super(JsonListGenerator, self).gen_json_from_data(data, context)
        result_list = []
        for items in data:
            self.gen_item_json(items, result_list)
        return result_list

    def gen_item_json(self, items, result_list):
        if isinstance(items, basestring):
            # this is component without context
            result_list += self.registry.get_component(type(self), items).gen_json()
        else:
            self._gen_item_json_with_context(items, result_list)

    def _gen_item_json_with_context(self, items, result_list):
        # TODO add check for dictionary
        for (item_type, item_data) in items.items():
            if item_type not in self.component_item_types:
                # this is named component with context

# Path: grafana_dashboards/errors.py
# class DashboardBuilderException(Exception):
# class DuplicateKeyError(DashboardBuilderException):
# class WrongComponentAttributeCountError(DashboardBuilderException):
# class UnregisteredComponentError(DashboardBuilderException):
# 
# Path: grafana_dashboards/common.py
# def get_component_type(clazz):
#     """
# 
#     :type clazz: type
#     """
#     return _all_cap_re.sub(r'\1-\2', _first_cap_re.sub(r'\1-\2', clazz.__name__)).lower()
# 
# Path: grafana_dashboards/context.py
# class Context(object):
# 
#     _pattern = re.compile('{.*}')
# 
#     def __init__(self, context=None):
#         super(Context, self).__init__()
#         if not context:
#             self._context = None
#         else:
#             self._context = DictDefaultingToPlaceholder(context)
# 
#     def expand_placeholders(self, to_expand):
#         """
# 
#         :rtype : dict
#         """
#         if not self._context:
#             return to_expand
# 
#         if isinstance(to_expand, basestring):
#             (result, to_expand) = self._expand(to_expand)
#             while result != to_expand:
#                 (result, to_expand) = self._expand(result)
#             if isinstance(result, basestring):
#                 return string.Formatter().vformat(result, (), self._context)
#             else:
#                 return result
#         elif isinstance(to_expand, list):
#             return [self.expand_placeholders(value) for value in to_expand]
#         elif isinstance(to_expand, dict):
#             return dict([(key, self.expand_placeholders(value)) for (key, value) in to_expand.items()])
#         else:
#             return to_expand
# 
#     def _expand(self, to_expand):
#         if not isinstance(to_expand, basestring):
#             return to_expand, to_expand
#         elif self._pattern.match(to_expand) and to_expand[1:-1] in self._context:
#             return self._context[to_expand[1:-1]], to_expand
#         escaped = to_expand.replace('{{', '{{{{').replace('}}', '}}}}')
#         return string.Formatter().vformat(escaped, (), self._context), to_expand
# 
#     def __str__(self):
#         return str(self._context)
# 
#     @staticmethod
#     def create_context(data, keys_to_expand=None):
#         return (Context(Context(context).expand_placeholders(context))
#                 for context in ContextExpander(keys_to_expand).create_context(None, data))


# Path: grafana_dashboards/components/base.py
import logging
import string
from grafana_dashboards import errors
from grafana_dashboards.common import get_component_type
from grafana_dashboards.context import Context

        for field in self._copy_fields:
            if field in data:
                json[field] = data[field]
        return json


class JsonListGenerator(JsonGenerator):
    def __init__(self, data, registry, item_base_class):
        super(JsonListGenerator, self).__init__(data, registry)
        self.component_item_types = [get_component_type(clazz) for clazz in _get_subclasses(item_base_class)]

    def gen_json_from_data(self, data, context):
        super(JsonListGenerator, self).gen_json_from_data(data, context)
        result_list = []
        for items in data:
            self.gen_item_json(items, result_list)
        return result_list

    def gen_item_json(self, items, result_list):
        if isinstance(items, basestring):
            # this is component without context
            result_list += self.registry.get_component(type(self), items).gen_json()
        else:
            self._gen_item_json_with_context(items, result_list)

    def _gen_item_json_with_context(self, items, result_list):
        # TODO add check for dictionary
        for (item_type, item_data) in items.items():
            if item_type not in self.component_item_types:
                # this is named component with context

                for context in Context.create_context(item_data, get_placeholders(item_type)):