diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2016-08-07 02:49:13 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2016-08-07 02:49:13 +0100 |
commit | bd95269c690963af6ebcc882cb0a5c572a3899b3 (patch) | |
tree | a6140cf0d083cee18a439c800a37e28d9da1bc3c | |
parent | 03824a1dba8eb4b82fff3fd6c0a8ae513e72a2a1 (diff) | |
parent | edd51aac25b2cc9f25e0df1d94724b945797832a (diff) | |
download | psycopg2-bd95269c690963af6ebcc882cb0a5c572a3899b3.tar.gz |
Merge branch 'master' into nul-terminator
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | doc/src/faq.rst | 2 | ||||
-rw-r--r-- | lib/_range.py | 11 | ||||
-rwxr-xr-x | tests/test_types_extras.py | 7 |
4 files changed, 25 insertions, 1 deletions
@@ -21,6 +21,12 @@ New features: - Added `~connection.get_dsn_parameters()` connection method (:ticket:`#364`). +What's new in psycopg 2.6.3 +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +- Make `~psycopg2.extras.Range` objects picklable (:ticket:`#462`). + + What's new in psycopg 2.6.2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/doc/src/faq.rst b/doc/src/faq.rst index 69273ba..d063666 100644 --- a/doc/src/faq.rst +++ b/doc/src/faq.rst @@ -73,7 +73,7 @@ Why does `!cursor.execute()` raise the exception *can't adapt*? I can't pass an integer or a float parameter to my query: it says *a number is required*, but *it is* a number! In your query string, you always have to use ``%s`` placeholders, - event when passing a number. All Python objects are converted by Psycopg + even when passing a number. All Python objects are converted by Psycopg in their SQL representation, so they get passed to the query as strings. See :ref:`query-parameters`. :: diff --git a/lib/_range.py b/lib/_range.py index 47b8208..b6fe0bd 100644 --- a/lib/_range.py +++ b/lib/_range.py @@ -171,6 +171,17 @@ class Range(object): else: return self.__gt__(other) + def __getstate__(self): + return dict( + (slot, getattr(self, slot)) + for slot in self.__slots__ + if hasattr(self, slot) + ) + + def __setstate__(self, state): + for slot, value in state.items(): + setattr(self, slot, value) + def register_range(pgrange, pyrange, conn_or_curs, globally=False): """Create and register an adapter and the typecasters to convert between diff --git a/tests/test_types_extras.py b/tests/test_types_extras.py index b81ceca..d844401 100755 --- a/tests/test_types_extras.py +++ b/tests/test_types_extras.py @@ -20,6 +20,7 @@ import sys from decimal import Decimal from datetime import date, datetime from functools import wraps +from pickle import dumps, loads from testutils import unittest, skip_if_no_uuid, skip_before_postgres from testutils import ConnectingTestCase, decorate_all_tests @@ -1397,6 +1398,12 @@ class RangeTestCase(unittest.TestCase): with py3_raises_typeerror(): self.assert_(Range(1, 2) >= 1) + def test_pickling(self): + from psycopg2.extras import Range + + r = Range(0, 4) + self.assertEqual(loads(dumps(r)), r) + def skip_if_no_range(f): @wraps(f) |