-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Repeating.has_children() method (#240)
- Loading branch information
Showing
6 changed files
with
69 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,33 @@ | ||
import time | ||
import typing | ||
from functools import reduce | ||
|
||
from stere import Stere | ||
|
||
|
||
def rgetattr(obj, attr, *args): | ||
"""A nested getattr""" | ||
def _getattr(obj, attr): | ||
return getattr(obj, attr, *args) | ||
return reduce(_getattr, [obj] + attr.split('.')) | ||
|
||
|
||
def _retry(fn, retry_time: typing.Optional[int] = None) -> bool: | ||
"""Retry a function for a specific amount of time. | ||
Returns: | ||
True if the function returns a truthy value, else False | ||
Arguments: | ||
fn (function): Function to retry | ||
retry_time: Number of seconds to retry. If not specified, | ||
Stere.retry_time will be used. | ||
""" | ||
retry_time = retry_time or Stere.retry_time | ||
end_time = time.time() + retry_time | ||
|
||
while time.time() < end_time: | ||
if fn(): | ||
return True | ||
return False |
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