wslwinreg
Loading...
Searching...
No Matches
wslwinreg.wslapi.PyHKEY Class Reference

A Python object representing a win32 registry key. More...

Public Member Functions

 __init__ (self, hkey, null_ok=False)
 Initialize the PyHKEY class.
 __del__ (self)
 Called when this object is garbage collected.
 Close (self)
 Closes the underlying Windows handle.
 Detach (self)
 Detaches the Windows handle from the handle object.
 __enter__ (self)
 Called when object is entered.
 __exit__ (self, exc_type, exc_value, exc_traceback)
 Release handle on class destruction.
 __hash__ (self)
 Convert the object into a hash.
 __int__ (self)
 Converting a handle to an integer returns the Win32 handle.
 __nonzero__ (self)
 Handles with an open object return true, otherwise false.
 __bool__ (self)
 Handles with an open object return true, otherwise false.
 __repr__ (self)
 Return descriptive string for the class object.
 __str__ (self)
 Return short string for the handle object.

Static Public Member Functions

 make (hkey, null_ok=None)
 Convert a pointer into a PyHKEY object.

Public Attributes

int hkey = hkey
 Integer that represents the HANDLE pointer.

Protected Member Functions

 _handle (self)
 The integer Win32 handle.

Properties

 handle = property(_handle)
 The integer Win32 handle.
 _as_parameter_
 Python sort description.

Detailed Description

A Python object representing a win32 registry key.

This object wraps a Windows HKEY object, automatically closing it when the object is destroyed. To guarantee cleanup, you can call either the Close() method on the object, or the CloseKey() function.

All registry functions in this module return one of these objects.

All registry functions in this module which accept a handle object also accept an integer, however, use of the handle object is encouraged.

Handle objects provide semantics for bool() – thus

if handle:
print("Yes")

will print Yes if the handle is currently valid (has not been closed or detached).

The object also support comparison semantics, so handle objects will compare true if they both reference the same underlying Windows handle value.

Handle objects can be converted to an integer (e.g., using the built-in int() function), in which case the underlying Windows handle value is returned. You can also use the Detach() method to return the integer handle, and also disconnect the Windows handle from the handle object.

Constructor & Destructor Documentation

◆ __init__()

wslwinreg.wslapi.PyHKEY.__init__ ( self,
hkey,
null_ok = False )

Initialize the PyHKEY class.

Parameters
hkeyInteger value representing the pointer to the HKEY
null_okTrue if None is acceptable.

Member Function Documentation

◆ __enter__()

wslwinreg.wslapi.PyHKEY.__enter__ ( self)

Called when object is entered.

Note
Needed for the Python with statement.

◆ __exit__()

wslwinreg.wslapi.PyHKEY.__exit__ ( self,
exc_type,
exc_value,
exc_traceback )

Release handle on class destruction.

Note
Needed for the Python with statement.

◆ __hash__()

wslwinreg.wslapi.PyHKEY.__hash__ ( self)

Convert the object into a hash.

Note
The implementation returns the id, which should be random enough.

◆ Close()

wslwinreg.wslapi.PyHKEY.Close ( self)

Closes the underlying Windows handle.

Note
If the handle is already closed, no error is raised.

◆ Detach()

wslwinreg.wslapi.PyHKEY.Detach ( self)

Detaches the Windows handle from the handle object.

Note
The result is the value of the handle before it is detached. If the handle is already detached, this will return zero.

After calling this function, the handle is effectively invalidated, but the handle is not closed. You would call this function when you need the underlying win32 handle to exist beyond the lifetime of the handle object.

On 64 bit windows, the result of this function is a long integer.

Returns
Previous HKEY integer.