# Path: cms/dbutil.py
# def get_mongodb(request):
# def get_collection(request, name):
# def get_gridfs(request, collection='fs'):
# def encode_keys(d):
# def get_es_conn(request):
# def get_es_index_name(request):
# def serve_gridfs_file(file):
# def serve_gridfs_file_for_id(request, id, collection='fs'):
# 
# Path: cms/diffutil.py
# def pretty_text_diff(text1, text2):
#     def startInsertText(self):
#     def endInsertText(self):
#     def startDeleteText(self):
#     def endDeleteText(self):
# def pretty_html_diff(html1, html2):
# def flatten_dictionary(d, prefix=''):
# def _flatten_list(l, prefix=''):
# def unflatten_dictionary(fd):
# def diff_flattened_dictionaries(fd1, fd2):
# def patch_flattened_dictionary(fd, patch):
# def diff_dictionaries(d1, d2):
# def patch_dictionary(d, patch):
# def patch_dictionary_multi(d, patches):
# def get_patch_keys(patch, top_level_only=False):
# class MyHTMLMatcher(htmldiff.NoTagHTMLMatcher):
# 
# Path: cms/htmlutil.py
# def sniff_html(s):
#     def __init__(self, formatter, show_link_urls=1, skip_tags=[], unknown_entity_replacement=None):
#     def handle_starttag(self, tag, method, attrs):
#     def handle_endtag(self, tag, method):
#     def unknown_starttag(self, tag, attrs):
#     def unknown_endtag(self, tag):
#     def handle_data(self, data):
#     def handle_charref(self, ref):
#     def handle_entityref(self, ref):
# def html_to_text(html, show_link_urls=1, skip_tags=[], unknown_entity_replacement=None):
# def main():
# class HTML_to_text_parser(htmllib.HTMLParser):
# SELF_CLOSING_FIX_RE = re.compile(r'(\S)/>')
# 
# Path: cms/dateutil.py
# def utcnow(zero_seconds=False):
#     """ Returns a timezone aware version of utcnow.
#     If zero_seconds, the datetime will be rounded down to the minute.
#     """
#     now = datetime.datetime.now(pytz.utc)
#     if zero_seconds: return now.replace(second=0, microsecond=0)
#     return now


from cms import dbutil, diffutil, htmlutil
from cms.dateutil import utcnow
from pyramid.security import authenticated_userid
from cms.thirdparty import diff_match_patch
#        time a special differ was used that ignores html markup.
#
#        Practically speaking, if there's an "htmldiff" key in the result, it means that the before
#        and after values contain HTML; the "htmldiff" shows differences in the rendered html,
#        while "diff" shows differences in the source html.
        """
        if (history_id1 == history_id2) and after_earlier_event: return {}  # Nothing could have changed in this case.
        after = before = None
        history_ids = [history_id1]
        if history_id2:
            history_ids.append(history_id2)
        else:
            after = obj.get_schema_values()
        patches = []
        for history in self.get_history_for_id(obj._id)['items']:
            if history['_id'] in history_ids:
                if after:
                    if after_earlier_event:
                        before = diffutil.patch_dictionary_multi(after, patches)
                        return diff_dictionaries(before, after)
                else:
                    after = diffutil.patch_dictionary_multi(obj.get_schema_values(), patches)
                    patches = []

            if history['action'] in ('edit', 'revert'):
                patch = history['changes']
                if patch: patches.append(patch)

            if history['_id'] in history_ids:
                if after and not after_earlier_event:

# Path: cms/dbutil.py
# def get_mongodb(request):
# def get_collection(request, name):
# def get_gridfs(request, collection='fs'):
# def encode_keys(d):
# def get_es_conn(request):
# def get_es_index_name(request):
# def serve_gridfs_file(file):
# def serve_gridfs_file_for_id(request, id, collection='fs'):
# 
# Path: cms/diffutil.py
# def pretty_text_diff(text1, text2):
#     def startInsertText(self):
#     def endInsertText(self):
#     def startDeleteText(self):
#     def endDeleteText(self):
# def pretty_html_diff(html1, html2):
# def flatten_dictionary(d, prefix=''):
# def _flatten_list(l, prefix=''):
# def unflatten_dictionary(fd):
# def diff_flattened_dictionaries(fd1, fd2):
# def patch_flattened_dictionary(fd, patch):
# def diff_dictionaries(d1, d2):
# def patch_dictionary(d, patch):
# def patch_dictionary_multi(d, patches):
# def get_patch_keys(patch, top_level_only=False):
# class MyHTMLMatcher(htmldiff.NoTagHTMLMatcher):
# 
# Path: cms/htmlutil.py
# def sniff_html(s):
#     def __init__(self, formatter, show_link_urls=1, skip_tags=[], unknown_entity_replacement=None):
#     def handle_starttag(self, tag, method, attrs):
#     def handle_endtag(self, tag, method):
#     def unknown_starttag(self, tag, attrs):
#     def unknown_endtag(self, tag):
#     def handle_data(self, data):
#     def handle_charref(self, ref):
#     def handle_entityref(self, ref):
# def html_to_text(html, show_link_urls=1, skip_tags=[], unknown_entity_replacement=None):
# def main():
# class HTML_to_text_parser(htmllib.HTMLParser):
# SELF_CLOSING_FIX_RE = re.compile(r'(\S)/>')
# 
# Path: cms/dateutil.py
# def utcnow(zero_seconds=False):
#     """ Returns a timezone aware version of utcnow.
#     If zero_seconds, the datetime will be rounded down to the minute.
#     """
#     now = datetime.datetime.now(pytz.utc)
#     if zero_seconds: return now.replace(second=0, microsecond=0)
#     return now


# Path: cms/resources/history.py
from cms import dbutil, diffutil, htmlutil
from cms.dateutil import utcnow
from pyramid.security import authenticated_userid
from cms.thirdparty import diff_match_patch

#        time a special differ was used that ignores html markup.
#
#        Practically speaking, if there's an "htmldiff" key in the result, it means that the before
#        and after values contain HTML; the "htmldiff" shows differences in the rendered html,
#        while "diff" shows differences in the source html.
        """
        if (history_id1 == history_id2) and after_earlier_event: return {}  # Nothing could have changed in this case.
        after = before = None
        history_ids = [history_id1]
        if history_id2:
            history_ids.append(history_id2)
        else:
            after = obj.get_schema_values()
        patches = []
        for history in self.get_history_for_id(obj._id)['items']:
            if history['_id'] in history_ids:
                if after:
                    if after_earlier_event:
                        before = diffutil.patch_dictionary_multi(after, patches)
                        return diff_dictionaries(before, after)
                else:
                    after = diffutil.patch_dictionary_multi(obj.get_schema_values(), patches)
                    patches = []

            if history['action'] in ('edit', 'revert'):
                patch = history['changes']
                if patch: patches.append(patch)

            if history['_id'] in history_ids:
                if after and not after_earlier_event:

                    before = diffutil.patch_dictionary_multi(after, patches)