<commit_before>import pydbc_intern as intern
from exceptions import StandardError
from functools import wraps

class Error(StandardError):
    pass


def translate_exceptions(f):
    @wraps(f)
    def wrapper(*args, **kwds):
        try:
            return f(*args, **kwds)
        except intern.Error as e:
            raise Error(str(e))
    return wrapper

class cursor():
    def __init__(self, impl):
        self.impl = impl
        self.rowcount = -1
        self.description = None
    
    def _assert_valid(self):
        if self.impl is None:
            raise Error("Cursor already closed")
        
    @translate_exceptions
    def execute(self, sql):
        """Execute an SQL query"""
        self._assert_valid()
        self.impl.execute(sql)
        self.rowcount = self.impl.get_rowcount()
        
    @translate_exceptions
    def fetchone(self):
        result = self.impl.fetchone()
        if len(result) == 0:
            return None 
        else:
            return result  
    
    @translate_exceptions    
    def fetchall(self):
        def rows():
            row = self.fetchone()
            while (row):
                yield row
                row = self.fetchone()
        return rows()

    def close(self):
        self._assert_valid()
        self.impl = None

    def is_closed(self):
        return self.impl is None

class Connection():
    def _assert_valid(self):
        if self.impl is None:
            raise Error("Connection already closed")
    
    def __init__(self, impl):
        self.impl = impl
        self.cursors = []
        
    @translate_exceptions
    def cursor(self):
        """Create a cursor object"""
        self._assert_valid()
        c = cursor(self.impl.cursor())
        self.cursors.append(c)
        return c
    
    @translate_exceptions
    def commit(self):<commit_msg>fetchall <commit_after>import pydbc_intern as intern
from exceptions import StandardError
from functools import wraps

class Error(StandardError):
    pass


def translate_exceptions(f):
    @wraps(f)
    def wrapper(*args, **kwds):
        try:
            return f(*args, **kwds)
        except intern.Error as e:
            raise Error(str(e))
    return wrapper

class cursor():
    def __init__(self, impl):
        self.impl = impl
        self.rowcount = -1
        self.description = None
    
    def _assert_valid(self):
        if self.impl is None:
            raise Error("Cursor already closed")
        
    @translate_exceptions
    def execute(self, sql):
        """Execute an SQL query"""
        self._assert_valid()
        self.impl.execute(sql)
        self.rowcount = self.impl.get_rowcount()
        
    @translate_exceptions
    def fetchone(self):
        result = self.impl.fetchone()
        if len(result) == 0:
            return None 
        else:
            return result  
    
    @translate_exceptions    
    def fetchall(self):
        #can be optimized by implementing it in C++. 
        #But has to make sure that really all remaining rows are fetched,
        #thereby finishing and closing the associated internal result set buffer.
        def rows():
            row = self.fetchone()
            while (row):
                yield row
                row = self.fetchone()
        return [row for row in rows()]
    
    

    def close(self):
        self._assert_valid()
        self.impl = None

    def is_closed(self):
        return self.impl is None

class Connection():
    def _assert_valid(self):
        if self.impl is None:
            raise Error("Connection already closed")
    
    def __init__(self, impl):
        self.impl = impl
        self.cursors = []
        
    @translate_exceptions
    def cursor(self):
        """Create a cursor object"""
        self._assert_valid()
        c = cursor(self.impl.cursor())
        self.cursors.append(c)
        return c
    
    @translate_exceptions
    def commit(self):
{'fraction_non_alphanumeric': 0.09180826781638346, 'fraction_numerical': 0.001014455997971088, 'mean_word_length': 1.85177151120752, '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': '1828127', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1082, 'n_words': 312}