Skip to content

Add __repr__ method#98

Merged
williballenthin merged 3 commits intowilliballenthin:masterfrom
MarkBaggett:master
May 5, 2020
Merged

Add __repr__ method#98
williballenthin merged 3 commits intowilliballenthin:masterfrom
MarkBaggett:master

Conversation

@MarkBaggett
Copy link
Contributor

Hello. Thank you for this module. It is IMHO the best module available for parsing registry files. Would you please consider accepting this pull request to add a __repr__ method to the objects? This will make understanding variables in debugger watch lists, ipython, jupyter notebooks and other interactive python sessions much easier.

So we get this...

>> from Registry.Registry import Registry
>>> hive = Registry("NTUSER.DAT")
>>> hive
Registry(hive_name=??\C:\Users\Win10Lab\ntuser.dat, hive_type=HiveType.NTUSER)
>>> key = hive.open(r"Software\Microsoft\Windows\CurrentVersion\Run")
>>> key
RegistryKey(name=Run, path=ROOT\SOFTWARE\Microsoft\Windows\CurrentVersion\Run)
>>> key.values()
[RegistryValue(name=OneDrive, value="C:\Users\Win10Lab\AppData\Local\Microsoft\OneDrive\OneDrive.exe" /background, type=RegSZ)]**
>>> hive.root().subkeys()
[RegistryKey(name=AppEvents, path=ROOT\AppEvents), RegistryKey(name=AppXBackupContentType, path=ROOT\AppXBackupContentType), RegistryKey(name=Console, path=ROOT\Console), RegistryKey(name=Control Panel, path=ROOT\Control Panel), RegistryKey(name=Environment, path=ROOT\Environment), RegistryKey(name=EUDC, path=ROOT\EUDC), RegistryKey(name=Keyboard Layout, path=ROOT\Keyboard Layout), RegistryKey(name=Network, path=ROOT\Network), RegistryKey(name=Printers, path=ROOT\Printers), RegistryKey(name=SOFTWARE, path=ROOT\SOFTWARE), RegistryKey(name=System, path=ROOT\System)]

Instead of this..

>>> from Registry.Registry import Registry
>>> hive = Registry("NTUSER.DAT")
>>> hive
<Registry.Registry.Registry object at 0x7f76ca6bfc88>
>>> key = hive.open(r"Software\Microsoft\Windows\CurrentVersion\Run")
>>> key
<Registry.Registry.RegistryKey object at 0x7f76ca025470>
>>> key.values()
[<Registry.Registry.RegistryValue object at 0x7f76ca0252e8>]
>>> hive.root().subkeys()
[<Registry.Registry.RegistryKey object at 0x7f76ca0253c8>, <Registry.Registry.RegistryKey object at 0x7f76ca01d198>, <Registry.Registry.RegistryKey object at 0x7f76ca01dc88>, <Registry.Registry.RegistryKey object at 0x7f76ca01de10>, <Registry.Registry.RegistryKey object at 0x7f76ca01dc50>, <Registry.Registry.RegistryKey object at 0x7f76ca01dcf8>, <Registry.Registry.RegistryKey object at 0x7f76ca01dd68>, <Registry.Registry.RegistryKey object at 0x7f76ca01dba8>, <Registry.Registry.RegistryKey object at 0x7f76ca01d9e8>, <Registry.Registry.RegistryKey object at 0x7f76ca01d908>, <Registry.Registry.RegistryKey object at 0x7f76ca01d978>]

@MarkBaggett
Copy link
Contributor Author

MarkBaggett commented May 5, 2020

Updating code to pass CI testing.

Ok I removed the use of f-strings so that it also works in python2 and older versions of Python. I think this should make it past your CI testing now.

Thanks again for your consideration.


$ python2
Python 2.7.17 (default, Nov  7 2019, 10:07:09) 
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from Registry.Registry import Registry
>>> hive=Registry("NTUSER.DAT")
>>> hive
Registry(hive_name="??\C:\Users\Win10Lab\ntuser.dat", hive_type="HiveType.NTUSER")
>>> key = hive.open(r"Software\Microsoft\Windows\CurrentVersion\Run")
>>> key
RegistryKey(name="Run", path="ROOT\SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
>>> key.subkeys()
[]
>>> key.values()
[RegistryValue(name="OneDrive", value=""C:\Users\Win10Lab\AppData\Local\Microsoft\OneDrive\OneDrive.exe" /background", type="RegSZ")]
>>> hive.root().subkeys()
[RegistryKey(name="AppEvents", path="ROOT\AppEvents"), RegistryKey(name="AppXBackupContentType", path="ROOT\AppXBackupContentType"), RegistryKey(name="Console", path="ROOT\Console"), RegistryKey(name="Control Panel", path="ROOT\Control Panel"), RegistryKey(name="Environment", path="ROOT\Environment"), RegistryKey(name="EUDC", path="ROOT\EUDC"), RegistryKey(name="Keyboard Layout", path="ROOT\Keyboard Layout"), RegistryKey(name="Network", path="ROOT\Network"), RegistryKey(name="Printers", path="ROOT\Printers"), RegistryKey(name="SOFTWARE", path="ROOT\SOFTWARE"), RegistryKey(name="System", path="ROOT\System")]
>>> 

@williballenthin
Copy link
Owner

outstanding, thanks!

@williballenthin williballenthin merged commit 24f2198 into williballenthin:master May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants