Improve Path.__contains__ check.
This commit is contained in:
parent
0cfaf72347
commit
e478aca497
1 changed files with 11 additions and 3 deletions
|
@ -33,9 +33,17 @@ class Path:
|
||||||
self.absolute_path = path
|
self.absolute_path = path
|
||||||
|
|
||||||
def __contains__(self, other):
|
def __contains__(self, other):
|
||||||
if isinstance(other, Path):
|
if isinstance(other, str):
|
||||||
other = other.normcase
|
other_norm = os.path.normcase(other)
|
||||||
return other.startswith(self.normcase)
|
elif isinstance(other, Path):
|
||||||
|
other_norm = other.normcase
|
||||||
|
else:
|
||||||
|
raise TypeError(other)
|
||||||
|
|
||||||
|
self_norm = self.normcase
|
||||||
|
if not self_norm.endswith(os.sep):
|
||||||
|
self_norm += os.sep
|
||||||
|
return other_norm.startswith(self_norm)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if not hasattr(other, 'absolute_path'):
|
if not hasattr(other, 'absolute_path'):
|
||||||
|
|
Loading…
Reference in a new issue