summaryrefslogtreecommitdiff
path: root/lib/extras.py
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-01-03 19:27:26 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-01-03 19:27:26 +0100
commit68305a0eb6648b56341caf0253e8cddedde5e13f (patch)
treed75ddb413a9af4c376f7b572c49cfd1b4f60a7db /lib/extras.py
parent3cc8719998931051f26321329cf8e7d507f3c35e (diff)
downloadpsycopg2-68305a0eb6648b56341caf0253e8cddedde5e13f.tar.gz
Fixed TYPE adaptation to basic tuples
Tuples and namedtuples have different constructors.
Diffstat (limited to 'lib/extras.py')
-rw-r--r--lib/extras.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/extras.py b/lib/extras.py
index 6fa8795..2a36c6b 100644
--- a/lib/extras.py
+++ b/lib/extras.py
@@ -765,7 +765,7 @@ class CompositeCaster(object):
self.attnames = [ a[0] for a in attrs ]
self.atttypes = [ a[1] for a in attrs ]
- self.type = self._create_type(name, self.attnames)
+ self._create_type(name, self.attnames)
self.typecaster = _ext.new_type((oid,), name, self.parse)
def parse(self, s, curs):
@@ -780,7 +780,7 @@ class CompositeCaster(object):
attrs = [ curs.cast(oid, token)
for oid, token in zip(self.atttypes, tokens) ]
- return self.type(*attrs)
+ return self._ctor(*attrs)
_re_tokenize = regex.compile(r"""
\(? ([,\)]) # an empty token, representing NULL
@@ -809,9 +809,11 @@ class CompositeCaster(object):
try:
from collections import namedtuple
except ImportError:
- return tuple
+ self.type = tuple
+ self._ctor = lambda *args: tuple(args)
else:
- return namedtuple(name, attnames)
+ self.type = namedtuple(name, attnames)
+ self._ctor = self.type
@classmethod
def _from_db(self, name, conn_or_curs):