-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c72d7c2
commit d678465
Showing
55 changed files
with
1,425 additions
and
380 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 |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
"or'ed", | ||
"Popen", | ||
"postchangelog", | ||
"Precomp", | ||
"psutil", | ||
"pyblish", | ||
"pylint", | ||
|
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
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# -*- coding=UTF-8 -*- | ||
# pyright: strict, reportTypeCommentUsage=none,reportUnusedImport=none | ||
|
||
|
||
from ._atomic_save_path import atomic_save_path | ||
from ._cast_int import cast_int | ||
from ._cast_list import cast_list | ||
from ._cast_text import cast_text | ||
from ._compat import PY2, binary_type, text_type | ||
from ._force_rename import force_rename | ||
from ._is_file_not_found_error import is_file_not_found_error | ||
from ._iteritems import iteritems | ||
from ._iterkeys import iterkeys | ||
from ._null_time import NULL_TIME | ||
from ._timezone import TZ_CHINA, TZ_UTC, FixedTimezone |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding=UTF-8 -*- | ||
# pyright: strict, reportTypeCommentUsage=none | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
TYPE_CHECKING = False | ||
if TYPE_CHECKING: | ||
from typing import Text | ||
|
||
|
||
import contextlib | ||
from typing import Text | ||
|
||
from ._force_rename import force_rename | ||
|
||
|
||
@contextlib.contextmanager | ||
def atomic_save_path( | ||
path, | ||
temp_suffix=".tmp", | ||
backup_suffix="", | ||
): | ||
# type: (Text, Text, Text) -> ... | ||
tmp_path = path + temp_suffix | ||
yield tmp_path | ||
if backup_suffix: | ||
backup_path = path + backup_suffix | ||
try: | ||
force_rename(path, backup_path) | ||
except FileNotFoundError: | ||
pass | ||
force_rename(tmp_path, path) |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# -*- coding=UTF-8 -*- | ||
# pyright: strict, reportTypeCommentUsage=none | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
TYPE_CHECKING = False | ||
if TYPE_CHECKING: | ||
from typing import Any | ||
|
||
|
||
def cast_int(v): | ||
# type: (Any) -> int | ||
if isinstance(v, int): | ||
return v | ||
return int(v) |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding=UTF-8 -*- | ||
# pyright: strict, reportTypeCommentUsage=none | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
TYPE_CHECKING = False | ||
if TYPE_CHECKING: | ||
from typing import Any, List | ||
|
||
import sys | ||
|
||
_py2 = sys.version_info[0] == 2 | ||
|
||
|
||
if _py2: | ||
_text_type = unicode # type: ignore | ||
_binary_type = str # type: ignore | ||
else: | ||
_text_type = str | ||
_binary_type = bytes | ||
|
||
|
||
def cast_list(v): | ||
# type: (Any) -> List[Any] | ||
if v is None: | ||
return [] | ||
if isinstance(v, list): | ||
return v # type: ignore | ||
if isinstance(v, tuple): | ||
return list(v) # type: ignore | ||
return [v] |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding=UTF-8 -*- | ||
# pyright: strict, reportTypeCommentUsage=none | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
TYPE_CHECKING = False | ||
if TYPE_CHECKING: | ||
from typing import Any | ||
|
||
|
||
from ._compat import text_type, binary_type | ||
|
||
|
||
def cast_text(v): | ||
# type: (Any) -> str | ||
if isinstance(v, binary_type): | ||
return v.decode("utf-8") | ||
if isinstance(v, text_type): | ||
return v | ||
return text_type(v) |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding=UTF-8 -*- | ||
# pyright: strict, reportTypeCommentUsage=none | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
TYPE_CHECKING = False | ||
if TYPE_CHECKING: | ||
from typing import Type | ||
|
||
import sys | ||
|
||
PY2 = sys.version_info[0] == 2 | ||
|
||
|
||
def _text_type(): | ||
# type: () -> Type[str] | ||
if PY2: | ||
return unicode # type: ignore | ||
return str | ||
|
||
|
||
text_type = _text_type() | ||
|
||
|
||
def _binary_type(): | ||
# type: () -> Type[bytes] | ||
if PY2: | ||
return str # type: ignore | ||
return bytes | ||
|
||
|
||
binary_type = _binary_type() |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding=UTF-8 -*- | ||
# pyright: strict, reportTypeCommentUsage=none | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
TYPE_CHECKING = False | ||
if TYPE_CHECKING: | ||
from typing import Text | ||
|
||
import os | ||
|
||
|
||
def force_rename(src, dst): | ||
# type: (Text, Text) -> None | ||
try: | ||
os.rename(src, dst) | ||
except FileExistsError: | ||
os.unlink(dst) | ||
os.rename(src, dst) |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# -*- coding=UTF-8 -*- | ||
# pyright: strict, reportTypeCommentUsage=none | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from ._compat import PY2 | ||
|
||
|
||
def is_file_not_found_error(err): | ||
# type: (Exception) -> bool | ||
if PY2: | ||
import errno | ||
|
||
return isinstance(err, (OSError, IOError)) and (err.errno == errno.ENOENT) | ||
|
||
return isinstance(err, FileNotFoundError) |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding=UTF-8 -*- | ||
# pyright: strict, reportTypeCommentUsage=none | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
TYPE_CHECKING = False | ||
if TYPE_CHECKING: | ||
from typing import Any, Mapping, TypeVar, ItemsView | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
from ._compat import PY2 | ||
|
||
|
||
def iteritems(d): | ||
# type: (Mapping[T, Any]) -> ItemsView[T, Any] | ||
if PY2: | ||
return d.iteritems() # type: ignore | ||
return d.items() |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding=UTF-8 -*- | ||
# pyright: strict, reportTypeCommentUsage=none | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
TYPE_CHECKING = False | ||
if TYPE_CHECKING: | ||
from typing import Any, Mapping, TypeVar, KeysView | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
from ._compat import PY2 | ||
|
||
|
||
def iterkeys(d): | ||
# type: (Mapping[T, Any]) -> KeysView[T] | ||
if PY2: | ||
return d.iterkeys() # type: ignore | ||
return d.keys() |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# -*- coding=UTF-8 -*- | ||
# pyright: strict, reportTypeCommentUsage=none | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from ._timezone import TZ_UTC | ||
from datetime import datetime | ||
|
||
NULL_TIME = datetime.fromtimestamp(0, TZ_UTC) |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding=UTF-8 -*- | ||
# pyright: strict, reportTypeCommentUsage=none | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
TYPE_CHECKING = False | ||
if TYPE_CHECKING: | ||
from typing import Text, Optional | ||
|
||
from datetime import datetime, timedelta, tzinfo | ||
|
||
|
||
class FixedTimezone(tzinfo): | ||
def __init__(self, name, utcoffset): | ||
# type: (Text, timedelta) -> None | ||
self._name = name | ||
self._utcoffset = utcoffset | ||
|
||
def tzname(self, dt): | ||
# type: (Optional[datetime]) -> Text | ||
return self._name | ||
|
||
def utcoffset(self, dt): | ||
# type: (Optional[datetime]) -> timedelta | ||
return self._utcoffset | ||
|
||
def dst(self, dt): | ||
# type: (Optional[datetime]) -> timedelta | ||
return timedelta() | ||
|
||
|
||
TZ_UTC = FixedTimezone("UTC", timedelta()) | ||
TZ_CHINA = FixedTimezone("UTC+8", timedelta(hours=8)) |
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
Oops, something went wrong.