def __getitem__(self, key): if key == None: return Null if key == ".": output = _get(self, "_dict") if isinstance(output, Mapping): return self else: return output if isinstance(key, str): key = key.decode("utf8") elif not isinstance(key, unicode): from pyLibrary.debugs.logs import Log Log.error("only string keys are supported") d = _get(self, "_dict") if key.find(".") >= 0: seq = _split_field(key) for n in seq: if isinstance(d, NullType): d = NullType(d, n) # OH DEAR, Null TREATS n AS PATH, NOT LITERAL elif isinstance(d, list): d = [_getdefault(dd, n) for dd in d] else: d = _getdefault(d, n) # EVERYTHING ELSE TREATS n AS LITERAL return wrap(d) else: o = d.get(key) if o == None: return NullType(d, key) return wrap(o)
def __setitem__(self, key, value): if key == "": from pyLibrary.debugs.logs import Log Log.error("key is empty string. Probably a bad idea") if isinstance(key, str): key = key.decode("utf8") d=self try: value = unwrap(value) if key.find(".") == -1: if value is None: dict.pop(d, key, None) else: dict.__setitem__(d, key, value) return self seq = _split_field(key) for k in seq[:-1]: d = _getdefault(d, k) if value == None: dict.pop(d, seq[-1], None) else: dict.__setitem__(d, seq[-1], value) return self except Exception, e: raise e
def __setitem__(self, key, value): if key == "": from pyLibrary.debugs.logs import Log Log.error("key is empty string. Probably a bad idea") if key == ".": # SOMETHING TERRIBLE HAPPENS WHEN value IS NOT A Mapping; # HOPEFULLY THE ONLY OTHER METHOD RUN ON self IS unwrap() v = unwrap(value) _set(self, "_dict", v) return v if isinstance(key, str): key = key.decode("utf8") try: d = _get(self, "_dict") value = unwrap(value) if key.find(".") == -1: if value is None: d.pop(key, None) else: d[key] = value return self seq = _split_field(key) for k in seq[:-1]: d = _getdefault(d, k) if value == None: d.pop(seq[-1], None) else: d[seq[-1]] = value return self except Exception, e: raise e
def __setitem__(self, key, value): if key == "": from pyLibrary.debugs.logs import Log Log.error("key is empty string. Probably a bad idea") if isinstance(key, str): key = key.decode("utf8") try: d = _get(self, "_dict") value = unwrap(value) if key.find(".") == -1: if value is None: d.pop(key, None) else: d[key] = value return self seq = split_field(key) for k in seq[:-1]: d = _getdefault(d, k) if value == None: d.pop(seq[-1], None) else: d[seq[-1]] = value return self except Exception, e: raise e
def __getitem__(self, key): if key == None: return Null if key == ".": output = _get(self, "_dict") if isinstance(output, Mapping): return self else: return output if isinstance(key, str): key = key.decode("utf8") elif not isinstance(key, unicode): from pyLibrary.debugs.logs import Log Log.error("only string keys are supported") d = _get(self, "_dict") if key.find(".") >= 0: seq = _split_field(key) for n in seq: if isinstance(d, NullType): d = NullType( d, n) # OH DEAR, Null TREATS n AS PATH, NOT LITERAL else: d = _getdefault(d, n) # EVERYTHING ELSE TREATS n AS LITERAL return wrap(d) else: o = d.get(key) if o == None: return NullType(d, key) return wrap(o)
def __getitem__(self, key): if key == None: return Null if isinstance(key, str): key = key.decode("utf8") d=self if key.find(".") >= 0: seq = _split_field(key) for n in seq: d = _getdefault(self, n) return wrap(d) else: o = dict.get(d, None) if o == None: return NullType(d, key) return wrap(o)
def __getitem__(self, key): if key == None: return Null if isinstance(key, str): key = key.decode("utf8") d = self if key.find(".") >= 0: seq = split_field(key) for n in seq: d = _getdefault(self, n) return wrap(d) else: o = dict.get(d, None) if o == None: return NullType(d, key) return wrap(o)
def __getitem__(self, key): if key == None: return Null if isinstance(key, str): key = key.decode("utf8") elif not isinstance(key, unicode): from pyLibrary.debugs.logs import Log Log.error("only string keys are supported") d = _get(self, "_dict") if key.find(".") >= 0: seq = split_field(key) for n in seq: d = _getdefault(d, n) return wrap(d) else: o = d.get(key) if o == None: return NullType(d, key) return wrap(o)