|
4 | 4 | # stored under pathlib.py.txt for later, quicker comparison
|
5 | 5 | import inspect
|
6 | 6 | import shutil
|
7 |
| - |
8 | 7 | # /bitranox addon
|
9 | 8 |
|
10 | 9 | # Original Pathlib imports
|
|
26 | 25 | # bitranox addon
|
27 | 26 | if sys.version_info < (3, 6):
|
28 | 27 | raise ImportError("pathlib3x is only compatible with Python 3.6 or newer")
|
| 28 | + |
| 29 | +if sys.version_info < (3, 10): |
| 30 | + import pathlib_original |
29 | 31 | # /bitranox addon
|
30 | 32 |
|
31 | 33 | __all__ = [
|
@@ -1064,35 +1066,38 @@ def absolute(self):
|
1064 | 1066 | return self._from_parts([self.cwd()] + self._parts)
|
1065 | 1067 |
|
1066 | 1068 | def resolve(self, strict=False):
|
1067 |
| - """ |
1068 |
| - Make the path absolute, resolving all symlinks on the way and also |
1069 |
| - normalizing it. |
1070 |
| - """ |
| 1069 | + if sys.version_info >= (3, 10): |
| 1070 | + """ |
| 1071 | + Make the path absolute, resolving all symlinks on the way and also |
| 1072 | + normalizing it. |
| 1073 | + """ |
1071 | 1074 |
|
1072 |
| - def check_eloop(e): |
1073 |
| - winerror = getattr(e, "winerror", 0) |
1074 |
| - if e.errno == ELOOP or winerror == _WINERROR_CANT_RESOLVE_FILENAME: |
1075 |
| - raise RuntimeError("Symlink loop from %r" % e.filename) |
1076 |
| - |
1077 |
| - try: |
1078 |
| - if sys.version_info >= (3, 10): |
1079 |
| - s = os.path.realpath(self, strict=strict) |
1080 |
| - else: |
1081 |
| - # bitranox - option strict will most probably not work correctly |
1082 |
| - s = os.path.realpath(self) |
1083 |
| - except OSError as e: |
1084 |
| - check_eloop(e) |
1085 |
| - raise |
1086 |
| - p = self._from_parts((s,)) |
| 1075 | + def check_eloop(e): |
| 1076 | + winerror = getattr(e, "winerror", 0) |
| 1077 | + if e.errno == ELOOP or winerror == _WINERROR_CANT_RESOLVE_FILENAME: |
| 1078 | + raise RuntimeError("Symlink loop from %r" % e.filename) |
1087 | 1079 |
|
1088 |
| - # In non-strict mode, realpath() doesn't raise on symlink loops. |
1089 |
| - # Ensure we get an exception by calling stat() |
1090 |
| - if not strict: |
1091 | 1080 | try:
|
1092 |
| - p.stat() |
| 1081 | + if sys.version_info >= (3, 10): |
| 1082 | + s = os.path.realpath(self, strict=strict) |
| 1083 | + else: |
| 1084 | + # bitranox - option strict will most probably not work correctly |
| 1085 | + s = os.path.realpath(self) |
1093 | 1086 | except OSError as e:
|
1094 | 1087 | check_eloop(e)
|
1095 |
| - return p |
| 1088 | + raise |
| 1089 | + p = self._from_parts((s,)) |
| 1090 | + |
| 1091 | + # In non-strict mode, realpath() doesn't raise on symlink loops. |
| 1092 | + # Ensure we get an exception by calling stat() |
| 1093 | + if not strict: |
| 1094 | + try: |
| 1095 | + p.stat() |
| 1096 | + except OSError as e: |
| 1097 | + check_eloop(e) |
| 1098 | + return p |
| 1099 | + else: |
| 1100 | + return pathlib_original.Path(self).resolve(strict=strict) |
1096 | 1101 |
|
1097 | 1102 | def stat(self, *, follow_symlinks=True):
|
1098 | 1103 | """
|
|
0 commit comments