# 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

    def get_component(self, component_type, name):
        component = self._get_component(component_type).get(name)
        if component is None:
            raise errors.UnregisteredComponentError("No component '%s' with name '%s' found!" % (component_type, name))
        return component


class ComponentBase(object):
    def __init__(self, data, registry):
        """

        :type registry: ComponentRegistry
        """
        super(ComponentBase, self).__init__()
        self.data = data[get_component_type(type(self))]
        if self.data is None:
            self.data = {}
        self.name = data.get('name')
        self.registry = registry


class JsonGenerator(ComponentBase):

    _copy_fields = set()

    def gen_json(self, context=Context()):
        return self.gen_json_from_data(context.expand_placeholders(self.data), context)

    def gen_json_from_data(self, data, 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


    def get_component(self, component_type, name):
        component = self._get_component(component_type).get(name)
        if component is None:
            raise errors.UnregisteredComponentError("No component '%s' with name '%s' found!" % (component_type, name))
        return component


class ComponentBase(object):
    def __init__(self, data, registry):
        """

        :type registry: ComponentRegistry
        """
        super(ComponentBase, self).__init__()
        self.data = data[get_component_type(type(self))]
        if self.data is None:
            self.data = {}
        self.name = data.get('name')
        self.registry = registry


class JsonGenerator(ComponentBase):

    _copy_fields = set()

    def gen_json(self, context=Context()):
        return self.gen_json_from_data(context.expand_placeholders(self.data), context)

    def gen_json_from_data(self, data, context):

        component_type = get_component_type(type(self))