MCPcopy Create free account
hub / github.com/PageBot/PageBot / copy

Method copy

Lib/pagebot/elements/element.py:1338–1371  ·  view source on GitHub ↗

Answers a full copy of self, where the "unique" fields are set to default. Also perform a deep copy on all child elements. >>> e1 = Element(name='Child', w=100) >>> e = Element(name='Parent', elements=[e1], w=200) >>> copyE = e.copy() >>> copyE.name == e.name

(self, parent=None)

Source from the content-addressed store, hash-verified

1336 appropriate. Default behavior of Element is to do nothing."""
1337
1338 def copy(self, parent=None):
1339 """Answers a full copy of self, where the "unique" fields are set to
1340 default. Also perform a deep copy on all child elements.
1341
1342 >>> e1 = Element(name='Child', w=100)
1343 >>> e = Element(name='Parent', elements=[e1], w=200)
1344 >>> copyE = e.copy()
1345 >>> copyE.name == e.name, copyE.eId == e.eId
1346 (True, False)
1347 >>> # Element tree is copied
1348 >>> copyE is e, copyE['Child'] is e['Child']
1349 (False, False)
1350 >>> # Values are copied
1351 >>> copyE.name == e.name, copyE.w == e.w == 200, copyE['Child'].w == e['Child'].w == 100
1352 (True, True, True)
1353 >>> e.copy().eId != e.eId
1354 True
1355 """
1356 # Deep-copies the element. Set the parent (if defined) and iterate
1357 # through the child tree to make a e.eId unique.
1358
1359 savedElements = self._elements # Avoid deep copy on child elements
1360 self._elements = []
1361 copied = copy.deepcopy(self)
1362 self._elements = savedElements
1363
1364 # Set some attributes on the copy
1365 copied._eId = uniqueID()
1366
1367 if parent is not None:
1368 copied.parent = parent
1369 for e in self.elements:
1370 copied.appendElement(e.copy())
1371 return copied
1372
1373 # C H I L D E L E M E N T P O S I T I O N S
1374

Callers 3

__init__Method · 0.45
_set_bordersMethod · 0.45
_set_templateMethod · 0.45

Calls 2

uniqueIDFunction · 0.90
appendElementMethod · 0.45

Tested by

no test coverage detected