<commit_before>#hack:
BAD_DO_ID = BAD_ZONE_ID = -1

if __debug__:
    from otp.avatar.DistributedPlayerAI import DistributedPlayerAI

class DoCollectionManager:
    def __init__(self):
        # Dict of {DistributedObject ids : DistributedObjects}
        self.doId2do = {}
        if wantOtpServer:
            # Dict of {
            #   parent DistributedObject id: 
            #     { zoneIds : [child DistributedObject ids] }}
            self.__doHierarchy = {}

    def doFind(self, str):
        """
        Returns list of distributed objects with matching str in value.
        """
        for value in self.doId2do.values():
            if `value`.find(str) >= 0:
                return value

    def doFindAll(self, str):
        """
        Returns list of distributed objects with matching str in value.
        """
        matches = []
        for value in self.doId2do.values():
            if `value`.find(str) >= 0:
                matches.append(value)
        return matches

    def getDoHierarchy(self):
        return self.__doHierarchy

    if __debug__:
        def printObjects(self):
            format="%10s %10s %10s %30s %20s"
            title=format%("parentId", "zoneId", "doId", "dclass", "name")
            print title
            print '-'*len(title)
            for distObj in self.doId2do.values():
                print format%(
                    distObj.__dict__.get("parentId"),
                    distObj.__dict__.get("zoneId"),
                    distObj.__dict__.get("doId"),
                    distObj.dclass.getName(),
                    distObj.__dict__.get("name"))

    def getDoIdList(self, parentId, zoneId=None, classType=None):
        """
        parentId is any distributed object id.
        zoneId is a uint32, defaults to None (all zones).  Try zone 2 if
            you're not sure which zone to use (0 is a bad/null zone and 
            1 has had reserved use in the past as a no messages zone, while
            2 has traditionally been a global, uber, misc stuff zone).
        dclassType is a distributed class type filter, defaults 
            to None (no filter).
        
        If dclassName is None then all objects in the zone are returned;
        otherwise the list is filtered to only include objects of that type.
        """
        parent=self.__doHierarchy.get(parentId)
        if parent is None:
            return []
        if zoneId is None:
            r = []
            for zone in parent.values():
                for obj in zone:
                    r.append(obj)
        else:
            r = parent.get(zoneId, [])
        if classType is not None:
            a = []
            for obj in r:
                if isinstance(obj, classType):
                    a.append(obj)
            r = a
        return r

    if __debug__:
        def getPlayerAvatars(self):
            return [i for i in simbase.air.doId2do.values()
                      if isinstance(i, DistributedPlayerAI)]
    
    def countObjects(self, classType):
        """
        Counts the number of objects of the given type in the
        repository (for testing purposes)
        """
        count = 0;
        for dobj in self.doId2do.values():
            if isinstance(dobj, classType):
                count += 1<commit_msg>prevent AI file import on the client<commit_after>#hack:
BAD_DO_ID = BAD_ZONE_ID = -1

if __debug__ and game.process != 'client':
    from otp.avatar.DistributedPlayerAI import DistributedPlayerAI

class DoCollectionManager:
    def __init__(self):
        # Dict of {DistributedObject ids : DistributedObjects}
        self.doId2do = {}
        if wantOtpServer:
            # Dict of {
            #   parent DistributedObject id: 
            #     { zoneIds : [child DistributedObject ids] }}
            self.__doHierarchy = {}

    def doFind(self, str):
        """
        Returns list of distributed objects with matching str in value.
        """
        for value in self.doId2do.values():
            if `value`.find(str) >= 0:
                return value

    def doFindAll(self, str):
        """
        Returns list of distributed objects with matching str in value.
        """
        matches = []
        for value in self.doId2do.values():
            if `value`.find(str) >= 0:
                matches.append(value)
        return matches

    def getDoHierarchy(self):
        return self.__doHierarchy

    if __debug__:
        def printObjects(self):
            format="%10s %10s %10s %30s %20s"
            title=format%("parentId", "zoneId", "doId", "dclass", "name")
            print title
            print '-'*len(title)
            for distObj in self.doId2do.values():
                print format%(
                    distObj.__dict__.get("parentId"),
                    distObj.__dict__.get("zoneId"),
                    distObj.__dict__.get("doId"),
                    distObj.dclass.getName(),
                    distObj.__dict__.get("name"))

    def getDoIdList(self, parentId, zoneId=None, classType=None):
        """
        parentId is any distributed object id.
        zoneId is a uint32, defaults to None (all zones).  Try zone 2 if
            you're not sure which zone to use (0 is a bad/null zone and 
            1 has had reserved use in the past as a no messages zone, while
            2 has traditionally been a global, uber, misc stuff zone).
        dclassType is a distributed class type filter, defaults 
            to None (no filter).
        
        If dclassName is None then all objects in the zone are returned;
        otherwise the list is filtered to only include objects of that type.
        """
        parent=self.__doHierarchy.get(parentId)
        if parent is None:
            return []
        if zoneId is None:
            r = []
            for zone in parent.values():
                for obj in zone:
                    r.append(obj)
        else:
            r = parent.get(zoneId, [])
        if classType is not None:
            a = []
            for obj in r:
                if isinstance(obj, classType):
                    a.append(obj)
            r = a
        return r

    if __debug__ and game.process != 'client':
        def getPlayerAvatars(self):
            return [i for i in simbase.air.doId2do.values()
                      if isinstance(i, DistributedPlayerAI)]
    
    def countObjects(self, classType):
        """
        Counts the number of objects of the given type in the
        repository (for testing purposes)
        """
        count = 0;
        for dobj in self.doId2do.values():
            if isinstance(dobj, classType):
                count += 1
{'fraction_non_alphanumeric': 0.08706058339566193, 'fraction_numerical': 0.008077786088257292, 'mean_word_length': 1.6229894076108278, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5619634', 'n_tokens_mistral': 1845, 'n_tokens_neox': 1758, 'n_words': 593}