def __init__(self, ns_tuple=()): '''New L{Tuple} from a C{tupe}, L{Tuple}, L{List} or C{NS[Mutable]Array}. ''' if isinstance(ns_tuple, tuple): self.NS = tuple2NS(ns_tuple) elif isinstance(ns_tuple, Tuple): self.NS = ns_tuple.NS elif isinstance(ns_tuple, _Types.List): self.NS = ns_tuple.NS.copy() elif isImmutable(ns_tuple, NSMutableArray, NSArray, name='ns_tuple'): self.NS = ns_tuple
def __init__(self, ns_set=()): '''New L{FrozenSet} from a C{frozenset}, C{list}, C{set}, C{tuple}, L{FrozenSet}, L{Set} or C{NSSet}. ''' if isinstance(ns_set, frozenset): self._set = ns_set elif isinstance(ns_set, (list, tuple, set)): self._set = frozenset(ns_set) elif isinstance(ns_set, FrozenSet): self._set = ns_set._set elif isinstance(ns_set, Set): self._set = frozenset(ns_set._set) elif isImmutable( ns_set, NSMutableSet, # mutable first NSSet, name=self.__class__.__name__): self._set = nsSet2set(ns_set)
def __new__(cls, ns_frozenset=()): '''New L{FrozenSet} from a C{frozenset}, C{list}, C{set}, C{tuple}, L{FrozenSet} or C{NSSet}. ''' if isinstance(ns_frozenset, FrozenSet): return ns_frozenset elif isinstance(ns_frozenset, frozenset): py = ns_frozenset ns = frozenset2NS(py) elif isinstance(ns_frozenset, (list, tuple, set)): py = frozenset(ns_frozenset) ns = frozenset2NS(py) elif isImmutable(ns_frozenset, NSMutableSet, NSSet, name=FrozenSet.__name__): ns = ns_frozenset py = nsSet2set(ns) self = super(FrozenSet, cls).__new__(cls, py) self._NS = ns # _RO return self
def __init__(self, *ns_dict, **kwds): '''New immutable L{FrozenDict}, like C{dict.__init__}. ''' ns_dict, kwds = _dict_kwds(ns_dict, kwds, FrozenDict.__name__) if isinstance(ns_dict, dict): if kwds: ns_dict = ns_dict.copy() ns_dict.update(kwds) kwds = {} self.NS = self._NS_Dictionary(py2NS(ns_dict)) elif isinstance(ns_dict, FrozenDict): self.NS = ns_dict.NS elif isinstance(ns_dict, Dict): self.NS = ns_dict.NS._NS_copy(False) elif isImmutable(ns_dict, NSMutableDictionary, NSDictionary, name=FrozenDict.__name__): self.NS = ns_dict if kwds: ns = self._NS_copy(True) ns.update(kwds) self.NS = ns._NS_copy(False)