def deepcopy(x, memo=None, _nil=[]):
 if (memo is None):
  memo = {}
 d = id(x)
 y = memo.get(d, _nil)
 if (y is not _nil):
  return y
 cls = type(x)
 copier = _deepcopy_dispatch.get(cls)
 if copier:
  y = copier(x, memo)
 else:
  try:
   issc = issubclass(cls, type)
  except TypeError:
   issc = 0
  if issc:
   y = _deepcopy_atomic(x, memo)
  else:
   copier = getattr(x, '__deepcopy__', None)
   if copier:
    y = copier(memo)
   else:
    reductor = dispatch_table.get(cls)
    if reductor:
     rv = reductor(x)
    else:
     reductor = getattr(x, '__reduce_ex__', None)
     if reductor:
      rv = reductor(4)
     else:
      reductor = getattr(x, '__reduce__', None)
      if reductor:
       rv = reductor()
      else:
       raise Error(('un(deep)copyable object of type %s' % cls))
    if isinstance(rv, str):
     y = x
    else:
     y = _reconstruct(x, memo, *rv)
 if (y is not x):
  memo[d] = y
  _keep_alive(x, memo)
 return y

def deepcopy ( x , memo = None , _nil = [ ] ) : if ( memo is None ) : memo = { } d = id ( x ) y = memo . get ( d , _nil ) if ( y is not _nil ) : return y cls = type ( x ) copier = _deepcopy_dispatch . get ( cls ) if copier : y = copier ( x , memo ) else : try : issc = issubclass ( cls , type ) except TypeError : issc = 0 if issc : y = _deepcopy_atomic ( x , memo ) else : copier = getattr ( x , '__deepcopy__' , None ) if copier : y = copier ( memo ) else : reductor = dispatch_table . get ( cls ) if reductor : rv = reductor ( x ) else : reductor = getattr ( x , '__reduce_ex__' , None ) if reductor : rv = reductor ( 4 ) else : reductor = getattr ( x , '__reduce__' , None ) if reductor : rv = reductor ( ) else : raise Error ( ( 'un(deep)copyable object of type %s' % cls ) ) if isinstance ( rv , str ) : y = x else : y = _reconstruct ( x , memo , * rv ) if ( y is not x ) : memo [ d ] = y _keep_alive ( x , memo ) return y
returns a deep copy of the given object .