@@ -167,7 +167,12 @@ class BGPHandler(asyncore.dispatcher_with_send):
167167 yield 'notification:%d,%d' % (body [0 ], body [1 ]), bytestream (body )
168168
169169 def announce (self , * args ):
170- flushed (' ' , self .ip , self .port , ' ' .join (str (_ ) for _ in args ) if len (args ) > 1 else args [0 ])
170+ flushed (
171+ ' ' ,
172+ self .ip ,
173+ self .port ,
174+ ' ' .join (str (_ ) for _ in args ) if len (args ) > 1 else args [0 ],
175+ )
171176
172177 def check_signal (self ):
173178 if self .messages and self .messages [0 ].startswith ('signal:' ):
@@ -307,7 +312,12 @@ class BGPHandler(asyncore.dispatcher_with_send):
307312 % (
308313 self .counter ,
309314 '%s:%s:%s:%s'
310- % (bytestream (header [:16 ]), bytestream (header [16 :18 ]), bytestream (header [18 :]), bytestream (body )),
315+ % (
316+ bytestream (header [:16 ]),
317+ bytestream (header [16 :18 ]),
318+ bytestream (header [18 :]),
319+ bytestream (body ),
320+ ),
311321 )
312322 )
313323 self .send (self .keepalive )
@@ -319,7 +329,12 @@ class BGPHandler(asyncore.dispatcher_with_send):
319329 % (
320330 self .counter ,
321331 '%s:%s:%s:%s'
322- % (bytestream (header [:16 ]), bytestream (header [16 :18 ]), bytestream (header [18 :]), bytestream (body )),
332+ % (
333+ bytestream (header [:16 ]),
334+ bytestream (header [16 :18 ]),
335+ bytestream (header [18 :]),
336+ bytestream (body ),
337+ ),
323338 )
324339 )
325340 self .send (header + body )
@@ -328,7 +343,12 @@ class BGPHandler(asyncore.dispatcher_with_send):
328343 % (
329344 self .counter ,
330345 '%s:%s:%s:%s'
331- % (bytestream (header [:16 ]), bytestream (header [16 :18 ]), bytestream (header [18 :]), bytestream (body )),
346+ % (
347+ bytestream (header [:16 ]),
348+ bytestream (header [16 :18 ]),
349+ bytestream (header [18 :]),
350+ bytestream (body ),
351+ ),
332352 )
333353 )
334354 return
@@ -352,11 +372,17 @@ class BGPHandler(asyncore.dispatcher_with_send):
352372 self .announce (
353373 'received %d (%1s%s):' % (self .counter , self .options ['letter' ], self .step ),
354374 '%s:%s:%s:%s'
355- % (announcement [:32 ], announcement [32 :36 ], announcement [36 :38 ], announcement [38 :]),
375+ % (
376+ announcement [:32 ],
377+ announcement [32 :36 ],
378+ announcement [36 :38 ],
379+ announcement [38 :],
380+ ),
356381 )
357382 else :
358383 self .announce (
359- 'received %d (%1s%s):' % (self .counter , self .options ['letter' ], self .step ), announcement
384+ 'received %d (%1s%s):' % (self .counter , self .options ['letter' ], self .step ),
385+ announcement ,
360386 )
361387 self .check_signal ()
362388 else :
@@ -380,7 +406,12 @@ class BGPHandler(asyncore.dispatcher_with_send):
380406 if message .startswith ('F' * 32 ):
381407 self .announce (
382408 ' %s:%s:%s:%s'
383- % (message [:32 ], message [32 :36 ], message [36 :38 ], message [38 :])
409+ % (
410+ message [:32 ],
411+ message [32 :36 ],
412+ message [36 :38 ],
413+ message [38 :],
414+ )
384415 )
385416 else :
386417 self .announce (' %s' % message )
@@ -389,7 +420,12 @@ class BGPHandler(asyncore.dispatcher_with_send):
389420 if message .startswith ('F' * 32 ):
390421 self .announce (
391422 'expected : %s:%s:%s:%s'
392- % (message [:32 ], message [32 :36 ], message [36 :38 ], message [38 :])
423+ % (
424+ message [:32 ],
425+ message [32 :36 ],
426+ message [36 :38 ],
427+ message [38 :],
428+ )
393429 )
394430 else :
395431 self .announce ('expected : %s' % message )
@@ -520,7 +556,7 @@ class BGPServer(asyncore.dispatcher):
520556 pair = self .accept ()
521557 if pair is not None :
522558 sock , addr = pair
523- handler = BGPHandler (sock ).setup (* addr [:2 ], messages = messages , options = self .options )
559+ BGPHandler (sock ).setup (* addr [:2 ], messages = messages , options = self .options )
524560
525561
526562def drop ():
@@ -556,20 +592,22 @@ def main():
556592 flushed (
557593 'a list of expected route announcement/withdrawl in the format <number>:announce:<ipv4-route> <number>:withdraw:<ipv4-route> <number>:raw:<exabgp hex dump : separated>'
558594 )
559- flushed ('for example:' , sys .argv [0 ], '1:announce:10.0.0.0/8 1:announce:192.0.2.0/24 2:withdraw:10.0.0.0/8 ' )
595+ flushed (
596+ 'for example:' ,
597+ sys .argv [0 ],
598+ '1:announce:10.0.0.0/8 1:announce:192.0.2.0/24 2:withdraw:10.0.0.0/8 ' ,
599+ )
560600 flushed ('routes with the same <number> can arrive in any order' )
561601 sys .exit (1 )
562602
563603 options = {'sink' : False , 'echo' : False , 'port' : int (port ), 'messages' : []}
564604
565605 for arg in sys .argv [1 :]:
566606 if arg == '--sink' :
567- messages = []
568607 options ['sink' ] = True
569608 continue
570609
571610 if arg == '--echo' :
572- messages = []
573611 options ['echo' ] = True
574612 continue
575613
@@ -598,7 +636,7 @@ def main():
598636 BGPServer ('127.0.0.1' , options )
599637 try :
600638 BGPServer ('::1' , options )
601- except :
639+ except Exception :
602640 # does not work on travis-ci
603641 pass
604642 drop ()
0 commit comments