本文整理汇总了Python中iron.dispatcher.Dispatcher.send方法的典型用法代码示例。如果您正苦于以下问题:Python Dispatcher.send方法的具体用法?Python Dispatcher.send怎么用?Python Dispatcher.send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iron.dispatcher.Dispatcher
的用法示例。
在下文中一共展示了Dispatcher.send方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runTest
# 需要导入模块: from iron.dispatcher import Dispatcher [as 别名]
# 或者: from iron.dispatcher.Dispatcher import send [as 别名]
def runTest( self ):
c = Context( 'Root' )
c.start()
o0 = self.TestObj()
Dispatcher.add( obj=o0, parentObj=None, context=c )
o1 = self.TestObj()
Dispatcher.add( obj=o1, parentObj=None, context=c )
Dispatcher.addListener( srcObj=o1, dstObj=o0 )
Dispatcher.send( event=Event( '1' ), srcObj=o0, dstObj=o1 )
assert( str(o1.lastHandler) == 'on1' )
Dispatcher.queue( event=Event( '2' ), srcObj=o0, dstObj=o1 )
#assert( str(o1.lastHandler) == 'on2' )
Dispatcher.send( event=Event( '3' ), srcObj=o0, dstObj=o1 )
#assert( str(o1.lastHandler) == 'on3' )
Dispatcher.notify( event=Event( '4' ), srcObj=o1 )
#assert( str(o1.lastHandler) == 'on4' )
Dispatcher.notify( event=Event( '4' ), srcObj=o1 )
#assert( str(o1.lastHandler) == 'on4' )
c.stop()
示例2: runTest
# 需要导入模块: from iron.dispatcher import Dispatcher [as 别名]
# 或者: from iron.dispatcher.Dispatcher import send [as 别名]
def runTest( self ):
c = Context( 'Root' )
c.start()
l = TestListener()
Dispatcher.add( l, context = c )
config = TestConfiguration()
e = NetEvent( NetEvent.EVENT_BIND, transport='tcp', localAddress=config.query( 'network.localAddress' ), localPort=config.query( 'network.localPort' ) )
o = TcpBinding( e )
Dispatcher.add( o, context=c )
Dispatcher.addListener( o, l )
o.addConfiguration( config )
e = NetEvent( NetEvent.EVENT_BIND, transport='tcp', localAddress=config.query( 'network.localAddress' ), localPort=config.query( 'network.localPort' ) )
Dispatcher.send( e, srcObj=l, dstObj=o )
sleep( config.query( 'test.timeout' ) )
packet = '' \
'REGISTER sip:sip.example.com SIP/2.0\r\n' \
'Via: SIP/2.0/UDP 192.168.1.1:5060;rport;branch=z9hG4bK58790139-438475846\r\n' \
'Max-Forwards: 70\r\n' \
'Allow: INVITE,BYE,CANCEL,ACK,INFO,PRACK,OPTIONS,SUBSCRIBE,NOTIFY,PUBLISH,MESSAGE,REFER,REGISTER,UPDATE\r\n' \
'Supported: path,replaces,norefersub\r\n' \
'User-Agent: IMS Phone 49\r\n' \
'From: <sip:[email protected]>;tag=UA_58790139-438475847\r\n' \
'To: <sip:[email protected]>\r\n' \
'Call-ID: 58790139-438475845\r\n' \
'CSeq: 1 REGISTER\r\n' \
'Expires: 3600\r\n' \
'Contact: 1<sip:[email protected]:5060;transport=tcp>;expires=3600\r\n' \
'Authorization: Digest username="1",realm="sip.example.com",nonce="",uri="sip:sip.example.com",response=""\r\n' \
'Content-Length: 0\r\n' \
'\r\n'
e = NetEvent( BindingBase.EVENT_QUEUE, transport='tcp', localAddress=config.query( 'network.localAddress' ), localPort=config.query( 'network.localPort' ), remoteAddress=config.query( 'network.remoteAddress' ), remotePort=config.query( 'network.remotePort' ), packet=packet )
Dispatcher.send( e, srcObj=l, dstObj=o )
sleep( config.query( 'test.timeout' ) )
e = NetEvent( BindingBase.EVENT_WRITE, transport='tcp', localAddress=config.query( 'network.localAddress' ), localPort=config.query( 'network.localPort' ), remoteAddress=config.query( 'network.remoteAddress' ), remotePort=config.query( 'network.remotePort' ) )
Dispatcher.send( e, srcObj=l, dstObj=o )
sleep( config.query( 'test.timeout' ) )
e = NetEvent( BindingBase.EVENT_READ, transport='tcp', localAddress=config.query( 'network.localAddress' ), localPort=config.query( 'network.localPort' ), remoteAddress=config.query( 'network.remoteAddress' ), remotePort=config.query( 'network.remotePort' ) )
Dispatcher.send( e, srcObj=l, dstObj=o )
sleep( config.query( 'test.timeout' ) )
e = NetEvent( NetEvent.EVENT_UNBIND, transport='tcp', localAddress=config.query( 'network.localAddress' ), localPort=config.query( 'network.localPort' ) )
Dispatcher.send( e, srcObj=l, dstObj=o )
sleep( config.query( 'test.timeout' ) )
c.stop()
示例3: onTxPacket
# 需要导入模块: from iron.dispatcher import Dispatcher [as 别名]
# 或者: from iron.dispatcher.Dispatcher import send [as 别名]
def onTxPacket( self, event ):
event.id = BindingBase.EVENT_QUEUE
name = Network.getBindingName( event.transport, event.localAddress, event.localPort )
binding = self.bindings[name]
if binding:
Dispatcher.send( event, srcObj=self, dstObj=binding )
else:
for binding in self.bindings.itervalues():
result = Dispatcher.send( event, srcObj=self, dstObj=binding )
if result:
break
示例4: onBind
# 需要导入模块: from iron.dispatcher import Dispatcher [as 别名]
# 或者: from iron.dispatcher.Dispatcher import send [as 别名]
def onBind( self, event ):
name = str(event.transport) + ':' + str(event.localAddress) + ':' + str(event.localPort)
binding = Binding( event )
Dispatcher.add( binding, parentObj=self )
Dispatcher.addListener( binding, self )
name = Network.getBindingName( event.transport, event.localAddress, event.localPort )
self.bindings[name] = binding
Dispatcher.send( event, srcObj=self, dstObj=binding )
if not self.__thread:
self.__thread = Thread( None, self.run )
self.__thread.start()
示例5: accept
# 需要导入模块: from iron.dispatcher import Dispatcher [as 别名]
# 或者: from iron.dispatcher.Dispatcher import send [as 别名]
def accept( self ):
if self.socket:
(newSocket, remote) = self.socket.accept()
connection = TcpConnection( self.transport, self.localAddress, self.localPort, remoteAddress=remote[0], remotePort=remote[1], csocket=newSocket )
Dispatcher.add( connection, parentObj=self )
Dispatcher.addListener( connection, self )
name = Network.getBindingName( connection.transport, connection.remoteAddress, connection.remotePort )
self.connections[name] = connection
# Send the TCP connection's connected notification to ourselves.
# This is a work-around, since we are constructing the connection in the connected state and
# we do not want to send the event in the TCP connection's constructor.
newEvent = NetEvent( NetEvent.EVENT_CONNECTED, connection.transport, connection.localAddress, connection.localPort, connection.remoteAddress, connection.remotePort, connection=connection )
Dispatcher.send( newEvent, srcObj=self, dstObj=self )
示例6: inBound_onQueue
# 需要导入模块: from iron.dispatcher import Dispatcher [as 别名]
# 或者: from iron.dispatcher.Dispatcher import send [as 别名]
def inBound_onQueue( self, event ):
if not event.connection:
if ( event.localAddress != self.localAddress ) or ( event.localPort != self.localPort ):
# This is not our binding.
return
# Let the network layer choose the local port.
event.localPort = 0
# Create a new connection and queue the event in the connection.
connection = TcpConnection( event.transport, event.localAddress, event.localPort, event.remoteAddress, event.remotePort )
Dispatcher.add( connection, parentObj=self )
Dispatcher.addListener( connection, self )
name = Network.getBindingName( connection.transport, connection.remoteAddress, connection.remotePort )
self.connections[name] = connection
Dispatcher.send( event, srcObj=self, dstObj=connection )
示例7: run
# 需要导入模块: from iron.dispatcher import Dispatcher [as 别名]
# 或者: from iron.dispatcher.Dispatcher import send [as 别名]
def run( self ):
while True:
timeout = self.query( 'network.selecttimeout' )
readSet = set()
writeSet = set()
errorSet = set()
#FIXME: There needs to be locking here since a socket can
# be killed while we are enumerating.
for binding in self.bindings.itervalues():
binding.getReadyBindings( readSet, writeSet, errorSet )
read = [ binding for binding in readSet ]
write = [ binding for binding in writeSet ]
error = [ binding for binding in errorSet ]
if len(errorSet) or len(readSet) or len(writeSet):
read, write, error = select( read, write, error, timeout )
for binding in read:
event = Event( binding.EVENT_READ )
Dispatcher.send( event, srcObj=self, dstObj=binding )
for binding in write:
event = Event( binding.EVENT_WRITE )
Dispatcher.send( event, srcObj=self, dstObj=binding )
for binding in error:
event = Event( binding.EVENT_ERROR )
Dispatcher.send( event, srcObj=self, dstObj=binding )
else:
sleep( timeout )
示例8: onUnbind
# 需要导入模块: from iron.dispatcher import Dispatcher [as 别名]
# 或者: from iron.dispatcher.Dispatcher import send [as 别名]
def onUnbind( self, event ):
name = Network.getBindingName( event.transport, event.localAddress, event.localPort )
binding = self.bindings[name]
if binding:
Dispatcher.send( event, srcObj=self, dstObj=binding )
del self.bindings[ name ]