#NEWLINE# def set_key( self , key , value ) : #NEWLINE# #INDENT# "\n        Set the given ``key`` to the given ``value``. Handles nested\n        keys, e.g.::\n\n            d = AttrDict()\n            d.set_key('foo.bar', 1)\n            d.foo.bar == 1  # True\n\n        " #NEWLINE# if ( '.' in key ) : #NEWLINE# #INDENT# ( key , remainder ) = key . split ( '.' , 1 ) #NEWLINE# try : #NEWLINE# #INDENT# self [ key ] . set_key ( remainder , value ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# self [ key ] = AttrDict ( ) #NEWLINE# self [ key ] . set_key ( remainder , value ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# if ( self [ key ] is None ) : #NEWLINE# #INDENT# self [ key ] = AttrDict ( ) #NEWLINE# self [ key ] . set_key ( remainder , key ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise KeyError ( 'Cannot set nested key on non-dict key.' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# self [ key ] = value