<commit_before>import random
import string
import sys
import uuid
from datetime import datetime, timedelta


class BabyMaker(object):
    """
    The factory that makes the babies.
    """
    def __init__(self, fields):
        self.fields = fields
        self.last_iteration = None
        self.current_iteration = None

    def make_one(self):
        """
        TODO - allow a field to raise an exception that it requires another field before it
            can be processed, which would retry the field after all other fields are done.
            Will need to be careful of circular dependencies.
        """
        self.last_iteration = self.current_iteration
        self.current_iteration = dict()
        for name, field in self.fields.iteritems():
            if hasattr(field, "emit"):
                self.current_iteration[name] = field.emit(self)
        return self.current_iteration

    def make_some(self, num):
        for x in range(num):
            yield self.make_one()


class FieldType(object):

    def emit(self, schema):
        return None

class StringType(FieldType):
    """
    Random string of characters.
    """
    def __init__(self, allowed_chars=None, min_size=1, max_size=64):
        self.allowed_chars = allowed_chars or string.printable
        self.max_size = max_size
        self.min_size = min_size

    def emit(self, schema):
        return "".join([random.choice(self.allowed_chars) for x in range(0, random.randint(self.min_size, self.max_size))])


class IntType(FieldType):<commit_msg>Make the babies behave like objects as well as dicts.<commit_after>import random
import string
import sys
import uuid
from datetime import datetime, timedelta


class BabyMaker(object):
    """
    The factory that makes the babies.
    """
    def __init__(self, fields):
        self.fields = fields
        self.last_iteration = None
        self.current_iteration = None

    def make_one(self):
        """
        TODO - allow a field to raise an exception that it requires another field before it
            can be processed, which would retry the field after all other fields are done.
            Will need to be careful of circular dependencies.
        """
        self.last_iteration = self.current_iteration
        self.current_iteration = dict()
        for name, field in self.fields.iteritems():
            if hasattr(field, "emit"):
                self.current_iteration[name] = field.emit(self)
        return DictObject(self.current_iteration)

    def make_some(self, num):
        for x in range(num):
            yield self.make_one()


class DictObject(dict):
    """
    A dict implementation that provides several extra conveniences.
    """
    def __getitem__(self, key):
        value = dict.__getitem__(self, key)
        if type(value) is dict:
            value = DictObject(value)
            self[key] = value
        return value

    def __getattr__(self, name):
        return self[name]

    def __setattr__(self, name, value):
        self[name] = value


class FieldType(object):

    def emit(self, schema):
        return None

class StringType(FieldType):
    """
    Random string of characters.
    """
    def __init__(self, allowed_chars=None, min_size=1, max_size=64):
        self.allowed_chars = allowed_chars or string.printable
        self.max_size = max_size
        self.min_size = min_size

    def emit(self, schema):
        return "".join([random.choice(self.allowed_chars) for x in range(0, random.randint(self.min_size, self.max_size))])


class IntType(FieldType):
{'fraction_non_alphanumeric': 0.08765051806216746, 'fraction_numerical': 0.0022402688322598714, 'mean_word_length': 2.572, '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': '1913301', 'n_tokens_mistral': 1009, 'n_tokens_neox': 991, 'n_words': 311}