mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-11 20:52:42 +01:00
structures: implement _from_iterable() so that set operations work
This commit is contained in:
parent
1a89813cd4
commit
7eff7861ed
@ -42,7 +42,7 @@ class CopyWrapper():
|
|||||||
def __deepcopy__(self, memo):
|
def __deepcopy__(self, memo):
|
||||||
"""Returns a deep copy of the channel object."""
|
"""Returns a deep copy of the channel object."""
|
||||||
newobj = copy(self)
|
newobj = copy(self)
|
||||||
log.debug('CopyWrapper: _BLACKLISTED_COPY_TYPES = %s', _BLACKLISTED_COPY_TYPES)
|
#log.debug('CopyWrapper: _BLACKLISTED_COPY_TYPES = %s', _BLACKLISTED_COPY_TYPES)
|
||||||
for attr, val in self.__dict__.items():
|
for attr, val in self.__dict__.items():
|
||||||
# We can't pickle IRCNetwork, so just return a reference of it.
|
# We can't pickle IRCNetwork, so just return a reference of it.
|
||||||
if not isinstance(val, tuple(_BLACKLISTED_COPY_TYPES)):
|
if not isinstance(val, tuple(_BLACKLISTED_COPY_TYPES)):
|
||||||
@ -64,7 +64,6 @@ class CaseInsensitiveFixedSet(collections.abc.Set, CopyWrapper):
|
|||||||
|
|
||||||
def __init__(self, *, data=None):
|
def __init__(self, *, data=None):
|
||||||
if data is not None:
|
if data is not None:
|
||||||
assert isinstance(data, set)
|
|
||||||
self._data = data
|
self._data = data
|
||||||
else:
|
else:
|
||||||
self._data = set()
|
self._data = set()
|
||||||
@ -76,6 +75,11 @@ class CaseInsensitiveFixedSet(collections.abc.Set, CopyWrapper):
|
|||||||
return key.lower()
|
return key.lower()
|
||||||
return key
|
return key
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _from_iterable(cls, it):
|
||||||
|
"""Returns a new iterable instance given the data in 'it'."""
|
||||||
|
return cls(data=it)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%s(%s)" % (self.__class__.__name__, self._data)
|
return "%s(%s)" % (self.__class__.__name__, self._data)
|
||||||
|
|
||||||
@ -97,7 +101,6 @@ class CaseInsensitiveDict(collections.abc.MutableMapping, CaseInsensitiveFixedSe
|
|||||||
"""
|
"""
|
||||||
def __init__(self, *, data=None):
|
def __init__(self, *, data=None):
|
||||||
if data is not None:
|
if data is not None:
|
||||||
assert isinstance(data, dict)
|
|
||||||
self._data = data
|
self._data = data
|
||||||
else:
|
else:
|
||||||
self._data = {}
|
self._data = {}
|
||||||
@ -127,6 +130,10 @@ class IRCCaseInsensitiveDict(CaseInsensitiveDict):
|
|||||||
return self._irc.to_lower(key)
|
return self._irc.to_lower(key)
|
||||||
return key
|
return key
|
||||||
|
|
||||||
|
def _from_iterable(self, it):
|
||||||
|
"""Returns a new iterable instance given the data in 'it'."""
|
||||||
|
return self.__class__(self._irc, data=it)
|
||||||
|
|
||||||
def __copy__(self):
|
def __copy__(self):
|
||||||
return self.__class__(self._irc, data=self._data.copy())
|
return self.__class__(self._irc, data=self._data.copy())
|
||||||
|
|
||||||
@ -155,6 +162,10 @@ class IRCCaseInsensitiveSet(CaseInsensitiveSet):
|
|||||||
return self._irc.to_lower(key)
|
return self._irc.to_lower(key)
|
||||||
return key
|
return key
|
||||||
|
|
||||||
|
def _from_iterable(self, it):
|
||||||
|
"""Returns a new iterable instance given the data in 'it'."""
|
||||||
|
return self.__class__(self._irc, data=it)
|
||||||
|
|
||||||
def __copy__(self):
|
def __copy__(self):
|
||||||
return self.__class__(self._irc, data=self._data.copy())
|
return self.__class__(self._irc, data=self._data.copy())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user