Query object ``name`` from the directory, split and subquery on ``\\``:: >>> obj >>> obj["WindowStations"]["WinSta0"] >>> obj["WindowS
(self, name)
| 165 | raise KeyError("Could not find WinObject <{0}> under <{1}>".format(name, self.fullname)) |
| 166 | |
| 167 | def __getitem__(self, name): |
| 168 | """Query object ``name`` from the directory, split and subquery on ``\\``:: |
| 169 | |
| 170 | >>> obj |
| 171 | <KernelObject "\Windows" (type="Directory")> |
| 172 | >>> obj["WindowStations"]["WinSta0"] |
| 173 | <KernelObject "\Windows\WindowStations" (type="Directory")> |
| 174 | >>> obj["WindowStations\\WinSta0"] |
| 175 | <KernelObject "\Windows\WindowStations" (type="Directory")> |
| 176 | |
| 177 | :rtype: :class:`KernelObject` |
| 178 | :raise: :class:`KeyError` if ``name`` can not be found. |
| 179 | """ |
| 180 | if name.startswith("\\"): |
| 181 | # Are we the root directory ? |
| 182 | if not self.fullname == "\\" : |
| 183 | raise ValueError("Cannot query an object path begining by '\\' from an object other than '\\'") |
| 184 | elif name == "\\": # Ask for root ? return ourself |
| 185 | return self |
| 186 | else: |
| 187 | name = name[1:] # Strip the leading \ and go to normal case |
| 188 | obj = self |
| 189 | for part in name.split("\\"): |
| 190 | try: |
| 191 | obj = obj.get(part) |
| 192 | except gdef.NtStatusException as e: |
| 193 | if e.code == gdef.STATUS_OBJECT_TYPE_MISMATCH: |
| 194 | raise KeyError("Could not find object <{0}> under <{1}> because it is a <{2}>".format( |
| 195 | part, obj.name, obj.type)) |
| 196 | raise # Something smart to do ? |
| 197 | return obj |
| 198 | |
| 199 | |
| 200 | class ObjectManager(object): |