From b4c20bfaa0464a68752a1c773212b96b6698f626 Mon Sep 17 00:00:00 2001 From: adustman Date: Fri, 17 Oct 2008 00:44:48 +0000 Subject: [PATCH] Fix #2156977: Use frozenset as the base for DBAPISet. Only tested for Python 2.5. --- MySQLdb/MySQLdb/__init__.py | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/MySQLdb/MySQLdb/__init__.py b/MySQLdb/MySQLdb/__init__.py index d06faa2..7bfac1d 100644 --- a/MySQLdb/MySQLdb/__init__.py +++ b/MySQLdb/MySQLdb/__init__.py @@ -31,25 +31,20 @@ from MySQLdb.constants import FIELD_TYPE from MySQLdb.times import Date, Time, Timestamp, \ DateFromTicks, TimeFromTicks, TimestampFromTicks -from sets import ImmutableSet -class DBAPISet(ImmutableSet): +try: + frozenset +except NameError: + from sets import ImmutableSet as frozenset + +class DBAPISet(frozenset): """A special type of set for which A == x is true if A is a DBAPISet and x is a member of that set.""" - def __ne__(self, other): - from sets import BaseSet - if isinstance(other, BaseSet): - return super(DBAPISet.self).__ne__(self, other) - else: - return other not in self - def __eq__(self, other): - from sets import BaseSet - if isinstance(other, BaseSet): - return super(DBAPISet, self).__eq__(self, other) - else: - return other in self + if isinstance(other, DBAPISet): + return not self.difference(other) + return other in self STRING = DBAPISet([FIELD_TYPE.ENUM, FIELD_TYPE.STRING, @@ -65,6 +60,18 @@ TIMESTAMP = DBAPISet([FIELD_TYPE.TIMESTAMP, FIELD_TYPE.DATETIME]) DATETIME = TIMESTAMP ROWID = DBAPISet() +def test_DBAPISet_set_equality(): + assert STRING == STRING + +def test_DBAPISet_set_inequality(): + assert STRING != NUMBER + +def test_DBAPISet_set_equality_membership(): + assert FIELD_TYPE.VAR_STRING == STRING + +def test_DBAPISet_set_inequality_membership(): + assert FIELD_TYPE.DATE != STRING + def Binary(x): return str(x)