From 5aadc31fdff35e9025509d49069920e9e18e8b45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AB=B9=E6=B0=B8=E5=BA=B7?= Date: Mon, 20 May 2024 08:57:03 +0800 Subject: [PATCH] 1.0.14 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.Optimize the logic block of importing actual code. 2.Optimize `MasqueradeClass`. 3.Fix a line break error. 4.Improve line break formatting in one place. 5.Correct a formatting error. 1.优化导入真实代码的逻辑块。 2.优化 `MasqueradeClass`。 3.纠正一处换行错误。 4.改进一处换行格式。 5.纠正一处格式错误。 --- LICENSE | 2 +- setup.py | 5 +++-- systempath/__init__.py | 23 ++++++++++------------- systempath/i systempath.py | 29 +++++++++++++++++++++-------- 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/LICENSE b/LICENSE index 8e8f45c..764fe3a 100644 --- a/LICENSE +++ b/LICENSE @@ -187,7 +187,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright (c) 2022, 2023 GQYLPY . All rights reserved. + Copyright (c) 2022-2024 GQYLPY . All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/setup.py b/setup.py index d02b47b..1548501 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ long_description=open('README.md', encoding='utf8').read(), long_description_content_type='text/markdown', packages=[i.__name__], - python_requires='>=3.8, <4', + python_requires='>=3.8', install_requires=[x.decode() for x in Content('requirements.txt') if x], classifiers=[ 'Development Status :: 4 - Beta', @@ -45,6 +45,7 @@ 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', - 'Programming Language :: Python :: 3.12' + 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3.13' ] ) diff --git a/systempath/__init__.py b/systempath/__init__.py index 16857ed..7da9a0c 100644 --- a/systempath/__init__.py +++ b/systempath/__init__.py @@ -18,12 +18,12 @@ >>> file.open.rb().read() b'GQYLPY \xe6\x94\xb9\xe5\x8f\x98\xe4\xb8\x96\xe7\x95\x8c' - @version: 1.0.13 + @version: 1.0.14 @author: 竹永康 @source: https://github.com/gqylpy/systempath ──────────────────────────────────────────────────────────────────────────────── -Copyright (c) 2022, 2023 GQYLPY . All rights reserved. +Copyright (c) 2022-2024 GQYLPY . All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -571,8 +571,8 @@ def lchown(self, uid: int, gid: int) -> None: def chflags(self, flags: int) -> None: """" - Set the flag for the file or directory, different flag have different - attributes. Call `os.chflags` internally. + Set the flag for the file or directory, different flag have + different attributes. Call `os.chflags` internally. @param flags Specify numeric flag, can be the inclusive-or(`|`) of: @@ -1592,12 +1592,9 @@ class _xe6_xad_x8c_xe7_x90_xaa_xe6_x80_xa1_xe7_x8e_xb2_xe8_x90_x8d_xe4_xba_x91: gcode = __import__(gpath, fromlist=...) for gname in gpack: - try: - assert gname[0] != '_' - gfunc = getattr(gcode, gname) - assert gfunc.__module__ == gpath - except (AssertionError, AttributeError): - continue - gfunc.__module__ = __package__ - gfunc.__doc__ = gpack[gname].__doc__ - gpack[gname] = gfunc + if gname[0] != '_': + gfunc = getattr(gcode, gname, None) + if gfunc and getattr(gfunc, '__module__', None) == gpath: + gfunc.__module__ = __package__ + gfunc.__doc__ = gpack[gname].__doc__ + gpack[gname] = gfunc diff --git a/systempath/i systempath.py b/systempath/i systempath.py index f600680..1ab9425 100644 --- a/systempath/i systempath.py +++ b/systempath/i systempath.py @@ -1,5 +1,5 @@ """ -Copyright (c) 2022, 2023 GQYLPY . All rights reserved. +Copyright (c) 2022-2024 GQYLPY . All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -18,6 +18,8 @@ import warnings import functools +from copy import copy, deepcopy + from os import ( stat, lstat, stat_result, rename, renames, replace, remove, @@ -54,11 +56,11 @@ def getpwuid(_): raise NotImplementedError __read_bufsize__ = 1024 * 1024 from os.path import ( - basename, dirname, abspath, realpath, relpath, + basename, dirname, abspath, realpath, relpath, normpath, expanduser, expandvars, - join, split, splitext, splitdrive, - isabs, exists, isdir, isfile, islink, ismount, - getctime, getmtime, getatime, getsize + join, split, splitext, splitdrive, + isabs, exists, isdir, isfile, islink, ismount, + getctime, getmtime, getatime, getsize ) from shutil import move, copyfile, copytree, copystat, copymode, copy2, rmtree @@ -142,11 +144,19 @@ def __new__(mcs, __name__: str, __bases__: tuple, __dict__: dict): return cls def __hash__(cls) -> int: + if sys._getframe(1).f_code in (deepcopy.__code__, copy.__code__): + return type.__hash__(cls) return hash(cls.__masquerade_class__) def __eq__(cls, o) -> bool: return True if o is cls.__masquerade_class__ else type.__eq__(cls, o) + def __init_subclass__(mcs) -> None: + setattr(builtins, mcs.__name__, mcs) + mcs.__name__ = MasqueradeClass.__name__ + mcs.__qualname__ = MasqueradeClass.__qualname__ + mcs.__module__ = MasqueradeClass.__module__ + MasqueradeClass.__name__ = type.__name__ builtins.MasqueradeClass = MasqueradeClass @@ -708,7 +718,9 @@ def utime( class Directory(Path): - def __new__(cls, name: PathLink = '.', /, strict: bool = False, **kw): + def __new__( + cls, name: PathLink = '.', /, strict: bool = False, **kw + ) -> 'Directory': instance = Path.__new__(cls, name, strict=strict, **kw) if strict and not isdir(name): @@ -1295,8 +1307,9 @@ def __init__( if downtop is None: downtop = bottom_up - self.tree = (self.downtop if downtop else self.topdown)\ - (dirpath, level=level) + self.tree = ( + self.downtop if downtop else self.topdown + )(dirpath, level=level) self.omit_dir = omit_dir