<commit_before># Copyright (c) 2007 gocept gmbh & co. kg
# See also LICENSE.txt
# $Id$

import StringIO
import datetime
import logging

import persistent
import transaction

import zope.annotation.interfaces
import zope.cachedescriptors.property
import zope.cachedescriptors.method
import zope.interface

import zope.app.container.contained

import zeit.cms.interfaces
import zeit.cms.repository.interfaces


logger = logging.getLogger('zeit.cms.repository')


class Container(zope.app.container.contained.Contained):
    """The container represents webdav collections."""

    zope.interface.implements(zeit.cms.repository.interfaces.ICollection)

    def __init__(self, uniqueId=None, __name__=None):
        self.uniqueId = uniqueId
        self.__name__ = __name__

    # Container interface

    def keys(self):
        """The keys are the filenames."""
        return sorted(self._local_unique_map.keys())

    def __iter__(self):
        '''See interface `IReadContainer`'''
        return iter(self.keys())

    def __getitem__(self, key):
        '''See interface `IReadContainer`'''
        unique_id = self._local_unique_map[key]
        __traceback_info__ = (key, unique_id)
        content = self.repository.getUncontainedContent(unique_id)
        zope.interface.directlyProvides(
            content, zeit.cms.repository.interfaces.IRepositoryContent)
        return zope.app.container.contained.contained(
            content, self, content.__name__)

    def get(self, key, default=None):
        '''See interface `IReadContainer`'''
        try:
            return self[key]
        except KeyError:
            return default

    def values(self):
        '''See interface `IReadContainer`'''
        for key in self.keys():
            yield self[key]

    def __len__(self):
        '''See interface `IReadContainer`'''
        return len(self._local_unique_map)
<commit_msg>not looking up the unique_id but computing it should result in better performance<commit_after># Copyright (c) 2007 gocept gmbh & co. kg
# See also LICENSE.txt
# $Id$

import StringIO
import datetime
import logging

import persistent
import transaction

import zope.annotation.interfaces
import zope.cachedescriptors.property
import zope.cachedescriptors.method
import zope.interface

import zope.app.container.contained

import zeit.cms.interfaces
import zeit.cms.repository.interfaces


logger = logging.getLogger('zeit.cms.repository')


class Container(zope.app.container.contained.Contained):
    """The container represents webdav collections."""

    zope.interface.implements(zeit.cms.repository.interfaces.ICollection)

    def __init__(self, uniqueId=None, __name__=None):
        self.uniqueId = uniqueId
        self.__name__ = __name__

    # Container interface

    def keys(self):
        """The keys are the filenames."""
        return sorted(self._local_unique_map.keys())

    def __iter__(self):
        '''See interface `IReadContainer`'''
        return iter(self.keys())

    def __getitem__(self, key):
        '''See interface `IReadContainer`'''
        unique_id = self._get_id_for_name(key)
        __traceback_info__ = (key, unique_id)
        content = self.repository.getUncontainedContent(unique_id)
        zope.interface.directlyProvides(
            content, zeit.cms.repository.interfaces.IRepositoryContent)
        return zope.app.container.contained.contained(
            content, self, content.__name__)

    def get(self, key, default=None):
        '''See interface `IReadContainer`'''
        try:
            return self[key]
        except KeyError:
            return default

    def values(self):
        '''See interface `IReadContainer`'''
        for key in self.keys():
            yield self[key]

    def __len__(self):
        '''See interface `IReadContainer`'''
        return len(self._local_unique_map)

{'fraction_non_alphanumeric': 0.10049210049210049, 'fraction_numerical': 0.002072002072002072, 'mean_word_length': 3.1571582346609257, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2122731', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1076, 'n_words': 262}