equal
deleted
inserted
replaced
77 |
77 |
78 import psycopg2 |
78 import psycopg2 |
79 import psycopg2.extensions |
79 import psycopg2.extensions |
80 |
80 |
81 from psycopg2 import DatabaseError, IntegrityError, OperationalError |
81 from psycopg2 import DatabaseError, IntegrityError, OperationalError |
|
82 |
|
83 |
|
84 log = logging.getLogger("pgmanager") |
82 |
85 |
83 |
86 |
84 class PgManagerError(Exception): |
87 class PgManagerError(Exception): |
85 |
88 |
86 pass |
89 pass |
349 if level.lower() == 'serializable': |
352 if level.lower() == 'serializable': |
350 return psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE |
353 return psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE |
351 raise PgManagerError('Unknown isolation level name: "%s"', level) |
354 raise PgManagerError('Unknown isolation level name: "%s"', level) |
352 return level |
355 return level |
353 |
356 |
354 |
357 @classmethod |
355 try: |
358 def get_instance(cls): |
356 NullHandler = logging.NullHandler |
359 if not hasattr(cls, '_instance'): |
357 except AttributeError: |
360 cls._instance = cls() |
358 class NullHandler(logging.Handler): |
361 return cls._instance |
359 def emit(self, record): |
|
360 pass |
|
361 |
|
362 |
|
363 log = logging.getLogger("pgmanager") |
|
364 log.addHandler(NullHandler()) |
|
365 |
|
366 |
|
367 instance = None |
|
368 |
362 |
369 |
363 |
370 def get_instance(): |
364 def get_instance(): |
371 global instance |
365 return PgManager.get_instance() |
372 if instance is None: |
366 |
373 instance = PgManager() |
|
374 return instance |
|
375 |
|
376 |
|