pathtree.py (52aeb314c0ebd07e5e5eaf24c0084add0e6ecaf0) | pathtree.py (ce2a6f0354ed450ada2171e239ac1056b3df3126) |
---|---|
1# Contributors Listed Below - COPYRIGHT 2016 2# [+] International Business Machines Corp. 3# 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# --- 143 unchanged lines hidden (view full) --- 152 d = self.root 153 for k in elements[:-1]: 154 d = d.setdefault(k, {kids: {}})[kids] 155 156 children = d.setdefault(elements[-1], {kids: {}})[kids] 157 d[elements[-1]].update({kids: children, 'data': value}) 158 159 def __getitem__(self, key): | 1# Contributors Listed Below - COPYRIGHT 2016 2# [+] International Business Machines Corp. 3# 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# --- 143 unchanged lines hidden (view full) --- 152 d = self.root 153 for k in elements[:-1]: 154 d = d.setdefault(k, {kids: {}})[kids] 155 156 children = d.setdefault(elements[-1], {kids: {}})[kids] 157 d[elements[-1]].update({kids: children, 'data': value}) 158 159 def __getitem__(self, key): |
160 return self.cache[key] | 160 if key in self.cache: 161 return self.cache[key] |
161 | 162 |
163 return self._get_node(key).get('data') 164 |
|
162 def setdefault(self, key, default): 163 if not self.get(key): 164 self.__setitem__(key, default) 165 166 return self.__getitem__(key) 167 168 def get(self, key, default=None): 169 try: --- 58 unchanged lines hidden --- | 165 def setdefault(self, key, default): 166 if not self.get(key): 167 self.__setitem__(key, default) 168 169 return self.__getitem__(key) 170 171 def get(self, key, default=None): 172 try: --- 58 unchanged lines hidden --- |