我们从Python开源项目中,提取了以下29个代码示例,用于说明如何使用collections.UserDict.__setitem__()。
def __setitem__(self, key, value): # This is heavily used. This implementation is the best we have # according to the timings in bench/env.__setitem__.py. # # The "key in self._special_set_keys" test here seems to perform # pretty well for the number of keys we have. A hard-coded # list works a little better in Python 2.5, but that has the # disadvantage of maybe getting out of sync if we ever add more # variable names. Using self._special_set.has_key() works a # little better in Python 2.4, but is worse than this test. # So right now it seems like a good trade-off, but feel free to # revisit this with bench/env.__setitem__.py as needed (and # as newer versions of Python come out). if key in self._special_set_keys: self._special_set[key](self, key, value) else: # If we already have the entry, then it's obviously a valid # key and we don't need to check. If we do check, using a # global, pre-compiled regular expression directly is more # efficient than calling another function or a method. if key not in self._dict \ and not _is_valid_var.match(key): raise SCons.Errors.UserError("Illegal construction variable `%s'" % key) self._dict[key] = value
def __init__(self, initdict=None): UserDict.__init__(self) if initdict == None: return for key, val in list(initdict.items()): self.__setitem__(self, key, val)
def __setitem__(self, key, item): UserDict.__setitem__(self, key, item) UserDict.__setitem__(self, item, key)
def __setitem__(self, item, val): try: method = getattr(self.env, item).method except AttributeError: pass else: self.env.RemoveMethod(method) UserDict.__setitem__(self, item, val) BuilderWrapper(self.env, val, item)
def update(self, dict): for i, v in dict.items(): self.__setitem__(i, v)
def Replace(self, **kw): """Replace existing construction variables in an Environment with new construction variables and/or values. """ try: kwbd = kw['BUILDERS'] except KeyError: pass else: kwbd = BuilderDict(kwbd,self) del kw['BUILDERS'] self.__setitem__('BUILDERS', kwbd) kw = copy_non_reserved_keywords(kw) self._update(semi_deepcopy(kw)) self.scanner_map_delete(kw)
def __setitem__(self, key, value): if not is_valid_construction_var(key): raise SCons.Errors.UserError("Illegal construction variable `%s'" % key) self.__dict__['overrides'][key] = value
def update(self, dict): for (key, val) in dict.items(): self.__setitem__(key, val)
def __setitem__(self, i, item): UserList.__setitem__(self, i, item) self.unique = False
def __setitem__(self, i, v): return self
def __setitem__(self, key, value): data = base64.b64encode(pickle.dumps(value)).decode('ascii') return UserDict.__setitem__(self, key, data)
def __setitem__(self, key, value): if self.get(key) != value: if key in self: self.del_value(self[key]) if value in self._reversed: del self[self.get_key(value)] self._reversed[value] = key if PY2: return UserDict.__setitem__(self, key, value) else: return super(TwoWayDict, self).__setitem__(key, value)