# 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
            user = authenticated_userid(self.request),
            action = action,
            ids = ids,
        )
        doc.update(**kwargs)
        self._get_collection().save(doc, safe=True)

    def get_history(self, spec=None, sort=None, skip=0, limit=0):
        cursor = self._get_collection().find(spec=spec, sort=sort, skip=skip, limit=limit)
        total = cursor.count()
        return dict(total=total, items=list(cursor))

    def get_history_for_id(self, _id, skip=0, limit=20):
        return self.get_history(spec={'ids':_id}, sort=[('time', -1)], skip=skip, limit=limit)

    def get_history_for_user(self, username, skip=0, limit=20):
        return self.get_history(spec={'user':username}, sort=[('time', -1)], skip=skip, limit=limit)

    def get_history_item(self, _id):
        return self._get_collection().find_one(dict(_id=_id))

    def apply_history(self, obj, history_id):
        """ Given a content object and the _id of a history record, apply
        changes from the edit history such that the object has the schema
        values it had just after the specified history event.
        Note that this method modifies the content object in place.
        """
        patches = []
        for history in self.get_history_for_id(obj._id)['items']:
            if history['_id'] == history_id:

# 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

            user = authenticated_userid(self.request),
            action = action,
            ids = ids,
        )
        doc.update(**kwargs)
        self._get_collection().save(doc, safe=True)

    def get_history(self, spec=None, sort=None, skip=0, limit=0):
        cursor = self._get_collection().find(spec=spec, sort=sort, skip=skip, limit=limit)
        total = cursor.count()
        return dict(total=total, items=list(cursor))

    def get_history_for_id(self, _id, skip=0, limit=20):
        return self.get_history(spec={'ids':_id}, sort=[('time', -1)], skip=skip, limit=limit)

    def get_history_for_user(self, username, skip=0, limit=20):
        return self.get_history(spec={'user':username}, sort=[('time', -1)], skip=skip, limit=limit)

    def get_history_item(self, _id):
        return self._get_collection().find_one(dict(_id=_id))

    def apply_history(self, obj, history_id):
        """ Given a content object and the _id of a history record, apply
        changes from the edit history such that the object has the schema
        values it had just after the specified history event.
        Note that this method modifies the content object in place.
        """
        patches = []
        for history in self.get_history_for_id(obj._id)['items']:
            if history['_id'] == history_id:

                data = diffutil.patch_dictionary_multi(obj.get_schema_values(), patches)