From beea767be0b374b7a4d8d11db13fb7eec1f7fc79 Mon Sep 17 00:00:00 2001 From: Brant Steen Date: Sat, 28 Jun 2014 15:16:30 -0400 Subject: [PATCH] removing things that are part of django --- .gitignore | 3 ++ django_postgrespool/base.py | 62 +++---------------------------------- 2 files changed, 8 insertions(+), 57 deletions(-) diff --git a/.gitignore b/.gitignore index f24cd99..a0baaf3 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ pip-log.txt #Mr Developer .mr.developer.cfg + +# Sublime Codeintel +.codeintel/ diff --git a/django_postgrespool/base.py b/django_postgrespool/base.py index a0d0f9c..080d20e 100644 --- a/django_postgrespool/base.py +++ b/django_postgrespool/base.py @@ -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