Skip to content

Commit

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

def _create_pgcursor(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, host,
db, port)
conn = connection(dsn)
return conn.cursor()

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)
dsn = "user=%s password=%s host=%s dbname=%s port=%s"%(user, passwd, host,
db, port)
conn = connection(dsn)
return conn

Expand Down Expand Up @@ -974,6 +982,20 @@ def save_local(pickler, obj):
log.info("# Loc")
return

@register(CursorType)
def save_pgconnection(pickler, obj):
log.info("Pgcur: %s" % obj)
dsn_parms = obj.connection.info.dsn_parameters
user = dsn_parms["user"]
password = obj.connection.info.password
dbname = dsn_parms["dbname"]
host = dsn_parms["host"]
port = dsn_parms["port"]
pickler.save_reduce(_create_pgcursor, (user, password, dbname,
host, port, ), obj=obj)
log.info("# Pgcur")
return

@register(ConnectionType)
def save_pgconnection(pickler, obj):
log.info("Pgcon: %s" % obj)
Expand Down

0 comments on commit 359f817

Please sign in to comment.