Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from django.db.backends import *
from django.db.backends.signals import connection_created
from django.db.backends.postgresql.client import DatabaseClient
from django.db.backends.postgresql.creation import DatabaseCreation
from django.db.backends.postgresql.introspection import DatabaseIntrospection
from django.db.backends.postgresql.operations import DatabaseOperations
from django.db.backends.postgresql.version import get_version
from django.utils.encoding import smart_str, smart_unicode
try:
import psycopg as Database
except ImportError, e:
from django.core.exceptions import ImproperlyConfigured
raise ImproperlyConfigured("Error loading psycopg module: %s" % e)
DatabaseError = Database.DatabaseError
IntegrityError = Database.IntegrityError
class UnicodeCursorWrapper(object):
"""
A thin wrapper around psycopg cursors that allows them to accept Unicode
strings as params.
This is necessary because psycopg doesn't apply any DB quoting to
parameters that are Unicode strings. If a param is Unicode, this will
convert it to a bytestring using database client's encoding before passing
it to psycopg.
All results retrieved from the database are converted into Unicode strings
before being returned to the caller.
"""
def __init__(self, cursor, charset):
def execute(self, sql, params=()):
try:
return self.cursor.execute(smart_str(sql, self.charset), self.format_params(params))
except Database.IntegrityError, e:
raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
except Database.DatabaseError, e:
raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
import sys, string, os.path, fileinput, os, time, getpass, glob, re
# 3rd party imports
dbapi = None
try:
from pyPgSQL import PgSQL
from pyPgSQL import libpq
dbapi = PgSQL
db_error = libpq.DatabaseError
dsn_format = "%s:%s:%s:%s:%s"
except ImportError:
_log.LogException("Cannot load pyPgSQL.PgSQL database adapter module.", sys.exc_info(), verbose=0)
try:
import psycopg
dbapi = psycopg
db_error = psycopg.DatabaseError
dsn_format = "host=%s port=%s dbname=%s user=%s password=%s"
except ImportError:
_log.LogException("Cannot load psycopg database adapter module.", sys.exc_info(), verbose=0)
try:
import pgdb
dbapi = pgdb
db_error = pgdb.DatabaseError
dsn_format = "%s:%s:%s:%s:%s"
except ImportError:
print "Cannot find Python module for connecting to the database server. Program halted."
print "Please check the log file and report to the mailing list."
_log.LogException("Cannot load pgdb database adapter module.", sys.exc_info(), verbose=0)
raise
# GnuMed imports
try:
"""
PostgreSQL database backend for Django.
Requires psycopg 1: http://initd.org/projects/psycopg1
"""
from django.core.db import base, typecasts
import psycopg as Database
DatabaseError = Database.DatabaseError
try:
# Only exists in python 2.4+
from threading import local
except ImportError:
# Import copy of _thread_local.py from python 2.4
from django.utils._threading_local import local
class DatabaseWrapper(local):
def __init__(self):
self.connection = None
self.queries = []
def cursor(self):
from django.conf.settings import DATABASE_USER, DATABASE_NAME, DATABASE_HOST, DATABASE_PORT, DATABASE_PASSWORD, DEBUG, TIME_ZONE
if self.connection is None: