Changeset 218


Ignore:
Timestamp:
03/30/11 11:17:26 (14 years ago)
Author:
tim
Message:

converted hive's .get_root() method into the 'root' property which is cached and better validated for user friendliness

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • test/pyregfi-smoketest.py

    r217 r218  
    1818    while p != None:
    1919        path.append(p.name)
    20         if p.is_root():
    21             break
    22         else:
    23             p = p.get_parent()
     20        p = p.get_parent()
    2421    path.reverse()
    2522    del path[0]
     
    130127# to access various base structure attributes.
    131128def recurseKeyTally(hive):
    132     root = hive.get_root()
    133     checkValues(root)
    134     recurseTree(root, checkValues)
     129    checkValues(hive.root)
     130    recurseTree(hive.root, checkValues)
    135131    print("  Key stat: %f" % recurseKey_stat)
    136132    print("  Value stat: %f" % recurseValue_stat)
     
    143139
    144140#tests = [("iterTallyNames",iterTallyNames),("iterParentWalk",iterParentWalk),("iterTallyData",iterTallyData),]
    145 tests = [("recurseKeyTally",recurseKeyTally),]
     141tests = [("recurseKeyTally",recurseKeyTally),("iterParentWalk",iterParentWalk),]
    146142
    147143files = []
  • trunk/python/pyregfi/__init__.py

    r217 r218  
    322322
    323323    def get_parent(self):
     324        if self.is_root():
     325            return None
    324326        parent_base = regfi.regfi_get_parentkey(self._hive.file, self._base)
    325327        if parent_base:
    326328            return Key(self._hive, parent_base)
    327 
    328329        return None
    329330
    330331    def is_root(self):
    331         return (self._hive.get_root() == self)
     332        return (self._hive.root == self)
    332333
    333334
     
    408409    file = None
    409410    raw_file = None
    410    
     411    _root = None
     412
    411413    def __init__(self, fh):
    412414        # The fileno method may not exist, or it may throw an exception
     
    426428
    427429    def __getattr__(self, name):
     430        if name == "root":
     431            if self._root == None:
     432                self._root = Key(self, regfi.regfi_get_rootkey(self.file))
     433            return self._root
     434
    428435        return getattr(self.file.contents, name)
    429436   
     
    435442    def __iter__(self):
    436443        return HiveIterator(self)
    437 
    438     def get_root(self):
    439         return Key(self, regfi.regfi_get_rootkey(self.file))
    440444
    441445
Note: See TracChangeset for help on using the changeset viewer.