<commit_before>"""This module contains fields that depend on importing `bson`. `bson` is
as part of the pymongo distribution.
"""

from dictshield.base import BaseField, ShieldException

import bson

class ObjectIdField(BaseField):
    """An field wrapper around MongoDB ObjectIds.  It is correct to say they're
    bson fields, but I am unaware of bson being used outside MongoDB.
    """

    def _jsonschema_type(self):
        return 'string'<commit_msg>Updated ObjectIdField to have default behavior like UUIDField.<commit_after>"""This module contains fields that depend on importing `bson`. `bson` is
as part of the pymongo distribution.
"""

from dictshield.base import BaseField, ShieldException

import bson

class ObjectIdField(BaseField):
    """An field wrapper around MongoDB ObjectIds.  It is correct to say they're
    bson fields, but I am unaware of bson being used outside MongoDB.
    """

    def __init__(self, auto_fill=True, **kwargs):
        self.auto_fill = auto_fill
        super(ObjectIdField, self).__init__(**kwargs)    

    def __set__(self, instance, value):
        """Convert any text values provided into Python UUID objects and
        auto-populate any empty values should auto_fill be set to True.
        """
        if not value and self.audo_fill is True:
            value = bson.objectid.ObjectId()

        if isinstance(value, (str, unicode)):
            value = bson.objectid.ObjectId(unicode(value))

        instance._data[self.field_name] = value
    
    def _jsonschema_type(self):
        return 'string'
{'fraction_non_alphanumeric': 0.08205128205128205, 'fraction_numerical': 0.0, 'mean_word_length': 3.3361111111111112, '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': '783765', 'n_tokens_mistral': 450, 'n_tokens_neox': 430, 'n_words': 163}