~diksham1/beautifulsoup/trunk

« back to all changes in this revision

Viewing changes to bs4/element.py

  • Committer: Leonard Richardson
  • Date: 2018-12-23 22:19:27 UTC
  • mfrom: (475.1.1 beautifulsoup)
  • Revision ID: leonardr@segfault.org-20181223221927-v8404xn3qi20p5em
Merged in next_previous_fixes from Isaac Muse. [bug=1782928,1798699]

Show diffs side-by-side

added added

removed removed

Lines of Context:
256
256
            self.previous_element.next_element = self
257
257
 
258
258
        self.next_element = next_element
259
 
        if self.next_element:
 
259
        if self.next_element is not None:
260
260
            self.next_element.previous_element = self
261
261
 
262
262
        self.next_sibling = next_sibling
263
 
        if self.next_sibling:
 
263
        if self.next_sibling is not None:
264
264
            self.next_sibling.previous_sibling = self
265
265
 
266
 
        if (not previous_sibling
 
266
        if (previous_sibling is None
267
267
            and self.parent is not None and self.parent.contents):
268
268
            previous_sibling = self.parent.contents[-1]
269
269
 
270
270
        self.previous_sibling = previous_sibling
271
 
        if previous_sibling:
 
271
        if previous_sibling is not None:
272
272
            self.previous_sibling.next_sibling = self
273
273
 
274
274
    nextSibling = _alias("next_sibling")  # BS3
275
275
    previousSibling = _alias("previous_sibling")  # BS3
276
276
 
277
277
    def replace_with(self, replace_with):
278
 
        if not self.parent:
 
278
        if self.parent is None:
279
279
            raise ValueError(
280
280
                "Cannot replace one element with another when the"
281
281
                "element to be replaced is not part of a tree.")
292
292
 
293
293
    def unwrap(self):
294
294
        my_parent = self.parent
295
 
        if not self.parent:
 
295
        if self.parent is None:
296
296
            raise ValueError(
297
297
                "Cannot replace an element with its contents when that"
298
298
                "element is not part of a tree.")
340
340
 
341
341
    def _last_descendant(self, is_initialized=True, accept_self=True):
342
342
        "Finds the last element beneath this object to be parsed."
343
 
        if is_initialized and self.next_sibling:
 
343
        if is_initialized and self.next_sibling is not None:
344
344
            last_child = self.next_sibling.previous_element
345
345
        else:
346
346
            last_child = self