<commit_before>###############################################################################

from pymongo import MongoClient
from bson.objectid import ObjectId
from bson.dbref import DBRef

import random
import string

from yORM import Object, MongoCollectionStorage

from website import settings
from urlparse import urlsplit

client = MongoClient(settings.mongo_uri)

db_name = urlsplit(settings.mongo_uri).path[1:] # Slices off the leading slash of the path (database name)

db = client[db_name]

class MongoObject(Object):
    @property
    def id(self):
        return self._id
    
    @classmethod
    def find(self, **kwargs):

        result = super(MongoObject, self).find(**kwargs)

        if result.count() == 1:
            result = result[0]
            return self(**result)
        elif result.count() > 0:
            return result
        else:
            return None

    def generate_random_id(self):
        chars = string.letters + string.digits[2:]
        return ''.join(random.sample(chars, 5))

    def optimistic_insert(self):
        while True:
            try:
                self._id = self.generate_random_id()
                self.insert()
            except:
                continue
            break<commit_msg>revert back to non-ambiguous ID chars<commit_after>###############################################################################

from pymongo import MongoClient
from bson.objectid import ObjectId
from bson.dbref import DBRef

import random

from yORM import Object, MongoCollectionStorage

from website import settings
from urlparse import urlsplit

client = MongoClient(settings.mongo_uri)

db_name = urlsplit(settings.mongo_uri).path[1:] # Slices off the leading slash of the path (database name)

db = client[db_name]

class MongoObject(Object):
    @property
    def id(self):
        return self._id
    
    @classmethod
    def find(self, **kwargs):

        result = super(MongoObject, self).find(**kwargs)

        if result.count() == 1:
            result = result[0]
            return self(**result)
        elif result.count() > 0:
            return result
        else:
            return None

    def generate_random_id(self):
        NUMBERS = '23456789'
        LOWERS = 'abcdefghijkmnpqrstuvwxyz'
        UPPERS = 'ABCDEFGHJKLMNPQRSTUVWXYZ'
        return ''.join(random.sample(NUMBERS+LOWERS+UPPERS, 5))

    def optimistic_insert(self):
        while True:
            try:
                self._id = self.generate_random_id()
                self.insert()
            except:
                continue
            break
{'fraction_non_alphanumeric': 0.1397228637413395, 'fraction_numerical': 0.007313317936874519, 'mean_word_length': 2.5264586160108546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4909324', 'n_tokens_mistral': 760, 'n_tokens_neox': 705, 'n_words': 193}