<commit_before>"""DB-SIG compliant module for communicating with MS SQL servers"""
from collections import deque
import datetime
import errno
import keyword
import os
import re
import six
import socket
import uuid
import warnings
import weakref

from six.moves import xrange

from pytds.tds_types import NVarCharType
from . import lcid
from . import tz
from .tds import (
    SimpleLoadBalancer,
    _TdsSocket, tds7_get_instances,
    _create_exception_by_message,
    output, default
)
from . import tds_base
from .tds_base import (
    Error, LoginError, DatabaseError, ProgrammingError,
    IntegrityError, DataError, InternalError,
    InterfaceError, TimeoutError, OperationalError,
    NotSupportedError, Warning, ClosedConnectionError,
    Column
)

from .tds_types import (
    TableValuedParam, Binary
)

from .tds_base import (
    ROWID, DECIMAL, STRING, BINARY, NUMBER, DATETIME, INTEGER, REAL, XML
)

__author__ = '<NAME> <<EMAIL>>'
__version__ = '1.8.2'


def _ver_to_int(ver):
    maj, minor, rev = ver.split('.')
    return (int(maj) << 24) + (int(minor) << 16) + (int(rev) << 8)


intversion = _ver_to_int(__version__)

#: Compliant with DB SIG 2.0
apilevel = '2.0'

#: Module may be shared, but not connections
threadsafety = 1

#: This module uses extended python format codes
paramstyle = 'pyformat'


class _TdsLogin:
    pass


def tuple_row_strategy(column_names):
    """ Tuple row strategy, rows returned as tuples, default
    """
    return tuple


def list_row_strategy(column_names):
    """  List row strategy, rows returned as lists
    """
    return list


def dict_row_strategy(column_names):
    """ Dict row strategy, rows returned as dictionaries
    """
    # replace empty column names with indices
    column_names = [(name or idx) for idx, name in enumerate(column_names)]

    def row_factory(row):
        return dict(zip(column_names, row))

    return row_factory


def is_valid_identifier(name):
    return name and re.match("^[_A-Za-z][_a-zA-Z0-9]*$", name) and not keyword.iskeyword(name)


def namedtuple_row_strategy(column_names):
    """ Namedtuple row strategy, rows returned as named tuples

    Column names that are not valid Python identifiers will be replaced
    with col<number>_
    """
    import collections
    # replace empty column names with placeholders
    column_names = [name if is_valid_identifier(name) else 'col%s_' % idx for idx, name in enumerate(column_names)]
    row_class = collections.namedtuple('Row', column_names)

    def row_factory(row):
        return row_class(*row)

    return row_factory


def recordtype_row_strategy(column_names):
    """ Recordtype row strategy, rows returned as recordtypes

    Column names that are not valid Python identifiers will be replaced
    with col<number>_
    """
    import recordtype  # optional dependency
    # replace empty column names with placeholders
    column_names = [name if is_valid_identifier(name) else 'col%s_' % idx for idx, name in enumerate(column_names)]
    recordtype_row_class = recordtype.recordtype('Row', column_names)

    # custom extension class that supports indexing
    class Row(recordtype_row_class):
        def __getitem__(self, index):
            if isinstance(index, slice):
                return tuple(getattr(self, x) for x in self.__slots__[index])
            return getattr(self, self.__slots__[index])

        def __setitem__(self, index, value):
            setattr(self, self.__slots__[index], value)

    def row_factory(row):
        return Row(*row)

    return row_factory


class Connection(object):
    """Connection object, this object should be created by calling :func:`connect`"""

    def __init__(self):
        self._closed = False
        self._conn = None<commit_msg>Switch to namedlist for python3 compatibility<commit_after>"""DB-SIG compliant module for communicating with MS SQL servers"""
from collections import deque
import datetime
import errno
import keyword
import os
import re
import six
import socket
import uuid
import warnings
import weakref

from six.moves import xrange

from pytds.tds_types import NVarCharType
from . import lcid
from . import tz
from .tds import (
    SimpleLoadBalancer,
    _TdsSocket, tds7_get_instances,
    _create_exception_by_message,
    output, default
)
from . import tds_base
from .tds_base import (
    Error, LoginError, DatabaseError, ProgrammingError,
    IntegrityError, DataError, InternalError,
    InterfaceError, TimeoutError, OperationalError,
    NotSupportedError, Warning, ClosedConnectionError,
    Column
)

from .tds_types import (
    TableValuedParam, Binary
)

from .tds_base import (
    ROWID, DECIMAL, STRING, BINARY, NUMBER, DATETIME, INTEGER, REAL, XML
)

__author__ = '<NAME> <<EMAIL>>'
__version__ = '1.8.2'


def _ver_to_int(ver):
    maj, minor, rev = ver.split('.')
    return (int(maj) << 24) + (int(minor) << 16) + (int(rev) << 8)


intversion = _ver_to_int(__version__)

#: Compliant with DB SIG 2.0
apilevel = '2.0'

#: Module may be shared, but not connections
threadsafety = 1

#: This module uses extended python format codes
paramstyle = 'pyformat'


class _TdsLogin:
    pass


def tuple_row_strategy(column_names):
    """ Tuple row strategy, rows returned as tuples, default
    """
    return tuple


def list_row_strategy(column_names):
    """  List row strategy, rows returned as lists
    """
    return list


def dict_row_strategy(column_names):
    """ Dict row strategy, rows returned as dictionaries
    """
    # replace empty column names with indices
    column_names = [(name or idx) for idx, name in enumerate(column_names)]

    def row_factory(row):
        return dict(zip(column_names, row))

    return row_factory


def is_valid_identifier(name):
    return name and re.match("^[_A-Za-z][_a-zA-Z0-9]*$", name) and not keyword.iskeyword(name)


def namedtuple_row_strategy(column_names):
    """ Namedtuple row strategy, rows returned as named tuples

    Column names that are not valid Python identifiers will be replaced
    with col<number>_
    """
    import collections
    # replace empty column names with placeholders
    column_names = [name if is_valid_identifier(name) else 'col%s_' % idx for idx, name in enumerate(column_names)]
    row_class = collections.namedtuple('Row', column_names)

    def row_factory(row):
        return row_class(*row)

    return row_factory


def recordtype_row_strategy(column_names):
    """ Recordtype row strategy, rows returned as recordtypes

    Column names that are not valid Python identifiers will be replaced
    with col<number>_
    """
    try:
        from namedlist import namedlist as recordtype  # optional dependency
    except ImportError:
        from recordtype import recordtype  # optional dependency
    # replace empty column names with placeholders
    column_names = [name if is_valid_identifier(name) else 'col%s_' % idx for idx, name in enumerate(column_names)]
    recordtype_row_class = recordtype('Row', column_names)

    # custom extension class that supports indexing
    class Row(recordtype_row_class):
        def __getitem__(self, index):
            if isinstance(index, slice):
                return tuple(getattr(self, x) for x in self.__slots__[index])
            return getattr(self, self.__slots__[index])

        def __setitem__(self, index, value):
            setattr(self, self.__slots__[index], value)

    def row_factory(row):
        return Row(*row)

    return row_factory


class Connection(object):
    """Connection object, this object should be created by calling :func:`connect`"""

    def __init__(self):
        self._closed = False
        self._conn = None
{'fraction_non_alphanumeric': 0.08579997392098057, 'fraction_numerical': 0.004303038205763463, 'mean_word_length': 3.7287299630086315, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 13, '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': '6493094', 'n_tokens_mistral': 2353, 'n_tokens_neox': 2240, 'n_words': 735}