zephyr_mirror: Split out the main loop into its own function.
(imported from commit 4c5639b3679f7ef0188e622bf7721bd3ee71bddc)
This commit is contained in:
		
							parent
							
								
									a72111c227
								
							
						
					
					
						commit
						a8fc07c745
					
				
					 1 changed files with 75 additions and 72 deletions
				
			
		| 
						 | 
				
			
			@ -148,19 +148,26 @@ def process_loop(log):
 | 
			
		|||
            continue
 | 
			
		||||
 | 
			
		||||
        try:
 | 
			
		||||
            process_notice(notice, log)
 | 
			
		||||
        except:
 | 
			
		||||
            print >>sys.stderr, 'Error relaying zephyr'
 | 
			
		||||
            traceback.print_exc()
 | 
			
		||||
            time.sleep(2)
 | 
			
		||||
 | 
			
		||||
def process_notice(notice, log):
 | 
			
		||||
    zsig, body = notice.message.split("\x00", 1)
 | 
			
		||||
    is_personal = False
 | 
			
		||||
    is_huddle = False
 | 
			
		||||
 | 
			
		||||
    if notice.opcode == "PING":
 | 
			
		||||
        # skip PING messages
 | 
			
		||||
                continue
 | 
			
		||||
        return
 | 
			
		||||
 | 
			
		||||
    if isinstance(zsig, str):
 | 
			
		||||
        # Check for width unicode character u'\u200B'.encode("utf-8")
 | 
			
		||||
        if u'\u200B'.encode("utf-8") in zsig:
 | 
			
		||||
            print "Skipping message from Humbug!"
 | 
			
		||||
                    continue
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
    sender = notice.sender.lower().replace("athena.mit.edu", "mit.edu")
 | 
			
		||||
    recipient = notice.recipient.lower().replace("athena.mit.edu", "mit.edu")
 | 
			
		||||
| 
						 | 
				
			
			@ -184,7 +191,7 @@ def process_loop(log):
 | 
			
		|||
    if (notice.cls.lower() not in current_zephyr_subs) and not \
 | 
			
		||||
            (is_personal and options.forward_personals):
 | 
			
		||||
        print "Skipping ...", notice.cls, notice.instance, is_personal
 | 
			
		||||
                continue
 | 
			
		||||
        return
 | 
			
		||||
 | 
			
		||||
    if is_huddle:
 | 
			
		||||
        zeph = { 'type'      : 'personal',
 | 
			
		||||
| 
						 | 
				
			
			@ -220,10 +227,6 @@ def process_loop(log):
 | 
			
		|||
        print >>sys.stderr, 'Error relaying zephyr'
 | 
			
		||||
        print zeph
 | 
			
		||||
        print res
 | 
			
		||||
        except:
 | 
			
		||||
            print >>sys.stderr, 'Error relaying zephyr'
 | 
			
		||||
            traceback.print_exc()
 | 
			
		||||
            time.sleep(2)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def zephyr_to_humbug(options):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue