mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 19:31:54 +08:00
Fix #2156977: Use frozenset as the base for DBAPISet. Only tested for
Python 2.5.
This commit is contained in:
@ -31,24 +31,19 @@ from MySQLdb.constants import FIELD_TYPE
|
|||||||
from MySQLdb.times import Date, Time, Timestamp, \
|
from MySQLdb.times import Date, Time, Timestamp, \
|
||||||
DateFromTicks, TimeFromTicks, TimestampFromTicks
|
DateFromTicks, TimeFromTicks, TimestampFromTicks
|
||||||
|
|
||||||
from sets import ImmutableSet
|
try:
|
||||||
class DBAPISet(ImmutableSet):
|
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
|
"""A special type of set for which A == x is true if A is a
|
||||||
DBAPISet and x is a member of that set."""
|
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):
|
def __eq__(self, other):
|
||||||
from sets import BaseSet
|
if isinstance(other, DBAPISet):
|
||||||
if isinstance(other, BaseSet):
|
return not self.difference(other)
|
||||||
return super(DBAPISet, self).__eq__(self, other)
|
|
||||||
else:
|
|
||||||
return other in self
|
return other in self
|
||||||
|
|
||||||
|
|
||||||
@ -65,6 +60,18 @@ TIMESTAMP = DBAPISet([FIELD_TYPE.TIMESTAMP, FIELD_TYPE.DATETIME])
|
|||||||
DATETIME = TIMESTAMP
|
DATETIME = TIMESTAMP
|
||||||
ROWID = DBAPISet()
|
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):
|
def Binary(x):
|
||||||
return str(x)
|
return str(x)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user