[Python-Dev] winreg

Thomas Heller thomas.heller@ion-tof.com
Tue, 27 Jun 2000 13:09:24 +0200


> > I've just had a chance to look at the winreg module. I think that it is
> > too low-level.
>
> I agree.  There was a proposal (from Thomas Heller, IIRC) to do just this.
> I successfully argued there should be _2_ modules for Python - the raw
> low-level API, which guarantees you can do (almost) anything.  A
> higher-level API could cover the 80% of cases.  It is probably worth
> getting in touch with Thomas - he may be able to dig up his proposed
> high-level API.  Ive CCd him on this message [I hope is _was_ you Thomas -
> otherwise you will be wondering WTF I am on about :]
Yes, it was me :-)

Here is the 3. (final?) proposal, earlier ones are in the archives:
http://www.python.org/pipermail/python-dev/2000-February/003417.html
and
http://www.python.org/pipermail/python-dev/2000-February/003472.html

----------------------------------------------------------------------
winreg - windows registry access module

Exception:
  error - raised when a function fails. Will contain
    a windows error code and a textual description.

Objects:
  regkey object - represents a open key in the
  registry.

Functions:
  OpenKey (name) -> regkey object
    Opens an existing key with the specified access rights
    and returns a regkey object.
    name is specified like "HKLM\Software\Python"
    or "HKEY_LOCAL_MACHINE\Software\Python"

  CreateKey (name) -> regkey object
    Creates a new key or opens an existing one
    and returns a regkey object.
    For the name format see OpenKey

regkey object methods:
  Standard Mapping protocol:
  len (r)
  r[k]
  r[k] = x
  del r[k]
  r.clear()
  r.has_key(k)
  r.items()
  r.keys()
  r.update(dict)
  r.values()
  r.get(k[, x])

  todict() -> dictionary
    Returns a dictionary mapping value names to values.

  SubKeys () -> sequence
    Returns a sequence containing the names of all subkeys.

  DeleteKey (name [,recursive=0])
    If recursive is 0, deletes the named key if no subkeys exist.
    If there are subkeys an error is raised.
    If recursive is not 0, the named key is deleted
    including subkeys.

  OpenKey (name) -> regkey object
    Openes an existing subkey and returns a regkey
    object pointing to it.

  CreateKey (name) -> regkey object
    Creates a new or openes an existing subkey and
    returns a regkey object pointing to it.

regkey objects have the following properties:
  name - the name of the RegistryKey, something
    like "HKLM\Software\Python"
  hkey - the integer keyhandle

----------------------------------------------------------------------

It would not be too much work to implement it, but
I will be away the next 20 days...

> I have no real problem with your proposed design, as long as it it written
> in Python, _using_ the low-level API.  It could be called "registry" or I
> would even be happy for "winreg.pyd" -> "_winreg.pyd" and your new module
> to be called "winreg.py"
>
If we change the name of the low level api module, we have to change
Distutils,
because it is used there. Maybe we would better use the high level api then,
but there is still this 1.5 compatibility using the win32api module.

Thomas