<commit_before>import copy


class _Request(object):
    def __init__(self, uri, graph, username=None, password=<PASSWORD>):
        self.responses = []
        self.uri = uri
        self.graph = graph
        self.username = username
        self.password = password
        
    def reset(self):
        pass
        
    def send(self, script=None, params=None):
        return _Response()


class _Response(object):
    def __init__(self, data=None, update_models=None):
        self.original_data = data
        self.update_models = update_models
        self.data = self._fix_data(data)
        
    def _fix_data(self, arg):
        def fix_properties(data_set):
            if isinstance(data_set, dict) and '_properties' in data_set:
                prop = data_set['_properties']
                del data_set['_properties']
                data_set.update(prop)
            
            return data_set
            
        if not hasattr(arg, '__iter__'):
            data = [{'response': arg}]
        elif isinstance(arg, dict):
            if len(self.update_models) > 0:
                data = []
            
                for k, model in self.update_models.iteritems():
                    val = fix_properties(arg.get(k, None))
                
                    if isinstance(val, dict):
                        if k == '_id':
                            model.fields[k].field_value = val
                        
                        model.hydrate(val)
                        data.append(val)
                        model.dirty = False
                        del arg[k]
            
                data.append(arg)<commit_msg>fixed setting _id<commit_after>import copy


class _Request(object):
    def __init__(self, uri, graph, username=None, password=<PASSWORD>):
        self.responses = []
        self.uri = uri
        self.graph = graph
        self.username = username
        self.password = password
        
    def reset(self):
        pass
        
    def send(self, script=None, params=None):
        return _Response()


class _Response(object):
    def __init__(self, data=None, update_models=None):
        self.original_data = data
        self.update_models = update_models
        self.data = self._fix_data(data)
        
    def _fix_data(self, arg):
        def fix_properties(data_set):
            if isinstance(data_set, dict) and '_properties' in data_set:
                prop = data_set['_properties']
                del data_set['_properties']
                data_set.update(prop)
            
            return data_set
            
        if not hasattr(arg, '__iter__'):
            data = [{'response': arg}]
        elif isinstance(arg, dict):
            if len(self.update_models) > 0:
                data = []
            
                for k, model in self.update_models.iteritems():
                    val = fix_properties(arg.get(k, None))
                
                    if isinstance(val, dict):
                        # the _id field is immutable in the interface, but for newly created 
                        # entites it is passed back with the response. Set it here
                        if k == '_id':
                            model.fields[k].value = val
                        
                        model.hydrate(val)
                        data.append(val)
                        model.dirty = False
                        del arg[k]
            
                data.append(arg)
{'fraction_non_alphanumeric': 0.0876539673446004, 'fraction_numerical': 0.0005729017473503294, 'mean_word_length': 1.3187250996015936, 'pattern_counts': {'":': 0, '<': 5, '<?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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4178427', 'n_tokens_mistral': 915, 'n_tokens_neox': 874, 'n_words': 216}