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