<commit_before>from sqlobject.dbconnection import DBAPI
import re
from sqlobject import col
from sqlobject import sqlbuilder
psycopg = None
pgdb = None

class PostgresConnection(DBAPI):

    supportTransactions = True
    dbName = 'postgres'
    schemes = [dbName, 'postgresql', 'psycopg']

    def __init__(self, dsn=None, host=None, db=None,
                 user=None, passwd=<PASSWORD>, usePygresql=False,
                 **kw):
        global psycopg, pgdb
        if usePygresql:
            if pgdb is None:
                import pgdb
            self.pgmodule = pgdb
        else:
            if psycopg is None:
                import psycopg
            self.pgmodule = psycopg

        if dsn is None:
            dsn = []
            if db:
                dsn.append('dbname=%s' % db)
            if user:
                dsn.append('user=%s' % user)
            if passwd:
                dsn.append('password=%s' % passwd)
            if host:
                # @@: right format?
                dsn.append('host=%s' % host)
            dsn = ' '.join(dsn)
        self.dsn = dsn
        DBAPI.__init__(self, **kw)

    def connectionFromURI(cls, uri):
        user, password, host, path, args = cls._parseURI(uri)
        path = path.strip('/')
        return cls(host=host, db=path, user=user, passwd=password, **args)
    connectionFromURI = classmethod(connectionFromURI)

    def _setAutoCommit(self, conn, auto):
        conn.autocommit(auto)

    def makeConnection(self):
        conn = self.pgmodule.connect(self.dsn)
        if self.autoCommit:<commit_msg>provide a better error message when having connection problems<commit_after>from sqlobject.dbconnection import DBAPI
import re
from sqlobject import col
from sqlobject import sqlbuilder
psycopg = None
pgdb = None

class PostgresConnection(DBAPI):

    supportTransactions = True
    dbName = 'postgres'
    schemes = [dbName, 'postgresql', 'psycopg']

    def __init__(self, dsn=None, host=None, db=None,
                 user=None, passwd=<PASSWORD>, usePygresql=False,
                 **kw):
        global psycopg, pgdb
        if usePygresql:
            if pgdb is None:
                import pgdb
            self.pgmodule = pgdb
        else:
            if psycopg is None:
                import psycopg
            self.pgmodule = psycopg

        if dsn is None:
            dsn = []
            if db:
                dsn.append('dbname=%s' % db)
            if user:
                dsn.append('user=%s' % user)
            if passwd:
                dsn.append('password=%s' % passwd)
            if host:
                # @@: right format?
                dsn.append('host=%s' % host)
            dsn = ' '.join(dsn)
        self.dsn = dsn
        DBAPI.__init__(self, **kw)

    def connectionFromURI(cls, uri):
        user, password, host, path, args = cls._parseURI(uri)
        path = path.strip('/')
        return cls(host=host, db=path, user=user, passwd=password, **args)
    connectionFromURI = classmethod(connectionFromURI)

    def _setAutoCommit(self, conn, auto):
        conn.autocommit(auto)

    def makeConnection(self):
        try:
            conn = self.pgmodule.connect(self.dsn)
        except self.pgmodule.OperationalError, e:
            raise self.pgmodule.OperationalError("%s; used connection string %r" % (e, self.dsn))
        if self.autoCommit:
{'fraction_non_alphanumeric': 0.10207100591715976, 'fraction_numerical': 0.0, 'mean_word_length': 1.8774468085106384, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4804417', 'n_tokens_mistral': 1023, 'n_tokens_neox': 1007, 'n_words': 255}