# Path: smartsnippets/resources_processor.py
# def get_resources(resources_data):
#     """
#         Parses resources_data to get all resources defined with
#     the following format:
#         snippet-field/custom.html, static: admin/style.css,
#             http://somesite/absolute-url.js
#     and returns a dictionary with resources extensions and the links defined.
#     """
#     if not resources_data:
#         return {}
#     resources_data = resources_data or ''
#     resources = defaultdict(list)
#     for resource in resources_data.split(','):
#         processed_link = _process(resource)
#         if not processed_link:
#             continue
#         links = resources[processed_link[0]]
#         res_link = processed_link[1]
#         # check if already added. Note: using list and not set just to
#         #   make sure the ordering is kept
#         if res_link not in links:
#             links.append(processed_link[1])
#     return resources
# 
# Path: smartsnippets/settings.py
# def _has_data_defined(widget_data):
# USE_BOOTSTRAP_ACE = getattr(
#     settings, 'SMARTSNIPPETS_USE_BOOTSTRAP_ACE', False)


import re
import logging
from django.core.cache import cache
from django.db import models
from django.core.exceptions import ValidationError
from django.template import Template, TemplateSyntaxError, \
    TemplateDoesNotExist, loader, VariableDoesNotExist
from django.template.loader import render_to_string
from django.db.models import signals
from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import python_2_unicode_compatible
from cms.models import CMSPlugin
from sekizai.helpers import (
    Watcher as sekizai_context_watcher,
    get_varname as sekizai_cache_key,
)
from .resources_processor import get_resources
from .settings import (
    snippet_caching_time, caching_enabled, allow_inheritance,
    inherit_variable_pattern)
        from widgets_pool import widget_pool
    class Meta:
        db_table = 'cmsplugin_smartsnippetpointer'

    def get_cache_key(self):
        return self.cache_key_format.format(primary_key=self.pk)

    def _do_restore_sekizai_context(self, context, changes):
        """Sekizai tags involve magic with the context object.
        When need to restore the sekizai content to the context"""
        cache_key = sekizai_cache_key()
        sekizai_container = context.get(cache_key)
        for key, values in changes.items():
            sekizai_namespace = sekizai_container[key]
            for value in values:
                sekizai_namespace.append(value)

    def fetch_cached(self, context):
        cache_key = self.get_cache_key()
        user = context['request'].user
        if not user.is_staff and caching_enabled and cache.has_key(cache_key):
            cached_value = cache.get(cache_key)
            rendered_content = cached_value.get('content')
            sekizai = cached_value.get('sekizai')
            self._do_restore_sekizai_context(context, sekizai)
            return rendered_content

    def set_and_get_cache(self, user, sekizai_diff, content):
        if not user.is_staff and caching_enabled:
            value = {'content': content, 'sekizai': sekizai_diff}
            key = self.get_cache_key()

# Path: smartsnippets/resources_processor.py
# def get_resources(resources_data):
#     """
#         Parses resources_data to get all resources defined with
#     the following format:
#         snippet-field/custom.html, static: admin/style.css,
#             http://somesite/absolute-url.js
#     and returns a dictionary with resources extensions and the links defined.
#     """
#     if not resources_data:
#         return {}
#     resources_data = resources_data or ''
#     resources = defaultdict(list)
#     for resource in resources_data.split(','):
#         processed_link = _process(resource)
#         if not processed_link:
#             continue
#         links = resources[processed_link[0]]
#         res_link = processed_link[1]
#         # check if already added. Note: using list and not set just to
#         #   make sure the ordering is kept
#         if res_link not in links:
#             links.append(processed_link[1])
#     return resources
# 
# Path: smartsnippets/settings.py
# def _has_data_defined(widget_data):
# USE_BOOTSTRAP_ACE = getattr(
#     settings, 'SMARTSNIPPETS_USE_BOOTSTRAP_ACE', False)


# Path: smartsnippets/models.py
import re
import logging
from django.core.cache import cache
from django.db import models
from django.core.exceptions import ValidationError
from django.template import Template, TemplateSyntaxError, \
    TemplateDoesNotExist, loader, VariableDoesNotExist
from django.template.loader import render_to_string
from django.db.models import signals
from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import python_2_unicode_compatible
from cms.models import CMSPlugin
from sekizai.helpers import (
    Watcher as sekizai_context_watcher,
    get_varname as sekizai_cache_key,
)
from .resources_processor import get_resources
from .settings import (
    snippet_caching_time, caching_enabled, allow_inheritance,
    inherit_variable_pattern)
        from widgets_pool import widget_pool

    class Meta:
        db_table = 'cmsplugin_smartsnippetpointer'

    def get_cache_key(self):
        return self.cache_key_format.format(primary_key=self.pk)

    def _do_restore_sekizai_context(self, context, changes):
        """Sekizai tags involve magic with the context object.
        When need to restore the sekizai content to the context"""
        cache_key = sekizai_cache_key()
        sekizai_container = context.get(cache_key)
        for key, values in changes.items():
            sekizai_namespace = sekizai_container[key]
            for value in values:
                sekizai_namespace.append(value)

    def fetch_cached(self, context):
        cache_key = self.get_cache_key()
        user = context['request'].user
        if not user.is_staff and caching_enabled and cache.has_key(cache_key):
            cached_value = cache.get(cache_key)
            rendered_content = cached_value.get('content')
            sekizai = cached_value.get('sekizai')
            self._do_restore_sekizai_context(context, sekizai)
            return rendered_content

    def set_and_get_cache(self, user, sekizai_diff, content):
        if not user.is_staff and caching_enabled:
            value = {'content': content, 'sekizai': sekizai_diff}
            key = self.get_cache_key()

            cache.set(key, value, snippet_caching_time)