# Path: ebu_tt_live/config/common.py
# class ConfigurableComponent(RequiredConfig):
# 
#     required_config = Namespace()
# 
#     config = None
#     component = None  # To store the component itself inside its configurator
#     _backend = None  # Static variable holding the backend
# 
#     def __init__(self, config, local_config, backend=None):
#         self.config = local_config
# 
#         if backend is not None:
#             if self.backend is not None:
#                 raise ConfigurationError(
#                     ERR_CONF_ONE_BACKEND_ONLY.format(
#                         backend1=self.backend,
#                         backend2=backend
#                     )
#                 )
#             else:
#                 ConfigurableComponent._backend = backend
#         elif self.backend is not None:
#             # Register configurator instance
#             self.backend.register_configurator(self)
# 
#     @property
#     def backend(self):
#         return ConfigurableComponent._backend
# 
#     @classmethod
#     def configure_component(cls, config, local_config, **kwargs):
#         """
#         This is a class method to either return an instance that already exists or create one.
#         :param config:
#         :param local_config:
#         :param kwargs: Extra parameters
#         :return: Instance of ConfigurableComponent
#         """
#         return cls(config=config, local_config=local_config)
# 
#     @classmethod
#     def _resolve_runtime_variable_match(cls, matchobj):
#         # Give this function to re.sub to do the replacement for you
#         var_loc = matchobj.group(0).replace(u'**', u'')
#         var_loc = var_loc.split(u'.')
#         node_id, attr_names = var_loc[0], var_loc[1:]
#         node = current_app.get_node(node_id)
#         result = node
#         for attr_name in attr_names:
#             temp_result = getattr(result, attr_name)
#             result = temp_result
# 
#         if not isinstance(result, six.text_type):
#             result = six.text_type(result)
#         return result
# 
#     @classmethod
#     def resolve_runtime_variables(cls, str_parameter):
#         return runtime_template_regex.sub(
#             repl=cls._resolve_runtime_variable_match,
#             string=str_parameter
#         )
# 
#     def start(self):
#         pass
# 
#     def stop(self):
#         pass
# 
# Path: ebu_tt_live/adapters/document_data.py
# class XMLtoEBUTT3Adapter(IDocumentDataAdapter):
# class XMLtoEBUTTDAdapter(IDocumentDataAdapter):
# class EBUTTDtoXMLAdapter(IDocumentDataAdapter):
# class EBUTT3toXMLAdapter(IDocumentDataAdapter):
# class EBUTT3toEBUTTDAdapter(IDocumentDataAdapter):
#     def convert_data(self, data, availability_time=None, sequence_identifier=None, **kwargs):
#     def convert_data(self, data, **kwargs):
#     def convert_data(self, data, **kwargs):
#     def convert_data(self, data, **kwargs):
#     def __init__(self, media_clock=None):
#     def convert_data(self, data, **kwargs):
# def get_document_data_adapter(expects, provides):


from .common import ConfigurableComponent
from ebu_tt_live.adapters import document_data, node_carriage
    'xml->ebuttd': document_data.XMLtoEBUTTDAdapter,
    'ebutt3->xml': document_data.EBUTT3toXMLAdapter,
    'ebuttd->xml': document_data.EBUTTDtoXMLAdapter
}


def parse_adapter_list(value):
    # This is working around a bug that configman leaves the lists intact
    parsed_value = []
    if value is not None:
        for item in value:
            conv_type = item['type']
            kwargs = {ckey: carg for ckey, carg in item.items() if ckey != 'type'}
            parsed_value.append(data_adapters_by_directed_conversion.get(conv_type)(**kwargs))
    return parsed_value or None


class ProducerNodeCarriageAdapter(ConfigurableComponent):

    @classmethod
    def configure_component(cls, config, local_config, producer=None, carriage=None, **kwargs):
        instance = cls(config=config, local_config=local_config)
        adapter_list = parse_adapter_list(local_config)
        instance.component = node_carriage.ProducerNodeCarriageAdapter(
            producer_carriage=carriage,
            producer_node=producer,
            data_adapters=adapter_list
        )



# Path: ebu_tt_live/config/common.py
# class ConfigurableComponent(RequiredConfig):
# 
#     required_config = Namespace()
# 
#     config = None
#     component = None  # To store the component itself inside its configurator
#     _backend = None  # Static variable holding the backend
# 
#     def __init__(self, config, local_config, backend=None):
#         self.config = local_config
# 
#         if backend is not None:
#             if self.backend is not None:
#                 raise ConfigurationError(
#                     ERR_CONF_ONE_BACKEND_ONLY.format(
#                         backend1=self.backend,
#                         backend2=backend
#                     )
#                 )
#             else:
#                 ConfigurableComponent._backend = backend
#         elif self.backend is not None:
#             # Register configurator instance
#             self.backend.register_configurator(self)
# 
#     @property
#     def backend(self):
#         return ConfigurableComponent._backend
# 
#     @classmethod
#     def configure_component(cls, config, local_config, **kwargs):
#         """
#         This is a class method to either return an instance that already exists or create one.
#         :param config:
#         :param local_config:
#         :param kwargs: Extra parameters
#         :return: Instance of ConfigurableComponent
#         """
#         return cls(config=config, local_config=local_config)
# 
#     @classmethod
#     def _resolve_runtime_variable_match(cls, matchobj):
#         # Give this function to re.sub to do the replacement for you
#         var_loc = matchobj.group(0).replace(u'**', u'')
#         var_loc = var_loc.split(u'.')
#         node_id, attr_names = var_loc[0], var_loc[1:]
#         node = current_app.get_node(node_id)
#         result = node
#         for attr_name in attr_names:
#             temp_result = getattr(result, attr_name)
#             result = temp_result
# 
#         if not isinstance(result, six.text_type):
#             result = six.text_type(result)
#         return result
# 
#     @classmethod
#     def resolve_runtime_variables(cls, str_parameter):
#         return runtime_template_regex.sub(
#             repl=cls._resolve_runtime_variable_match,
#             string=str_parameter
#         )
# 
#     def start(self):
#         pass
# 
#     def stop(self):
#         pass
# 
# Path: ebu_tt_live/adapters/document_data.py
# class XMLtoEBUTT3Adapter(IDocumentDataAdapter):
# class XMLtoEBUTTDAdapter(IDocumentDataAdapter):
# class EBUTTDtoXMLAdapter(IDocumentDataAdapter):
# class EBUTT3toXMLAdapter(IDocumentDataAdapter):
# class EBUTT3toEBUTTDAdapter(IDocumentDataAdapter):
#     def convert_data(self, data, availability_time=None, sequence_identifier=None, **kwargs):
#     def convert_data(self, data, **kwargs):
#     def convert_data(self, data, **kwargs):
#     def convert_data(self, data, **kwargs):
#     def __init__(self, media_clock=None):
#     def convert_data(self, data, **kwargs):
# def get_document_data_adapter(expects, provides):


# Path: ebu_tt_live/config/adapters.py
from .common import ConfigurableComponent
from ebu_tt_live.adapters import document_data, node_carriage

    'xml->ebuttd': document_data.XMLtoEBUTTDAdapter,
    'ebutt3->xml': document_data.EBUTT3toXMLAdapter,
    'ebuttd->xml': document_data.EBUTTDtoXMLAdapter
}


def parse_adapter_list(value):
    # This is working around a bug that configman leaves the lists intact
    parsed_value = []
    if value is not None:
        for item in value:
            conv_type = item['type']
            kwargs = {ckey: carg for ckey, carg in item.items() if ckey != 'type'}
            parsed_value.append(data_adapters_by_directed_conversion.get(conv_type)(**kwargs))
    return parsed_value or None


class ProducerNodeCarriageAdapter(ConfigurableComponent):

    @classmethod
    def configure_component(cls, config, local_config, producer=None, carriage=None, **kwargs):
        instance = cls(config=config, local_config=local_config)
        adapter_list = parse_adapter_list(local_config)
        instance.component = node_carriage.ProducerNodeCarriageAdapter(
            producer_carriage=carriage,
            producer_node=producer,
            data_adapters=adapter_list
        )



class ConsumerNodeCarriageAdapter(ConfigurableComponent):