# Path: html5_appcache/settings.py
# DJANGOCMS_2_3 = LooseVersion(cms.__version__) < LooseVersion('2.4')
# 
# def get_setting(key):
#     local_settings = {
#         'DISABLE': getattr(settings, "HTML5_APPCACHE_DISABLE", False),
#         'ADD_WILDCARD': getattr(settings, "HTML5_APPCACHE_ADD_WILDCARD", True),
#         'CACHE_KEY': getattr(settings, "HTML5_APPCACHE_CACHE_KEY", "html5_appcache"),
#         'CACHE_DURATION': getattr(settings, "HTML5_APPCACHE_CACHE_DURATION", 86400),
#         'USE_SITEMAP': getattr(settings, "HTML5_APPCACHE_USE_SITEMAP", True),
#         'DISCARD_EXTERNAL': getattr(settings, "HTML5_APPCACHE_DISCARD_EXTERNAL", True),
#         'SITEMAP_URL': getattr(settings, "HTML5_APPCACHE_SITEMAP_URL", "/sitemap.xml"),
#         'CACHED_URL': getattr(settings, "HTML5_APPCACHE_CACHED_URL", []),
#         'EXCLUDE_URL': getattr(settings, "HTML5_APPCACHE_EXCLUDE_URL", []),
#         'NETWORK_URL': getattr(settings, "HTML5_APPCACHE_NETWORK_URL", []),
#         'FALLBACK_URL': getattr(settings, "HTML5_APPCACHE_FALLBACK_URL", {}),
#         'OVERRIDE_URLCONF': getattr(settings, "HTML5_APPCACHE_OVERRIDE_URLCONF", False),
#         'OVERRIDDEN_URLCONF': getattr(settings, "HTML5_APPCACHE_OVERRIDDEN_URLCONF", False),
#         'DJANGOCMS_2_3': getattr(settings, "HTML5_APPCACHE_DJANGOCMS_2_3", DJANGOCMS_2_3),
#         'DJANGOCMS': getattr(settings, "HTML5_APPCACHE_DJANGOCMS", DJANGOCMS),
#     }
#     return local_settings[key]
# 
# DJANGO_1_4 = (LooseVersion('1.5') > LooseVersion(django.get_version()) >= LooseVersion('1.4'))
# 
# Path: html5_appcache/cache.py
# def get_cached_value(key, version=None):
#     from django.core.cache import cache
#     if not version:
#         version = get_cache_version()
#     return cache.get(get_cache_key(key), version=version)
# 
# def set_cached_value(key, value, version=1):
#     from django.core.cache import cache
#     return cache.set(get_cache_key(key), value, get_setting('CACHE_DURATION'),
#                      version=version)
# 
# def is_manifest_clean():
#     """
#     Signals if the cache is
#     """
#     return get_cache_version() == 1
# 
# def reset_cache_manifest():
#     """
#     Move to version 2 (meaning stale data).
#     """
#     set_cached_value("data_clean", 2)
# 
# def set_cached_manifest(manifest):
#     """
#     When setting new manifest, both versions are updated.
#     """
#     set_cached_value("data_clean", 1)
#     set_cached_value("manifest", manifest, 1)
#     set_cached_value("manifest", manifest, 2)
# 
# def get_cached_manifest():
#     return get_cached_value("manifest")
# 
# Path: html5_appcache/utils.py
# def is_external_url(url, request=None):
#     """
#     Check if a protocol is declared and SERVER_NAME differs from the domain in
#     the URL
#     """
#     path = urlparse(url)
#     ext_server = True
#     if request:
#         ext_server = (
#             "%s:%s" % (request.META['SERVER_NAME'], request.META['SERVER_PORT']) !=
#             path.netloc
#         )
#     return len(path.scheme) != 0 and ext_server


import string
import time
from datetime import datetime
from lxml import etree
from lxml.html import document_fromstring
from django.template import RequestContext
from django.template.loader import render_to_string
from html5_appcache.settings import DJANGOCMS_2_3, get_setting, DJANGO_1_4
from html5_appcache.cache import (get_cached_value, set_cached_value,
                                  is_manifest_clean, reset_cache_manifest,
                                  set_cached_manifest, get_cached_manifest)
from html5_appcache.utils import is_external_url
        from django.db.models.signals import post_save, post_delete
        from django.contrib.sites.models import get_current_site
        from django.test import Client
        from django.test import Client
    def add_appcache(self, appcache):
        """
        Adds the externally retrieved urls to the internal set.

        `appcache` is a dictionary with `cached`, `network`, `fallback` keys
        """
        self._external_appcaches.update(appcache)

    def _get_sitemap(self):
        """
        Pretty ugly method that fetches the current sitemap and parses it to
        retrieve the list of available urls
        """

        def walk_sitemap(urlset, doc):
            """
            Nested function for convenience. Recursively scans the sitemap to
            retrieve the urls
            """
            if isinstance(doc.tag, basestring):
                tag = etree.QName(doc.tag)
                if tag.localname == "loc":
                    urlset.append(doc.text)
            for node in doc:
                urlset = walk_sitemap(urlset, node)
            return urlset
        req_protocol = 'https' if self.request.is_secure() else 'http'
        req_site = get_current_site(self.request)
        client = Client()
        path = get_setting('SITEMAP_URL')

# Path: html5_appcache/settings.py
# DJANGOCMS_2_3 = LooseVersion(cms.__version__) < LooseVersion('2.4')
# 
# def get_setting(key):
#     local_settings = {
#         'DISABLE': getattr(settings, "HTML5_APPCACHE_DISABLE", False),
#         'ADD_WILDCARD': getattr(settings, "HTML5_APPCACHE_ADD_WILDCARD", True),
#         'CACHE_KEY': getattr(settings, "HTML5_APPCACHE_CACHE_KEY", "html5_appcache"),
#         'CACHE_DURATION': getattr(settings, "HTML5_APPCACHE_CACHE_DURATION", 86400),
#         'USE_SITEMAP': getattr(settings, "HTML5_APPCACHE_USE_SITEMAP", True),
#         'DISCARD_EXTERNAL': getattr(settings, "HTML5_APPCACHE_DISCARD_EXTERNAL", True),
#         'SITEMAP_URL': getattr(settings, "HTML5_APPCACHE_SITEMAP_URL", "/sitemap.xml"),
#         'CACHED_URL': getattr(settings, "HTML5_APPCACHE_CACHED_URL", []),
#         'EXCLUDE_URL': getattr(settings, "HTML5_APPCACHE_EXCLUDE_URL", []),
#         'NETWORK_URL': getattr(settings, "HTML5_APPCACHE_NETWORK_URL", []),
#         'FALLBACK_URL': getattr(settings, "HTML5_APPCACHE_FALLBACK_URL", {}),
#         'OVERRIDE_URLCONF': getattr(settings, "HTML5_APPCACHE_OVERRIDE_URLCONF", False),
#         'OVERRIDDEN_URLCONF': getattr(settings, "HTML5_APPCACHE_OVERRIDDEN_URLCONF", False),
#         'DJANGOCMS_2_3': getattr(settings, "HTML5_APPCACHE_DJANGOCMS_2_3", DJANGOCMS_2_3),
#         'DJANGOCMS': getattr(settings, "HTML5_APPCACHE_DJANGOCMS", DJANGOCMS),
#     }
#     return local_settings[key]
# 
# DJANGO_1_4 = (LooseVersion('1.5') > LooseVersion(django.get_version()) >= LooseVersion('1.4'))
# 
# Path: html5_appcache/cache.py
# def get_cached_value(key, version=None):
#     from django.core.cache import cache
#     if not version:
#         version = get_cache_version()
#     return cache.get(get_cache_key(key), version=version)
# 
# def set_cached_value(key, value, version=1):
#     from django.core.cache import cache
#     return cache.set(get_cache_key(key), value, get_setting('CACHE_DURATION'),
#                      version=version)
# 
# def is_manifest_clean():
#     """
#     Signals if the cache is
#     """
#     return get_cache_version() == 1
# 
# def reset_cache_manifest():
#     """
#     Move to version 2 (meaning stale data).
#     """
#     set_cached_value("data_clean", 2)
# 
# def set_cached_manifest(manifest):
#     """
#     When setting new manifest, both versions are updated.
#     """
#     set_cached_value("data_clean", 1)
#     set_cached_value("manifest", manifest, 1)
#     set_cached_value("manifest", manifest, 2)
# 
# def get_cached_manifest():
#     return get_cached_value("manifest")
# 
# Path: html5_appcache/utils.py
# def is_external_url(url, request=None):
#     """
#     Check if a protocol is declared and SERVER_NAME differs from the domain in
#     the URL
#     """
#     path = urlparse(url)
#     ext_server = True
#     if request:
#         ext_server = (
#             "%s:%s" % (request.META['SERVER_NAME'], request.META['SERVER_PORT']) !=
#             path.netloc
#         )
#     return len(path.scheme) != 0 and ext_server


# Path: html5_appcache/appcache_base.py
import string
import time
from datetime import datetime
from lxml import etree
from lxml.html import document_fromstring
from django.template import RequestContext
from django.template.loader import render_to_string
from html5_appcache.settings import DJANGOCMS_2_3, get_setting, DJANGO_1_4
from html5_appcache.cache import (get_cached_value, set_cached_value,
                                  is_manifest_clean, reset_cache_manifest,
                                  set_cached_manifest, get_cached_manifest)
from html5_appcache.utils import is_external_url
        from django.db.models.signals import post_save, post_delete
        from django.contrib.sites.models import get_current_site
        from django.test import Client
        from django.test import Client

    def add_appcache(self, appcache):
        """
        Adds the externally retrieved urls to the internal set.

        `appcache` is a dictionary with `cached`, `network`, `fallback` keys
        """
        self._external_appcaches.update(appcache)

    def _get_sitemap(self):
        """
        Pretty ugly method that fetches the current sitemap and parses it to
        retrieve the list of available urls
        """

        def walk_sitemap(urlset, doc):
            """
            Nested function for convenience. Recursively scans the sitemap to
            retrieve the urls
            """
            if isinstance(doc.tag, basestring):
                tag = etree.QName(doc.tag)
                if tag.localname == "loc":
                    urlset.append(doc.text)
            for node in doc:
                urlset = walk_sitemap(urlset, node)
            return urlset
        req_protocol = 'https' if self.request.is_secure() else 'http'
        req_site = get_current_site(self.request)
        client = Client()
        path = get_setting('SITEMAP_URL')

        if DJANGO_1_4 and not DJANGOCMS_2_3: