コード例 #1
0
from __future__ import print_function

import sys
import random
from types import GeneratorType

from spinoff.util.python import enumrange
from spinoff.util.logging import dbg

(Bind, Connect, Disconnect, SigDisconnect, Send, Ping, RelaySigNew,
 RelayConnect, RelaySigConnected, RelaySend, RelayForward, RelaySigNodeDown,
 RelayNvm, Receive, SendFailed, NodeDown, NextBeat) = enumrange(
     'Bind', 'Connect', 'Disconnect', 'SigDisconnect', 'Send', 'Ping',
     'RelaySigNew', 'RelayConnect', 'RelaySigConnected', 'RelaySend',
     'RelayForward', 'RelaySigNodeDown', 'RelayNvm', 'Receive', 'SendFailed',
     'NodeDown', 'NextBeat')
IN, OUT = enumrange('IN', 'OUT')
BIG_BANG_T = -sys.maxint


def nid2addr(nid):
    return nid.rsplit('|', 1)[0]


def FLUSH(self, nid):
    for msg_h in self.queues.pop(nid, []):
        yield SendFailed, msg_h


def NODEDOWN(self, nid):
    yield FLUSH(self, nid)
コード例 #2
0
def test_enumrange_aka_enums_with_implicit_order():
    names = [_make_random_name() for _ in range(3)]
    assert [(x.order, x.name) for x in enumrange(*names)] == [(order, name) for order, name in enumerate(names)]
コード例 #3
0
ファイル: hublogic.py プロジェクト: magicbill/spinoff
import sys
import random
from types import GeneratorType

from spinoff.util.python import enumrange
from spinoff.util.logging import dbg


(
    Bind, Connect, Disconnect, SigDisconnect, Send, Ping,
    RelaySigNew, RelayConnect, RelaySigConnected, RelaySend, RelayForward, RelaySigNodeDown, RelayNvm,
    Receive, SendFailed, NodeDown, NextBeat
) = enumrange(
    'Bind', 'Connect', 'Disconnect', 'SigDisconnect', 'Send', 'Ping',
    'RelaySigNew', 'RelayConnect', 'RelaySigConnected', 'RelaySend', 'RelayForward', 'RelaySigNodeDown', 'RelayNvm',
    'Receive', 'SendFailed', 'NodeDown', 'NextBeat'
)
IN, OUT = enumrange('IN', 'OUT')
BIG_BANG_T = -sys.maxint


def nid2addr(nid):
    return nid.rsplit('|', 1)[0]


def FLUSH(self, nid):
    for msg_h in self.queues.pop(nid, []):
        yield SendFailed, msg_h