<commit_before>from __future__ import nested_scopes
import _sqlite3 as _sqlite

import copy, new, sys, weakref
from types import *

if sys.version_info[:2] >= (2,2):
    MyStopIteration = StopIteration
else:
    MyStopIteration = IndexError

class DBAPITypeObject:
    def __init__(self,*values):
        self.values = values

    def __cmp__(self,other):
        if other in self.values:
            return 0
        if other < self.values:
            return 1
        else:
            return -1

class Row:
    def __init__(self, data, description):
        self.description = description
        self.data = data
        self.col_names = {}
        for idx, col in enumerate(description):
            self.col_names[col[0].upper()] = idx

    def __getitem__(self, idx):
        if isinstance(idx, str):
            return self.__getattr__(idx)
        return self.data[idx]
        
    def __getattr__(self, attr):
        attr = attr.upper()
        if self.col_names.has_key(attr):
            return self.data[self.col_names[attr]]
        raise AttributeError, attr

    def __len__(self):
        return len(self.data)

    def __contains__(self, key):
        return self.has_key(key)

    def __getslice__(self, i, j):
        return Row(self.data[i:j], self.description[i:j])

    def __repr__(self):
        return repr(self.data)

    def __str__(self):
        return str(self.data)

    def __cmp__(self, other):
        return cmp(self.data, other)

    def description(self):
        return self.description

    def keys(self):
        return [ x[0] for x in self.description ]

    def values(self):
        return self.data[:]

    def items(self):
        l = []
        for i in xrange(len(self.data)):
            l.append((self.description[i][0], self.data[i]))

        return l

    def has_key(self, key):
        return self.col_names.has_key(key.upper())

    def get(self, key, defaultval=None):
        if self.has_key(key):
            return self[key]
        else:
            return defaultval

class Cursor:
    """Abstract cursor class implementing what all cursor classes have in
    common."""

    def __init__(self, conn):
        self.arraysize = 1

        # Add ourselves to the list of cursors for our owning connection.
        self.con = weakref.proxy(conn)
        self.con.cursors[id(self)] = self

        self.stmt = None
        self._reset()
        self.rowcount = -1
        self.rownumber = 0

    def _reset(self):
        # closed is a trinary variable:
        #     == None => Cursor has not been opened.
        #     ==    0 => Cursor is open.
        #     ==    1 => Cursor is closed.
        self.closed = None
        self.description = None
        self.current_row = None
        if self.stmt is not None:
            self.stmt.reset()
            self.stmt = None
        
    def _checkNotClosed(self, methodname=None):
        if self.closed:
            raise _sqlite.ProgrammingError, \<commit_msg>use finalize, not reset.  reset will fail if the database is locked<commit_after>from __future__ import nested_scopes
import _sqlite3 as _sqlite

import copy, new, sys, weakref
from types import *

if sys.version_info[:2] >= (2,2):
    MyStopIteration = StopIteration
else:
    MyStopIteration = IndexError

class DBAPITypeObject:
    def __init__(self,*values):
        self.values = values

    def __cmp__(self,other):
        if other in self.values:
            return 0
        if other < self.values:
            return 1
        else:
            return -1

class Row:
    def __init__(self, data, description):
        self.description = description
        self.data = data
        self.col_names = {}
        for idx, col in enumerate(description):
            self.col_names[col[0].upper()] = idx

    def __getitem__(self, idx):
        if isinstance(idx, str):
            return self.__getattr__(idx)
        return self.data[idx]
        
    def __getattr__(self, attr):
        attr = attr.upper()
        if self.col_names.has_key(attr):
            return self.data[self.col_names[attr]]
        raise AttributeError, attr

    def __len__(self):
        return len(self.data)

    def __contains__(self, key):
        return self.has_key(key)

    def __getslice__(self, i, j):
        return Row(self.data[i:j], self.description[i:j])

    def __repr__(self):
        return repr(self.data)

    def __str__(self):
        return str(self.data)

    def __cmp__(self, other):
        return cmp(self.data, other)

    def description(self):
        return self.description

    def keys(self):
        return [ x[0] for x in self.description ]

    def values(self):
        return self.data[:]

    def items(self):
        l = []
        for i in xrange(len(self.data)):
            l.append((self.description[i][0], self.data[i]))

        return l

    def has_key(self, key):
        return self.col_names.has_key(key.upper())

    def get(self, key, defaultval=None):
        if self.has_key(key):
            return self[key]
        else:
            return defaultval

class Cursor:
    """Abstract cursor class implementing what all cursor classes have in
    common."""

    def __init__(self, conn):
        self.arraysize = 1

        # Add ourselves to the list of cursors for our owning connection.
        self.con = weakref.proxy(conn)
        self.con.cursors[id(self)] = self

        self.stmt = None
        self._reset()
        self.rowcount = -1
        self.rownumber = 0

    def _reset(self):
        # closed is a trinary variable:
        #     == None => Cursor has not been opened.
        #     ==    0 => Cursor is open.
        #     ==    1 => Cursor is closed.
        self.closed = None
        self.description = None
        self.current_row = None
        if self.stmt is not None:
            self.stmt.finalize()
            self.stmt = None
        
    def _checkNotClosed(self, methodname=None):
        if self.closed:
            raise _sqlite.ProgrammingError, \
{'fraction_non_alphanumeric': 0.10121524887631098, 'fraction_numerical': 0.00499417346429166, 'mean_word_length': 1.9890547263681593, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '3276179', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1759, 'n_words': 493}