<commit_before>"""
Implements collections.abc for common .NET types
https://docs.python.org/3.6/library/collections.abc.html
"""

import collections.abc as col

class IteratorMixin(col.Iterator):
    def close(self):
        self.Dispose()

class IterableMixin(col.Iterable):
    pass

class SizedMixin(col.Sized):
    def __len__(self): return self.Count

class ContainerMixin(col.Container):
    def __contains__(self, item): return self.Contains(item)

try:
    abc_Collection = col.Collection
except AttributeError:
    # Python 3.5- does not have collections.abc.Collection
    abc_Collection = col.Container

class CollectionMixin(SizedMixin, IterableMixin, ContainerMixin, abc_Collection):
    pass

class SequenceMixin(CollectionMixin, col.Sequence):
    pass

class MutableSequenceMixin(SequenceMixin, col.MutableSequence):
    pass

class MappingMixin(CollectionMixin, col.Mapping):
    def __contains__(self, item): return self.ContainsKey(item)
    def keys(self): return self.Keys
    def items(self): return [(k,self[k]) for k in self.Keys]
    def values(self): return self.Values
    def __iter__(self): return self.Keys.__iter__()
    def get(self, key):
        _, item = self.TryGetValue(key)
        return item

class MutableMappingMixin(MappingMixin, col.MutableMapping):
    def __delitem__(self, key):
        return self.Remove(key)
    def clear(self):
        self.Clear()
    def pop(self, key):
        return self.Remove(key)
    def setdefault(self, key, value):
        existed, item = self.TryGetValue(key)
        if existed:
            return item
        else:
            self[key] = value
            return value
    def update(self, items):
        for key, value in items:
            self[key] = value<commit_msg>fixed implementation of mixins for Mapping and MutableMapping (still untested)<commit_after>"""
Implements collections.abc for common .NET types
https://docs.python.org/3.6/library/collections.abc.html
"""

import collections.abc as col

class IteratorMixin(col.Iterator):
    def close(self):
        self.Dispose()

class IterableMixin(col.Iterable):
    pass

class SizedMixin(col.Sized):
    def __len__(self): return self.Count

class ContainerMixin(col.Container):
    def __contains__(self, item): return self.Contains(item)

try:
    abc_Collection = col.Collection
except AttributeError:
    # Python 3.5- does not have collections.abc.Collection
    abc_Collection = col.Container

class CollectionMixin(SizedMixin, IterableMixin, ContainerMixin, abc_Collection):
    pass

class SequenceMixin(CollectionMixin, col.Sequence):
    pass

class MutableSequenceMixin(SequenceMixin, col.MutableSequence):
    pass

class MappingMixin(CollectionMixin, col.Mapping):
    def __contains__(self, item): return self.ContainsKey(item)
    def keys(self): return self.Keys
    def items(self): return [(k,self[k]) for k in self.Keys]
    def values(self): return self.Values
    def __iter__(self): return self.Keys.__iter__()
    def get(self, key, default=None):
        existed, item = self.TryGetValue(key)
        return item if existed else default

class MutableMappingMixin(MappingMixin, col.MutableMapping):
    _UNSET_ = object()

    def __delitem__(self, key):
        self.Remove(key)

    def clear(self):
        self.Clear()

    def pop(self, key, default=_UNSET_):
        existed, item = self.TryGetValue(key)
        if existed:
            self.Remove(key)
            return item
        elif default == self._UNSET_:
            raise KeyError(key)
        else:
            return default

    def setdefault(self, key, value=None):
        existed, item = self.TryGetValue(key)
        if existed:
            return item
        else:
            self[key] = value
            return value

    def update(self, items, **kwargs):
        if isinstance(items, col.Mapping):
            for key, value in items.items():
                self[key] = value
        else:
            for key, value in items:
                self[key] = value

        for key, value in kwargs.items():
            self[key] = value
{'fraction_non_alphanumeric': 0.09929078014184398, 'fraction_numerical': 0.0019564685742235266, 'mean_word_length': 2.9631782945736433, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '6181228', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1196, 'n_words': 323}