<commit_before>##
# Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# DRI: <NAME>, <EMAIL>
##

"""
Apache UserFile/GroupFile compatible directory service implementation.
"""

__all__ = [
    "BasicDirectoryService",
    "DigestDirectoryService",
]

from crypt import crypt

from twisted.python.filepath import FilePath
from twisted.cred.credentials import UsernamePassword

from twistedcaldav.directory.directory import DirectoryService, DirectoryRecord
from twistedcaldav.directory.directory import UnknownRecordTypeError

class AbstractDirectoryService(DirectoryService):
    """
    Abstract Apache-compatible implementation of L{IDirectoryService}.
    """
    def __repr__(self):
        return "<%s %r: %r %r>" % (self.__class__.__name__, realmName, self.userFile, self.groupFile)

    def __init__(self, realmName, userFile, groupFile=None):
        super(AbstractDirectoryService, self).__init__()

        if type(userFile) is str:
            userFile = FilePath(userFile)
        if type(groupFile) is str:
            groupFile = FilePath(groupFile)

        self.realmName = realmName
        self.userFile = userFile
        self.groupFile = groupFile

    def recordTypes(self):
        recordTypes = ("user",)
        if self.groupFile is not None:
            recordTypes += ("group",)
        return recordTypes

    def listRecords(self, recordType):
        for entryShortName, entryData in self.entriesForRecordType(recordType):
            if recordType == "user":
                yield self.userRecordClass(
                    service       = self,
                    recordType    = recordType,
                    shortName     = entryShortName,
                    cryptPassword = entryData,
                )
<commit_msg>Fix repr<commit_after>##
# Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# DRI: <NAME>, <EMAIL>
##

"""
Apache UserFile/GroupFile compatible directory service implementation.
"""

__all__ = [
    "BasicDirectoryService",
    "DigestDirectoryService",
]

from crypt import crypt

from twisted.python.filepath import FilePath
from twisted.cred.credentials import UsernamePassword

from twistedcaldav.directory.directory import DirectoryService, DirectoryRecord
from twistedcaldav.directory.directory import UnknownRecordTypeError

class AbstractDirectoryService(DirectoryService):
    """
    Abstract Apache-compatible implementation of L{IDirectoryService}.
    """
    def __repr__(self):
        return "<%s %r: %r %r>" % (self.__class__.__name__, self.realmName, self.userFile, self.groupFile)

    def __init__(self, realmName, userFile, groupFile=None):
        super(AbstractDirectoryService, self).__init__()

        if type(userFile) is str:
            userFile = FilePath(userFile)
        if type(groupFile) is str:
            groupFile = FilePath(groupFile)

        self.realmName = realmName
        self.userFile = userFile
        self.groupFile = groupFile

    def recordTypes(self):
        recordTypes = ("user",)
        if self.groupFile is not None:
            recordTypes += ("group",)
        return recordTypes

    def listRecords(self, recordType):
        for entryShortName, entryData in self.entriesForRecordType(recordType):
            if recordType == "user":
                yield self.userRecordClass(
                    service       = self,
                    recordType    = recordType,
                    shortName     = entryShortName,
                    cryptPassword = entryData,
                )

{'fraction_non_alphanumeric': 0.0834416991764196, 'fraction_numerical': 0.0034677069787602947, 'mean_word_length': 2.9681857265692178, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '799994', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1168, 'n_words': 397}