# Path: achilles/common.py
# class BaseLibrary(object):
#     """
#     Base register library, provides decorator functions to register
#     items of any type.
# 
#     All items are registered using a name to uniquely identify them
# 
#     This register library is namespaced, so every new instance of it
#     gets registered under the given namespace. This will avoid
#     collisions between apps
#     """
#     namespace_separator = ':'
# 
#     def __init__(self, namespace):
#         # global namespaced register
#         if not hasattr(type(self), 'registers'):
#             type(self).registers = {}
# 
#         # Register the instanced library
#         if namespace in type(self).registers:
#             library = type(self).registers[namespace]
#             raise ValueError("An namespace with name "
#                              "'%s' is already registered in '%s'" %
#                              (namespace, library.__module__))
# 
#         type(self).registers[namespace] = self
#         self.namespace = namespace
#         self.items = {}
# 
#     def get(self, name):
#         if name not in self.items:
#             raise KeyError("'%s' item doesn't exists" % name)
#         return self.items[name]
# 
#     @classmethod
#     def get_global(cls, name):
#         if cls.namespace_separator in name:
#             namespace, name = name.split(cls.namespace_separator, 1)
#         else:
#             namespace = None
#         if namespace not in cls.registers:
#             raise KeyError("'%s' namespace doesn't exists. "
#                            "Avaible namespaces are: %s"
#                            % (namespace, cls.registers.keys()))
#         register = cls.registers[namespace]
#         try:
#             return register.get(name)
#         except KeyError:
#             raise KeyError("'%s' doesn't exists" % name)
# 
#     def register(self, name=None):
#         if name is None:
#             return self._register
#         elif callable(name):
#             func = name
#             name = getattr(name, '_decorated_function', name).__name__
#             return self._register(func, name)
#         else:
#             def dec(func):
#                 return self._register(func, name)
#             return dec
# 
#     def _register(self, func, name=None):
#         name = name or getattr(func, '_decorated_function', func).__name__
#         func.register_name = ':'.join([self.namespace or '', name])
#         self.items[name] = func
#         return func
# 
# Path: achilles/actions.py
# class Library(BaseLibrary):
#     """
#     Action library holds a register of all defined actions
# 
#     Use it to define and register new actions, grouping them under
#     a common namespace::
# 
#         from achilles import actions
# 
#         register = actions.Library('myapp')
# 
#         @register.action
#         def foo(transport, *args, **kwargs):
#             # do stuff
#             pass
# 
#     :param namespace: Unique namespace for this register
#     """
#     def __init__(self, namespace=None):
#         BaseLibrary.__init__(self, namespace)
# 
#         # Provide action register
#         self.action = self.register
# 
#     def _register(self, func, name=None):
#         def wrapper(transport, *args, **kwargs):
#             pre_action_call.send(sender=wrapper,
#                                  transport=transport,
#                                  args=args, kwargs=kwargs)
# 
#             result = func(transport, *args, **kwargs)
# 
#             post_action_call.send(sender=wrapper,
#                                   transport=transport,
#                                   args=args, kwargs=kwargs)
#             return result
# 
#         name = name or getattr(func, '_decorated_function', func).__name__
#         wrapper.register_name = ':'.join([self.namespace or '', name])
#         wrapper.__name__ = name
#         self.items[name] = wrapper
#         return wrapper


from django.conf import settings
from django.template import Context, RequestContext
from django.template.loader import get_template
from django.utils.log import getLogger
from inspect import isclass
from importlib import import_module
from achilles.common import BaseLibrary
from achilles.actions import Library as ActionsLibrary
            from importlib import find_loader
import sys
import six
import traceback
    def __init__(self, context):
        self.context = context or Context()

    def render(self, *args, **kwargs):
        """
        Render the block, this method receives block arguments (if any)
        and renders HTML result of the block.
        """
        t = get_template(self.template_name)
        return t.render(self.get_context_data(*args, **kwargs))

    def get_context_data(self, *args, **kwargs):
        """
        Returns context to be passed to the template renderer in
        :func:`render`.
        """
        return self.context

    def update(self, transport, *args, **kwargs):
        """
        Render and send the update of block within the given achilles transport
        """
        transport.data('blocks', []).append({
            'name': self.register_name,
            'args': args,
            'kwargs': kwargs,
            'data': self.render(*args, **kwargs),
        })



# Path: achilles/common.py
# class BaseLibrary(object):
#     """
#     Base register library, provides decorator functions to register
#     items of any type.
# 
#     All items are registered using a name to uniquely identify them
# 
#     This register library is namespaced, so every new instance of it
#     gets registered under the given namespace. This will avoid
#     collisions between apps
#     """
#     namespace_separator = ':'
# 
#     def __init__(self, namespace):
#         # global namespaced register
#         if not hasattr(type(self), 'registers'):
#             type(self).registers = {}
# 
#         # Register the instanced library
#         if namespace in type(self).registers:
#             library = type(self).registers[namespace]
#             raise ValueError("An namespace with name "
#                              "'%s' is already registered in '%s'" %
#                              (namespace, library.__module__))
# 
#         type(self).registers[namespace] = self
#         self.namespace = namespace
#         self.items = {}
# 
#     def get(self, name):
#         if name not in self.items:
#             raise KeyError("'%s' item doesn't exists" % name)
#         return self.items[name]
# 
#     @classmethod
#     def get_global(cls, name):
#         if cls.namespace_separator in name:
#             namespace, name = name.split(cls.namespace_separator, 1)
#         else:
#             namespace = None
#         if namespace not in cls.registers:
#             raise KeyError("'%s' namespace doesn't exists. "
#                            "Avaible namespaces are: %s"
#                            % (namespace, cls.registers.keys()))
#         register = cls.registers[namespace]
#         try:
#             return register.get(name)
#         except KeyError:
#             raise KeyError("'%s' doesn't exists" % name)
# 
#     def register(self, name=None):
#         if name is None:
#             return self._register
#         elif callable(name):
#             func = name
#             name = getattr(name, '_decorated_function', name).__name__
#             return self._register(func, name)
#         else:
#             def dec(func):
#                 return self._register(func, name)
#             return dec
# 
#     def _register(self, func, name=None):
#         name = name or getattr(func, '_decorated_function', func).__name__
#         func.register_name = ':'.join([self.namespace or '', name])
#         self.items[name] = func
#         return func
# 
# Path: achilles/actions.py
# class Library(BaseLibrary):
#     """
#     Action library holds a register of all defined actions
# 
#     Use it to define and register new actions, grouping them under
#     a common namespace::
# 
#         from achilles import actions
# 
#         register = actions.Library('myapp')
# 
#         @register.action
#         def foo(transport, *args, **kwargs):
#             # do stuff
#             pass
# 
#     :param namespace: Unique namespace for this register
#     """
#     def __init__(self, namespace=None):
#         BaseLibrary.__init__(self, namespace)
# 
#         # Provide action register
#         self.action = self.register
# 
#     def _register(self, func, name=None):
#         def wrapper(transport, *args, **kwargs):
#             pre_action_call.send(sender=wrapper,
#                                  transport=transport,
#                                  args=args, kwargs=kwargs)
# 
#             result = func(transport, *args, **kwargs)
# 
#             post_action_call.send(sender=wrapper,
#                                   transport=transport,
#                                   args=args, kwargs=kwargs)
#             return result
# 
#         name = name or getattr(func, '_decorated_function', func).__name__
#         wrapper.register_name = ':'.join([self.namespace or '', name])
#         wrapper.__name__ = name
#         self.items[name] = wrapper
#         return wrapper


# Path: achilles/blocks.py
from django.conf import settings
from django.template import Context, RequestContext
from django.template.loader import get_template
from django.utils.log import getLogger
from inspect import isclass
from importlib import import_module
from achilles.common import BaseLibrary
from achilles.actions import Library as ActionsLibrary
            from importlib import find_loader
import sys
import six
import traceback

    def __init__(self, context):
        self.context = context or Context()

    def render(self, *args, **kwargs):
        """
        Render the block, this method receives block arguments (if any)
        and renders HTML result of the block.
        """
        t = get_template(self.template_name)
        return t.render(self.get_context_data(*args, **kwargs))

    def get_context_data(self, *args, **kwargs):
        """
        Returns context to be passed to the template renderer in
        :func:`render`.
        """
        return self.context

    def update(self, transport, *args, **kwargs):
        """
        Render and send the update of block within the given achilles transport
        """
        transport.data('blocks', []).append({
            'name': self.register_name,
            'args': args,
            'kwargs': kwargs,
            'data': self.render(*args, **kwargs),
        })



register = ActionsLibrary('blocks')