lldb.formatters.attrib_fromdict

Package lldb :: Package formatters :: Module attrib_fromdict |
[hide private]
[frames] | no frames]

# Source Code for Module lldb.formatters.attrib_fromdict

     1  """
     2  Objective-C runtime wrapper for use by LLDB Python formatters
     3
     4  part of The LLVM Compiler Infrastructure
     5  This file is distributed under the University of Illinois Open Source
     6  License. See LICENSE.TXT for details.
     7  """
     8
     9
    10 -class AttributesDictionary:
    11
    12 -    def __init__(self, allow_reset=True):
    13          # need to do it this way to prevent endless recursion
    14          self.__dict__['_dictionary'] = {}
    15          self.__dict__['_allow_reset'] = allow_reset
    16
    17 -    def __getattr__(self, name):
    18          if not self._check_exists(name):
    19              return None
    20          value = self._dictionary[name]
    21          return value
    22
    23 -    def _set_impl(self, name, value):
    24          self._dictionary[name] = value
    25
    26 -    def _check_exists(self, name):
    27          return name in self._dictionary
    28
    29 -    def __setattr__(self, name, value):
    30          if self._allow_reset:
    31              self._set_impl(name, value)
    32          else:
    33              self.set_if_necessary(name, value)
    34
    35 -    def set_if_necessary(self, name, value):
    36          if not self._check_exists(name):
    37              self._set_impl(name, value)
    38              return True
    39          return False
    40
    41 -    def __len__(self):
    42          return len(self._dictionary)
    43