removing things that are part of django

This commit is contained in:
Brant Steen
2014-06-28 15:16:30 -04:00
parent 799b629a8a
commit beea767be0
2 changed files with 8 additions and 57 deletions
+3
View File
@@ -25,3 +25,6 @@ pip-log.txt
#Mr Developer
.mr.developer.cfg
# Sublime Codeintel
.codeintel/
+5 -57
View File
@@ -7,7 +7,7 @@ from sqlalchemy import event
from sqlalchemy.pool import manage, QueuePool
from psycopg2 import InterfaceError, ProgrammingError, OperationalError
from django.db import transaction
# from django.db import transaction
from django.conf import settings
from django.db.backends.postgresql_psycopg2.base import *
@@ -53,7 +53,7 @@ def is_disconnect(e, connection, cursor):
elif isinstance(e, ProgrammingError):
# not sure where this path is originally from, it may
# be obsolete. It really says "losed", not "closed".
return "losed the connection unexpectedly" in str(e)
return "closed the connection unexpectedly" in str(e)
else:
return False
@@ -72,40 +72,13 @@ class DatabaseWrapper(Psycopg2DatabaseWrapper):
super(DatabaseWrapper, self).__init__(*args, **kwargs)
self.creation = DatabaseCreation(self)
def _cursor(self):
if self.connection is None or self.connection.is_valid == False:
self.connection = db_pool.connect(**self._get_conn_params())
transaction.set_autocommit(True)
self.connection.set_client_encoding('UTF8')
tz = 'UTC' if settings.USE_TZ else self.settings_dict.get('TIME_ZONE')
if tz:
try:
get_parameter_status = self.connection.get_parameter_status
except AttributeError:
# psycopg2 < 2.0.12 doesn't have get_parameter_status
conn_tz = None
else:
conn_tz = get_parameter_status('TimeZone')
if conn_tz != tz:
# Set the time zone in autocommit mode (see #17062)
self.connection.set_isolation_level(
psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
self.connection.cursor().execute(
self.ops.set_time_zone_sql(), [tz])
self.connection.set_isolation_level(self.isolation_level)
connection_created.send(sender=self.__class__, connection=self)
cursor = self.connection.cursor()
cursor.tzinfo_factory = utc_tzinfo_factory if settings.USE_TZ else None
return cursor
def _commit(self):
if self.connection is not None and self.connection.is_valid:
if self.connection is not None and self.is_usable():
with self.wrap_database_errors:
return self.connection.commit()
def _rollback(self):
if self.connection is not None and self.connection.is_valid:
if self.connection is not None and self.is_usable():
with self.wrap_database_errors:
return self.connection.rollback()
@@ -113,7 +86,7 @@ class DatabaseWrapper(Psycopg2DatabaseWrapper):
"""Dispose of the pool for this instance, closing all connections."""
self.close()
# _DBProxy.dispose doesn't actually call dispose on the pool
conn_params = self._get_conn_params()
conn_params = self.get_connection_params()
key = db_pool._serialize(**conn_params)
try:
pool = db_pool.pools[key]
@@ -122,28 +95,3 @@ class DatabaseWrapper(Psycopg2DatabaseWrapper):
else:
pool.dispose()
del db_pool.pools[key]
def _get_conn_params(self):
settings_dict = self.settings_dict
if not settings_dict['NAME']:
from django.core.exceptions import ImproperlyConfigured
raise ImproperlyConfigured(
"settings.DATABASES is improperly configured. "
"Please supply the NAME value.")
conn_params = {
'database': settings_dict['NAME'],
}
conn_params.update(settings_dict['OPTIONS'])
if 'autocommit' in conn_params:
del conn_params['autocommit']
if settings_dict['USER']:
conn_params['user'] = settings_dict['USER']
if settings_dict['PASSWORD']:
conn_params['password'] = settings_dict['PASSWORD']
if settings_dict['HOST']:
conn_params['host'] = settings_dict['HOST']
if settings_dict['PORT']:
conn_params['port'] = settings_dict['PORT']
return conn_params