IFormatter() | |
ProtocolError | Malformed message. |
MySet(*v, **kw) | A set-like object that allows for unhashable entries. |
MyCondition([lock, verbose]) | |
IntStringFormatter | Formatter for messages of the format “%i.%s”(len(msg),msg) |
MsgQueue([maxsize]) | Implements a threadsafe message queue that allows you to add data and then yields parsed and complete messages. |
hasargs(decorator) | Meta-decorator to allow a decorator to accept kwargs or no arg (but use the default values). |
Inheritance diagram for mmf.async.utils:
Some useful non-twisted dependent utilities.
Bases: zope.interface.Interface
Bases: exceptions.Exception
Malformed message.
x.__init__(...) initializes x; see help(type(x)) for signature
Bases: list
A set-like object that allows for unhashable entries.
Methods
add(item) | |
append | L.append(object) – append object to end |
count | L.count(value) -> integer – return number of occurrences of value |
extend | L.extend(iterable) – extend list by appending elements from the iterable |
index | L.index(value, [start, [stop]]) -> integer – return first index of value. |
insert | L.insert(index, object) – insert object before index |
pop | L.pop([index]) -> item – remove and return item at index (default last). |
remove(item[, throw]) | |
reverse | L.reverse() – reverse IN PLACE |
sort | L.sort(cmp=None, key=None, reverse=False) – stable sort IN PLACE; |
update(iterable) |
Bases: threading._Condition
Methods
notify([n]) | |
notifyAll() | |
notify_all() | |
wait([timeout]) | Like regular wait, but raises and exception upon timeout. |
Bases: object
Formatter for messages of the format “%i.%s”(len(msg),msg)
>>> F = IntStringFormatter
>>> msg = F.format("Hello")
>>> msg
'5.Hello'
>>> F.split(msg)
('Hello', '')
>>> F.split("2.Hi5.There")
('Hi', '5.There')
Invalid messages will raise a ProtocolError >>> F.split(“1j.Hello”) Traceback (most recent call last):
...
ProtocolError: Received non-digit ‘j’ in message prefix ‘1j’
x.__init__(...) initializes x; see help(type(x)) for signature
Bases: Queue.Queue
Implements a threadsafe message queue that allows you to add data and then yields parsed and complete messages.
Methods
Formatter | |
empty() | Return True if the queue is empty, False otherwise (not reliable!). |
full() | Return True if the queue is full, False otherwise (not reliable!). |
get([block, timeout]) | Remove and return an item from the queue. |
get_nowait() | Remove and return an item from the queue without blocking. |
join() | Blocks until all items in the Queue have been gotten and processed. |
put(item[, block, timeout]) | Put an item into the queue. |
put_nowait(item) | Put an item into the queue without blocking. |
qsize() | Return the approximate size of the queue (not reliable!). |
task_done() | Indicate that a formerly enqueued task is complete. |
alias of IntStringFormatter
Meta-decorator to allow a decorator to accept kwargs or no arg (but use the default values). Also applies wraps.
>>> @hasargs
... def decorator_with_args(f, m=2, b=1):
... return lambda x: m*f(x) + b
>>> @decorator_with_args
... def f(x): return x**2
>>> f(2.0)
9.0
>>> @decorator_with_args(m=3, b=2)
... def f(x): return x**2
>>> f(2.0)
14.0