Skip to content

Commit

Permalink
psycopg connectionObject reduce added!
Browse files Browse the repository at this point in the history
  • Loading branch information
pwnslinger committed Aug 29, 2019
1 parent be48186 commit fe2a1bb
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions dill/_dill.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def _trace(boolean):
from pickle import _Pickler as StockPickler, Unpickler as StockUnpickler
from _thread import LockType
from sqlalchemy.cprocessors import UnicodeResultProcessor
from psycopg2.extensions import connection as ConnectionType
if (sys.hexversion >= 0x30200f0):
from _thread import RLock as RLockType
else:
Expand Down Expand Up @@ -608,6 +609,13 @@ def _create_unicodeProcessor(*args, **kwargs): #XXX: process is readonly
p = UnicodeResultProcessor('utf8')
return p

def _create_pgconnection(user, passwd, db, host, port, *args, **kwargs):
from psycopg2.extensions import connection
dsn = "user=%s password=%s host=%s dbname=%s port=%s"%(user, passwd, db,
host, port)
conn = connection(dsn)
return conn

def _create_local(impl, *args, **kwargs):
local = LocalType()
if local:
Expand Down Expand Up @@ -966,6 +974,19 @@ def save_local(pickler, obj):
log.info("# Loc")
return

@register(ConnectionType)
def save_pgconnection(pickler, obj):
log.info("Pgcon: %s" % obj)
user = obj.info.dsn_parameters["user"]
password = obj.info.password
dbname = obj.info.dsn_parameters["dbname"]
host = obj.info.dsn_parameters["host"]
port = obj.info.dsn_parameters["port"]
pickler.save_reduce(_create_pgconnection, (user, password, dbname,
host, port, ), obj=obj)
log.info("# Pgcon")
return

@register(UnicodeResultProcessor)
def save_processor(pickler, obj):
log.info("SqlUni: %s" % obj)
Expand Down

0 comments on commit fe2a1bb

Please sign in to comment.