diff options
| author | jason | 2016-04-25 10:54:34 -0600 |
|---|---|---|
| committer | jason | 2016-04-25 11:01:32 -0600 |
| commit | fb4a49bf331e36447395d9d2f66e502c8122d904 (patch) | |
| tree | 1bc251fc0da2996476d351432d2d26d3786a1a04 | |
| parent | fefed8c83faf2e75f8f61e9aec1de17824e1eb8a (diff) | |
| download | eventmq-fb4a49bf331e36447395d9d2f66e502c8122d904.tar.gz eventmq-fb4a49bf331e36447395d9d2f66e502c8122d904.zip | |
update docs
| -rw-r--r-- | docs/utils/devices.rst | 3 | ||||
| -rw-r--r-- | docs/utils/index.rst (renamed from docs/utils.rst) | 0 | ||||
| -rw-r--r-- | docs/utils/settings.rst | 3 | ||||
| -rw-r--r-- | eventmq/utils/__init__.py | 8 | ||||
| -rw-r--r-- | eventmq/utils/classes.py | 125 | ||||
| -rw-r--r-- | eventmq/utils/settings.py | 4 |
6 files changed, 127 insertions, 16 deletions
diff --git a/docs/utils/devices.rst b/docs/utils/devices.rst new file mode 100644 index 0000000..ef68c27 --- /dev/null +++ b/docs/utils/devices.rst | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | .. automodule:: eventmq.utils.devices | ||
| 2 | :members: | ||
| 3 | :special-members: | ||
diff --git a/docs/utils.rst b/docs/utils/index.rst index 02904ed..02904ed 100644 --- a/docs/utils.rst +++ b/docs/utils/index.rst | |||
diff --git a/docs/utils/settings.rst b/docs/utils/settings.rst new file mode 100644 index 0000000..1334f15 --- /dev/null +++ b/docs/utils/settings.rst | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | .. automodule:: eventmq.utils.settings | ||
| 2 | :members: | ||
| 3 | :special-members: | ||
diff --git a/eventmq/utils/__init__.py b/eventmq/utils/__init__.py index cf7aeed..586b955 100644 --- a/eventmq/utils/__init__.py +++ b/eventmq/utils/__init__.py | |||
| @@ -21,9 +21,11 @@ like creating message more simple. | |||
| 21 | .. toctree :: | 21 | .. toctree :: |
| 22 | :maxdepth: 2 | 22 | :maxdepth: 2 |
| 23 | 23 | ||
| 24 | utils/classes | 24 | classes |
| 25 | utils/messages | 25 | devices |
| 26 | utils/timeutils | 26 | messages |
| 27 | settings | ||
| 28 | timeutils | ||
| 27 | """ | 29 | """ |
| 28 | 30 | ||
| 29 | 31 | ||
diff --git a/eventmq/utils/classes.py b/eventmq/utils/classes.py index 2017f1a..a966c75 100644 --- a/eventmq/utils/classes.py +++ b/eventmq/utils/classes.py | |||
| @@ -394,23 +394,40 @@ class ZMQSendMixin(object): | |||
| 394 | class EMQdeque(object): | 394 | class EMQdeque(object): |
| 395 | """ | 395 | """ |
| 396 | EventMQ deque based on python's collections.deque with full and | 396 | EventMQ deque based on python's collections.deque with full and |
| 397 | programmable full | 397 | programmable full. |
| 398 | |||
| 399 | .. note:: | ||
| 400 | |||
| 401 | Because of the programmable full, some of the methods that would | ||
| 402 | normally return None return a boolean value that should be captured and | ||
| 403 | checked to ensure proper error handling. | ||
| 404 | |||
| 398 | """ | 405 | """ |
| 399 | def __init__(self, full=None, pfull=None, on_full=None): | 406 | def __init__(self, full=None, pfull=None, on_full=None, initial=()): |
| 400 | """ | 407 | """ |
| 401 | |||
| 402 | Args: | 408 | Args: |
| 403 | full (int): Hard limit on deque size | 409 | full (int): Hard limit on deque size. Rejects adding elements. |
| 410 | Default: 0 - no limit | ||
| 404 | pfull (int): Programmable limit on deque size, defaults | 411 | pfull (int): Programmable limit on deque size, defaults |
| 405 | to full length | 412 | to ``full`` length |
| 406 | on_full (func): callback for on_full event | 413 | on_full (func): callback to call when ``full`` limit is hit |
| 414 | initial (iter): The initial iteratable used to contruct the deque | ||
| 407 | """ | 415 | """ |
| 408 | self.full = full if not None else 0 | 416 | self.full = full if not None else 0 |
| 409 | self.pfull = pfull if not None else full | 417 | self.pfull = pfull if not None else full |
| 410 | 418 | ||
| 411 | self._queue = deque(maxlen=self.full) | 419 | self._queue = deque(initial, maxlen=self.full) |
| 412 | self.on_full = on_full | 420 | self.on_full = on_full |
| 413 | 421 | ||
| 422 | def __str__(self): | ||
| 423 | return "{}".format(str(self._queue)) | ||
| 424 | |||
| 425 | def __unicode__(self): | ||
| 426 | return "{}".format(unicode(self._queue)) | ||
| 427 | |||
| 428 | def __repr__(self): | ||
| 429 | return "{}".format(repr(self._queue)) | ||
| 430 | |||
| 414 | def __iter__(self): | 431 | def __iter__(self): |
| 415 | return self._queue.__iter__() | 432 | return self._queue.__iter__() |
| 416 | 433 | ||
| @@ -418,7 +435,20 @@ class EMQdeque(object): | |||
| 418 | return len(self._queue) | 435 | return len(self._queue) |
| 419 | 436 | ||
| 420 | def append(self, item): | 437 | def append(self, item): |
| 421 | if len(self._queue) == self.full: | 438 | """ |
| 439 | Append item to the right this deque if the deque isn't full. | ||
| 440 | |||
| 441 | .. note:: | ||
| 442 | |||
| 443 | You should check the return value of this call and handle the cases | ||
| 444 | where False is returned. | ||
| 445 | |||
| 446 | Returns: | ||
| 447 | bool: True if ``item`` was successfully added, False if the deque | ||
| 448 | is at the ``self.full`` limit. If it is, ``self.on_full`` is | ||
| 449 | called. | ||
| 450 | """ | ||
| 451 | if self.is_full(): | ||
| 422 | if self.on_full: | 452 | if self.on_full: |
| 423 | self.on_full() | 453 | self.on_full() |
| 424 | return False | 454 | return False |
| @@ -427,28 +457,99 @@ class EMQdeque(object): | |||
| 427 | return True | 457 | return True |
| 428 | 458 | ||
| 429 | def remove(self, item): | 459 | def remove(self, item): |
| 460 | """ | ||
| 461 | Remove ``item`` from the deque. | ||
| 462 | |||
| 463 | Args: | ||
| 464 | item (object): The item to remove from the deque | ||
| 465 | """ | ||
| 430 | return self._queue.remove(item) | 466 | return self._queue.remove(item) |
| 431 | 467 | ||
| 432 | def is_full(self): | 468 | def is_full(self): |
| 433 | if self.full is not 0: | 469 | """ |
| 470 | Check to see if the deque contains ``self.full`` items. | ||
| 471 | |||
| 472 | Returns: | ||
| 473 | bool: True if the deque contains at least ``full`` items. False | ||
| 474 | otherwise | ||
| 475 | """ | ||
| 476 | if self.full and self.full is not 0: | ||
| 434 | return len(self._queue) >= self.full | 477 | return len(self._queue) >= self.full |
| 435 | else: | 478 | else: |
| 436 | return False | 479 | return False |
| 437 | 480 | ||
| 438 | def is_empty(self): | 481 | def is_empty(self): |
| 482 | """ | ||
| 483 | Check to see if the deque contains no items. | ||
| 484 | |||
| 485 | Returns: | ||
| 486 | bool: True if the deque contains 0 items. False otherwise | ||
| 487 | """ | ||
| 439 | return len(self._queue) == 0 | 488 | return len(self._queue) == 0 |
| 440 | 489 | ||
| 441 | def is_pfull(self): | 490 | def is_pfull(self): |
| 442 | if self.pfull is not 0: | 491 | """ |
| 492 | Check to see if the deque contains ``self.pfull`` items. | ||
| 493 | |||
| 494 | Returns: | ||
| 495 | bool: True if the deque contains at least ``pfull`` items. | ||
| 496 | False otherwise | ||
| 497 | """ | ||
| 498 | if self.pfull and self.pfull is not 0: | ||
| 443 | return len(self._queue) >= self.pfull | 499 | return len(self._queue) >= self.pfull |
| 444 | else: | 500 | else: |
| 445 | return False | 501 | return False |
| 446 | 502 | ||
| 447 | def pop(self): | 503 | def pop(self): |
| 504 | """ | ||
| 505 | Returns: | ||
| 506 | object: the last (right-most) element of the deque | ||
| 507 | """ | ||
| 448 | return self._queue.pop() | 508 | return self._queue.pop() |
| 449 | 509 | ||
| 450 | def popleft(self): | 510 | def popleft(self): |
| 511 | """ | ||
| 512 | Returns: | ||
| 513 | object: the first (left-most) element of the deque | ||
| 514 | """ | ||
| 451 | return self._queue.popleft() | 515 | return self._queue.popleft() |
| 452 | 516 | ||
| 453 | def insert(self, pos, item): | 517 | def appendleft(self, item): |
| 454 | self._queue.insert(pos, item) | 518 | """ |
| 519 | Append item to the left this deque if the deque isn't full. | ||
| 520 | |||
| 521 | .. note:: | ||
| 522 | |||
| 523 | You should check the return value of this call and handle the cases | ||
| 524 | where False is returned. | ||
| 525 | |||
| 526 | Returns: | ||
| 527 | bool: True if ``item`` was successfully added, False if the deque | ||
| 528 | is at the ``self.full`` limit. If it is, ``self.on_full`` is | ||
| 529 | called. | ||
| 530 | """ | ||
| 531 | if self.is_full(): | ||
| 532 | if self.on_full: | ||
| 533 | self.on_full() | ||
| 534 | return False | ||
| 535 | else: | ||
| 536 | self._queue.appendleft(item) | ||
| 537 | return True | ||
| 538 | |||
| 539 | def extend(self, iterable): | ||
| 540 | """ | ||
| 541 | append ``iterable`` to the right (end) of the deque | ||
| 542 | |||
| 543 | Returns: | ||
| 544 | bool: True if ``item`` was successfully added, False if the deque | ||
| 545 | is at the ``self.full`` limit. If it is, ``self.on_full`` is | ||
| 546 | called. | ||
| 547 | """ | ||
| 548 | if self.full and self.full > 0 and \ | ||
| 549 | len(self._queue) + len(iterable) >= self.full: | ||
| 550 | |||
| 551 | if len(self._queue) >= self.full and self.on_full: | ||
| 552 | self.on_full() | ||
| 553 | return False | ||
| 554 | else: | ||
| 555 | self._deque.extend(iterable) | ||
diff --git a/eventmq/utils/settings.py b/eventmq/utils/settings.py index e1004d4..5c0ee85 100644 --- a/eventmq/utils/settings.py +++ b/eventmq/utils/settings.py | |||
| @@ -13,7 +13,9 @@ | |||
| 13 | # You should have received a copy of the GNU Lesser General Public License | 13 | # You should have received a copy of the GNU Lesser General Public License |
| 14 | # along with eventmq. If not, see <http://www.gnu.org/licenses/>. | 14 | # along with eventmq. If not, see <http://www.gnu.org/licenses/>. |
| 15 | """ | 15 | """ |
| 16 | :mod:'settings' -- Settings Utilities """ | 16 | :mod:`settings` -- Settings Utilities |
| 17 | ===================================== | ||
| 18 | """ | ||
| 17 | import os | 19 | import os |
| 18 | import ConfigParser | 20 | import ConfigParser |
| 19 | from .. import conf | 21 | from .. import conf |