Guest User

Untitled

a guest
Feb 18th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. def copy(self, destination):
  2.  
  3. new_obj = self.__new__(self.__class__)
  4. new_obj.__dict__['data'] = {}
  5.  
  6. for field in self.__dict__.keys():
  7. if not field.startswith('__'):
  8. setattr(new_obj, field, self.__dict__[field])
  9.  
  10. stack = list(new_obj.data.items())
  11. parent = self
  12.  
  13. while stack:
  14. name, obj = stack.pop()
  15. if isinstance(obj, Folder):
  16. stack.extend(list(obj.items()))
  17. obj.__parent__ = parent
  18. parent = obj
  19. elif isinstance(obj, Page):
  20. obj.__parent__ = parent
  21.  
  22. destination[new_obj.__name__] = new_obj
Add Comment
Please, Sign In to add comment