MCPcopy Create free account
hub / github.com/FlightGear/flightgear / MutableVirtualPath

Class MutableVirtualPath

scripts/python/TerraSync/terrasync/virtual_path.py:457–495  ·  view source on GitHub ↗

Mutable subclass of VirtualPath. Contrary to VirtualPath objects, instances of this class can be modified in-place with the /= operator, in order to append path components. The price to pay for this advantage is that they can't be used as dictionary keys or as elements of a set or f

Source from the content-addressed store, hash-verified

455
456
457class MutableVirtualPath(VirtualPath):
458
459 """Mutable subclass of VirtualPath.
460
461 Contrary to VirtualPath objects, instances of this class can be
462 modified in-place with the /= operator, in order to append path
463 components. The price to pay for this advantage is that they can't
464 be used as dictionary keys or as elements of a set or frozenset,
465 because they are not hashable.
466
467 """
468
469 __hash__ = None # ensure the type is not hashable
470
471 def _normalize(self):
472 self._path = self.normalizeStringPath(self._path)
473
474 def __itruediv__(self, s):
475 """Path concatenation with the '/=' operator.
476
477 's' must be a string representing a relative path using the '/'
478 separator, for instance "dir/subdir/other-subdir".
479
480 """
481 # This check could of course be skipped if it is found to really affect
482 # performance.
483 self._check()
484 assert not (s.startswith('/') or s.endswith('/')), repr(s)
485
486 if self._path == '/':
487 self._path += s
488 else:
489 self._path += '/' + s
490
491 # Collapse multiple slashes, remove trailing '/' except if the whole
492 # path is '/', etc.
493 self._normalize()
494
495 return self
496
497
498if __name__ == "__main__":

Callers 3

test_mixedComparisonsMethod · 0.90

Calls

no outgoing calls

Tested by 3

test_mixedComparisonsMethod · 0.72