forked from Delgan/loguru
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dangerous use of "importlib.reload()" in tests
It changes the global state and may cause unexpected behavior.
- Loading branch information
Showing
5 changed files
with
53 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,53 @@ | ||
import os | ||
|
||
if os.name == "nt": | ||
import win32_setctime | ||
|
||
def get_ctime(filepath): | ||
return os.stat(filepath).st_ctime | ||
def load_ctime_functions(): | ||
if os.name == "nt": | ||
import win32_setctime | ||
|
||
def set_ctime(filepath, timestamp): | ||
if not win32_setctime.SUPPORTED: | ||
return | ||
def get_ctime(filepath): | ||
return os.stat(filepath).st_ctime | ||
|
||
try: | ||
win32_setctime.setctime(filepath, timestamp) | ||
except (OSError, ValueError): | ||
pass | ||
def set_ctime(filepath, timestamp): | ||
if not win32_setctime.SUPPORTED: | ||
return | ||
|
||
try: | ||
win32_setctime.setctime(filepath, timestamp) | ||
except (OSError, ValueError): | ||
pass | ||
|
||
elif hasattr(os.stat_result, "st_birthtime"): | ||
|
||
elif hasattr(os.stat_result, "st_birthtime"): | ||
def get_ctime(filepath): | ||
return os.stat(filepath).st_birthtime | ||
|
||
def get_ctime(filepath): | ||
return os.stat(filepath).st_birthtime | ||
def set_ctime(filepath, timestamp): | ||
pass | ||
|
||
def set_ctime(filepath, timestamp): | ||
pass | ||
elif hasattr(os, "getxattr") and hasattr(os, "setxattr"): | ||
|
||
def get_ctime(filepath): | ||
try: | ||
return float(os.getxattr(filepath, b"user.loguru_crtime")) | ||
except OSError: | ||
return os.stat(filepath).st_mtime | ||
|
||
elif hasattr(os, "getxattr") and hasattr(os, "setxattr"): | ||
def set_ctime(filepath, timestamp): | ||
try: | ||
os.setxattr(filepath, b"user.loguru_crtime", str(timestamp).encode("ascii")) | ||
except OSError: | ||
pass | ||
|
||
def get_ctime(filepath): | ||
try: | ||
return float(os.getxattr(filepath, b"user.loguru_crtime")) | ||
except OSError: | ||
else: | ||
|
||
def get_ctime(filepath): | ||
return os.stat(filepath).st_mtime | ||
|
||
def set_ctime(filepath, timestamp): | ||
try: | ||
os.setxattr(filepath, b"user.loguru_crtime", str(timestamp).encode("ascii")) | ||
except OSError: | ||
def set_ctime(filepath, timestamp): | ||
pass | ||
|
||
return get_ctime, set_ctime | ||
|
||
else: | ||
|
||
def get_ctime(filepath): | ||
return os.stat(filepath).st_mtime | ||
|
||
def set_ctime(filepath, timestamp): | ||
pass | ||
get_ctime, set_ctime = load_ctime_functions() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters