[ANN] regobj - Pythonic object-based access to the Windows Registry

Glenn Linderman v+python at g.nevcal.com
Mon May 4 13:09:42 EDT 2009

On approximately 5/3/2009 7:35 AM, came the following characters from 
the keyboard of Ryan Kelly:
> Hi All,
>   I've just released the results of a nice Sunday's coding, inspired by
> one too many turns at futzing around with the _winreg module.  The
> "regobj" module brings a convenient and clean object-based API for
> accessing the Windows Registry.

Sounds very interesting, Ryan.  Just a couple questions about the 
dictionary interface.

> If a subkey is assigned a dictionary, the structure of that dictionary
> is copied into the subkey.  Scalar values become key values, while
> nested  dictionaries create subkeys:
>   >>> HKCU.Software.MyTests = {"val1":7, "stuff":{"a":1,"c":2,"e":3}}
>   >>> [v.name for v in HKCU.Software.MyTests.values()]
>   ['val1']
>   >>> [k.name for k in HKCU.Software.MyTests.subkeys()]
>   ['stuff']
>   >>> len(HKCU.Software.MyTests.stuff)
>   3
> Any other value assigned to a subkey will become the default value for
> that key (i.e. the value with name ""):
>   >>> HKCU.Software.MyTests = "dead parrot"
>   >>> HKCU.Software.MyTests[""].data
>   u'dead parrot'

I could see how you could map  numbers to DWORD, 2.x str/3.x bytes to 
binary, and 2.x unicode/3.x str to REG_SZ.  But you don't document such 
a translation, so it is unclear exactly what you actually do.  This 
would be somewhat weird in 2.x, though, where str commonly would want to 
map to String rather than Binary.

It seems almost necessary to add an explanation of whatever mapping is 
presently done, to have complete documentation.

Thinking more, I wonder if it is possible to create objects of type 
Value to put in the dictionary to allow specification of multistring and 
expandablestring Registry types, but then the dictionary name would have 
to be redundant with the name attribute in the Value object.  Maybe a 
nameless value type could be invented, with just type and data attributes?

Then the dictionary could be populated with numbers (mapped to DWORD) 
str or unicode items (mapped to String), [3.x only] bytes (mapped to 
Binary), or nameless value objects (which map to their internal types).

This would allow a bidirectional conversion between dictionaries and 
registry keys... when asking for the value of a key, one could return a 
dictionary of nameless value types... and allow iterations over that.

Subkeys could be a tuple with the type of key, and the value of a key 

Well, these are just thoughts.  I don't know if they would increase or 
decrease the Pythonicity of your design, which certainly sounds better 
than using _winreg, to me.

Glenn -- http://nevcal.com/
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

More information about the Python-list mailing list