Revision fde0203b lib/utils.py
b/lib/utils.py | ||
---|---|---|
55 | 55 |
import sha |
56 | 56 |
sha1 = sha.new |
57 | 57 |
|
58 |
try: |
|
59 |
import functools |
|
60 |
except ImportError: |
|
61 |
functools = None |
|
62 |
|
|
58 | 63 |
from ganeti import errors |
59 | 64 |
from ganeti import constants |
60 | 65 |
|
... | ... | |
1501 | 1506 |
return False |
1502 | 1507 |
|
1503 | 1508 |
|
1509 |
# Even though we're using Python's built-in "partial" function if available, |
|
1510 |
# this one is always defined for testing. |
|
1511 |
def _partial(func, *args, **keywords): # pylint: disable-msg=W0622 |
|
1512 |
"""Decorator with partial application of arguments and keywords. |
|
1513 |
|
|
1514 |
This function was copied from Python's documentation. |
|
1515 |
|
|
1516 |
""" |
|
1517 |
def newfunc(*fargs, **fkeywords): |
|
1518 |
newkeywords = keywords.copy() |
|
1519 |
newkeywords.update(fkeywords) |
|
1520 |
return func(*(args + fargs), **newkeywords) # pylint: disable-msg=W0142 |
|
1521 |
|
|
1522 |
newfunc.func = func |
|
1523 |
newfunc.args = args |
|
1524 |
newfunc.keywords = keywords |
|
1525 |
return newfunc |
|
1526 |
|
|
1527 |
|
|
1528 |
if functools is None: |
|
1529 |
partial = _partial |
|
1530 |
else: |
|
1531 |
partial = functools.partial |
|
1532 |
|
|
1533 |
|
|
1504 | 1534 |
def SingleWaitForFdCondition(fdobj, event, timeout): |
1505 | 1535 |
"""Waits for a condition to occur on the socket. |
1506 | 1536 |
|
Also available in: Unified diff