-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support
functools.partial
handlers
Handlers can now be wrapped by `functools.partial`, and take arbitrary arguments.
- Loading branch information
1 parent
2e9d265
commit 4becf5a
Showing
8 changed files
with
177 additions
and
9 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
from functools import partial | ||
from typing import Tuple | ||
|
||
__ATTR_MARK_NAME = "_xml_handlers_on" | ||
|
||
|
||
def _unwrap_partials(obj: object) -> object: | ||
if isinstance(obj, partial): | ||
return obj.func | ||
return obj | ||
|
||
|
||
def has_marks(obj: object) -> bool: | ||
return hasattr(obj, __ATTR_MARK_NAME) | ||
return hasattr(_unwrap_partials(obj), __ATTR_MARK_NAME) | ||
|
||
|
||
def get_marks(obj: object) -> Tuple[Tuple[str, ...], ...]: | ||
return getattr(obj, __ATTR_MARK_NAME, ()) | ||
return getattr(_unwrap_partials(obj), __ATTR_MARK_NAME, ()) | ||
|
||
|
||
def add_mark(obj: object, mark: Tuple[str, ...]) -> None: | ||
obj = _unwrap_partials(obj) | ||
marks = get_marks(obj) | ||
marks += (mark,) | ||
setattr(obj, __ATTR_MARK_NAME, marks) |
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