#NEWLINE# def deepcopy( val , depth = 0 ) : #NEWLINE# #INDENT# 'Return a copy of a value. For immutable values, this returns the\n    value itself. For mutables, it returns a deep copy.\n\n    This presumes that the value is DB-storable. Therefore, the only\n    mutable types are list and dict. (And dict keys are always strings.)\n\n    We include a guard against loopy data structures. These raise\n    TypeError.\n    ' #NEWLINE# if isinstance ( val , list ) : #NEWLINE# #INDENT# if ( depth >= 8 ) : #NEWLINE# #INDENT# raise TypeError ( 'Database object cannot be recursive' ) #NEWLINE# #UNINDENT# newdepth = ( depth + 1 ) #NEWLINE# return [ deepcopy ( subval , depth = newdepth ) for subval in val ] #NEWLINE# #UNINDENT# if isinstance ( val , dict ) : #NEWLINE# #INDENT# if ( depth >= 8 ) : #NEWLINE# #INDENT# raise TypeError ( 'Database object cannot be recursive' ) #NEWLINE# #UNINDENT# newdepth = ( depth + 1 ) #NEWLINE# return { key : deepcopy ( subval , depth = newdepth ) for ( key , subval ) in val . items ( ) } #NEWLINE# #UNINDENT# return val