def set_subkey(self,name,value=None):
self.sam |= KEY_CREATE_SUB_KEY<EOL>subkey = Key(name,self)<EOL>try:<EOL><INDENT>subkey = self.get_subkey(name)<EOL><DEDENT>except AttributeError:<EOL><INDENT>_winreg.CreateKey(self.hkey,name)<EOL>subkey = self.get_subkey(name)<EOL><DEDENT>if value is None:<EOL><INDENT>pass<EOL><DEDENT>elif issubclass(type(value),type) and issubclass(value,Key):<EOL><INDENT>pass<EOL><DEDENT>elif isinstance(value,Key):<EOL><INDENT>for v in value.values():<EOL><INDENT>subkey[v.name] = v<EOL><DEDENT>for k in value.subkeys():<EOL><INDENT>subkey.set_subkey(k.name,k)<EOL><DEDENT><DEDENT>elif isinstance(value,dict):<EOL><INDENT>for (nm,val) in value.items():<EOL><INDENT>if isinstance(val,dict):<EOL><INDENT>subkey.set_subkey(nm,val)<EOL><DEDENT>elif isinstance(val,Key):<EOL><INDENT>subkey.set_subkey(nm,val)<EOL><DEDENT>elif issubclass(type(val),type) and issubclass(val,Key):<EOL><INDENT>subkey.set_subkey(nm,val)<EOL><DEDENT>else:<EOL><INDENT>subkey[nm] = val<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>if not isinstance(value,Value):<EOL><INDENT>value = Value(value)<EOL><DEDENT>subkey[value.name] = value<EOL><DEDENT>
Create the named subkey and set its value.

        There are several different ways to specify the new contents of
        the named subkey:

          * if 'value' is the Key class, a subclass thereof, or None, then
            the subkey is created but not populated with any data.
          * if 'value' is a key instance,  the data from that key will be
            copied into the new subkey.
          * if 'value' is a dictionary, the dict's keys are interpreted as
            key or value names and the corresponding entries are created
            within the new subkey - nested dicts create further subkeys,
            while scalar values create values on the subkey.
          * any other value will be converted to a Value object and assigned
            to the default value for the new subkey.