rem
stringlengths 1
322k
| add
stringlengths 0
2.05M
| context
stringlengths 4
228k
| meta
stringlengths 156
215
|
---|---|---|---|
print "e.g. \"( true & false | ( true & !true ) )\"" | print "e.g. \"( true & false | ( true & ! true ) )\"" | def infix_to_prefix(expr): """converts the infix expression to prefix using the shunting yard algorithm""" ops = [] results = [] for token in tokenize(expr): #print ops, results if is_op(token): #If the token is an operator, o1, then: #while there is an operator token, o2, at the top of the stack, and #either o1 is left-associative and its precedence is less than or equal to that of o2, #or o1 is right-associative and its precedence is less than that of o2, #pop o2 off the stack, onto the output queue; #push o1 onto the stack. while len(ops) > 0 and is_op(ops[-1]) and \ ( (associativity(token) == 'left' and precedence(token) <= ops[-1]) \ or (associativity(token) == 'right' and precedence(token) < ops[-1]) ): results.append(ops.pop()) ops.append(token) #If the token is a left parenthesis, then push it onto the stack. elif is_left_paran(token): ops.append(token) #If the token is a right parenthesis: elif is_right_paran(token): #Until the token at the top of the stack is a left parenthesis, pop operators off the stack onto the output queue. while len(ops) > 0 and not is_left_paran(ops[-1]): results.append(ops.pop()) #Pop the left parenthesis from the stack, but not onto the output queue. #If the stack runs out without finding a left parenthesis, then there are mismatched parentheses. if len(ops) == 0: print "error: mismatched parentheses" exit() if is_left_paran(ops[-1]): ops.pop() else: #If the token is a number, then add it to the output queue. results.append(token) #When there are no more tokens to read: #While there are still operator tokens in the stack: while len(ops) > 0: #If the operator token on the top of the stack is a parenthesis, then there are mismatched parentheses. if is_right_paran(ops[-1]) or is_left_paran(ops[-1]): print "error: mismatched parentheses" exit() #Pop the operator onto the output queue. results.append(ops.pop()) return results | e767b12033e64b5042fe38b01fa3dd7f6b9765d9 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/14576/e767b12033e64b5042fe38b01fa3dd7f6b9765d9/shuntingyard.py |
v = obj.Schema().getField(field).get(obj, mimetype="text/plain") | v = obj.Schema().getField(field).getRaw(obj) | def get(self, obj, field, context=None): """ """ v = obj.Schema().getField(field).get(obj, mimetype="text/plain") return v | 17ab13941f03c72a692c09805275c64163d96d17 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11226/17ab13941f03c72a692c09805275c64163d96d17/base.py |
f = str(f.data) full_path = os.path.join(parent_path, filename) try: full_path = full_path.encode('ascii') except: try: full_path = full_path.decode('utf-8').encode('ascii') except: pass zip.writestr(full_path, f) | fdata = str(f.data) full_path = os.path.join(parent_path, zip_filename) zip.writestr(full_path, fdata) | def get(self, obj, field, context=None, zip=None, parent_path=''): """ """ f = obj.Schema().getField(field).get(obj) if not f : return '' else: filename = f.filename if zip is not None: #logger.error(obj.Schema().getField(field).getType()) if obj.Schema().getField(field).getType() in \ ("plone.app.blob.subtypes.file.ExtensionBlobField", "Products.Archetypes.Field.FileField", 'Products.AttachmentField.AttachmentField.AttachmentField', "Products.Archetypes.Field.ImageField"): | 40041ba04503cafee99b4c2bb76a7457a842b91a /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11226/40041ba04503cafee99b4c2bb76a7457a842b91a/file.py |
obj = getattr(container.aq_explicit, id, None) if obj is None: | oids = container.objectIds() if not id in oids: | def importObject(self, row, specific_fields, type, conflict_winner, export_date, wf_transition, zip, encoding='utf-8', ignore_content_errors=False, plain_format=False): """ """ modified = False is_new_object = False protected = True parent_path = row[0] id = row[1] type_class = row[2] if parent_path == "": container = self.context else: try: container = self.context.unrestrictedTraverse(parent_path) except: raise csvreplicataNonExistentContainer, \ "Non existent container %s " % parent_path | 46dc04825b3abad9211bd86f96a3401a73c44f6b /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11226/46dc04825b3abad9211bd86f96a3401a73c44f6b/replicator.py |
obj = getattr(container.aq_explicit, id) | def importObject(self, row, specific_fields, type, conflict_winner, export_date, wf_transition, zip, encoding='utf-8', ignore_content_errors=False, plain_format=False): """ """ modified = False is_new_object = False protected = True parent_path = row[0] id = row[1] type_class = row[2] if parent_path == "": container = self.context else: try: container = self.context.unrestrictedTraverse(parent_path) except: raise csvreplicataNonExistentContainer, \ "Non existent container %s " % parent_path | 46dc04825b3abad9211bd86f96a3401a73c44f6b /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11226/46dc04825b3abad9211bd86f96a3401a73c44f6b/replicator.py |
|
def importObject(self, row, specific_fields, type, conflict_winner, export_date, wf_transition, zip, encoding='utf-8', ignore_content_errors=False, plain_format=False): """ """ modified = False is_new_object = False protected = True parent_path = row[0] id = row[1] type_class = row[2] if parent_path == "": container = self.context else: try: container = self.context.unrestrictedTraverse(parent_path) except: raise csvreplicataNonExistentContainer, \ "Non existent container %s " % parent_path | 7b3f44a7192a2b3d019b344d69aa6f88161972ce /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11226/7b3f44a7192a2b3d019b344d69aa6f88161972ce/replicator.py |
||
else: | obj = getattr(container.aq_explicit, id, None) if not is_new_object: | def importObject(self, row, specific_fields, type, conflict_winner, export_date, wf_transition, zip, encoding='utf-8', ignore_content_errors=False, plain_format=False): """ """ modified = False is_new_object = False protected = True parent_path = row[0] id = row[1] type_class = row[2] if parent_path == "": container = self.context else: try: container = self.context.unrestrictedTraverse(parent_path) except: raise csvreplicataNonExistentContainer, \ "Non existent container %s " % parent_path | 7b3f44a7192a2b3d019b344d69aa6f88161972ce /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11226/7b3f44a7192a2b3d019b344d69aa6f88161972ce/replicator.py |
obj = getattr(container.aq_explicit, id, None) | def importObject(self, row, specific_fields, type, conflict_winner, export_date, wf_transition, zip, encoding='utf-8', ignore_content_errors=False, plain_format=False): """ """ modified = False is_new_object = False protected = True parent_path = row[0] id = row[1] type_class = row[2] if parent_path == "": container = self.context else: try: container = self.context.unrestrictedTraverse(parent_path) except: raise csvreplicataNonExistentContainer, \ "Non existent container %s " % parent_path | 7b3f44a7192a2b3d019b344d69aa6f88161972ce /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11226/7b3f44a7192a2b3d019b344d69aa6f88161972ce/replicator.py |
|
zip.writestr(os.path.join(parent_path, filename), f) | full_path = os.path.join(parent_path, filename) try: full_path = full_path.encode('ascii') except: try: full_path = full_path.decode('utf-8').encode('ascii') except: pass zip.writestr(full_path, f) | def get(self, obj, field, context=None, zip=None, parent_path=''): """ """ f = obj.Schema().getField(field).get(obj) if not f : return '' else: filename = f.filename if zip is not None: #logger.error(obj.Schema().getField(field).getType()) if obj.Schema().getField(field).getType() in \ ("plone.app.blob.subtypes.file.ExtensionBlobField", "Products.Archetypes.Field.FileField", 'Products.AttachmentField.AttachmentField.AttachmentField', "Products.Archetypes.Field.ImageField"): | 7405b193fcff1eee7ce5c52a04579d29315bcb33 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11226/7405b193fcff1eee7ce5c52a04579d29315bcb33/file.py |
query = """INSERT INTO cmtSUBSCRIPTION (id_bibrec, id_user, creation_time) | query = """INSERT INTO cmtSUBSCRIPTION (id_bibrec, id_user, creation_time) | def subscribe_user_to_discussion(recID, uid): """ Subscribe a user to a discussion, so the she receives by emails all new new comments for this record. @param recID: record ID corresponding to the discussion we want to subscribe the user @param uid: user id """ query = """INSERT INTO cmtSUBSCRIPTION (id_bibrec, id_user, creation_time) VALUES (%s, %s, %s)""" params = (recID, uid, convert_datestruct_to_datetext(time.localtime())) try: res = run_sql(query, params) except: return 0 return 1 | 0a1e261095ef1900914b1aa5807b70e51080d1f1 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/3302/0a1e261095ef1900914b1aa5807b70e51080d1f1/webcomment.py |
res = run_sql(query, params) | run_sql(query, params) | def subscribe_user_to_discussion(recID, uid): """ Subscribe a user to a discussion, so the she receives by emails all new new comments for this record. @param recID: record ID corresponding to the discussion we want to subscribe the user @param uid: user id """ query = """INSERT INTO cmtSUBSCRIPTION (id_bibrec, id_user, creation_time) VALUES (%s, %s, %s)""" params = (recID, uid, convert_datestruct_to_datetext(time.localtime())) try: res = run_sql(query, params) except: return 0 return 1 | 0a1e261095ef1900914b1aa5807b70e51080d1f1 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/3302/0a1e261095ef1900914b1aa5807b70e51080d1f1/webcomment.py |
def calculate_start_date(display_since): """ Private function Returns the datetime of display_since argument in MYSQL datetime format calculated according to the local time. @param display_since: = all= no filtering nd = n days ago nw = n weeks ago nm = n months ago ny = n years ago where n is a single digit number @return: string of wanted datetime. If 'all' given as argument, will return datetext_default datetext_default is defined in miscutils/lib/dateutils and equals 0000-00-00 00:00:00 => MySQL format If bad arguement given, will return datetext_default """ time_types = {'d':0, 'w':0, 'm':0, 'y':0} today = datetime.today() try: nb = int(display_since[:-1]) except: return datetext_default if display_since in [None, 'all']: return datetext_default if str(display_since[-1]) in time_types: time_type = str(display_since[-1]) else: return datetext_default # year if time_type == 'y': if (int(display_since[:-1]) > today.year - 1) or (int(display_since[:-1]) < 1): # 1 < nb years < 2008 return datetext_default else: final_nb_year = today.year - nb yesterday = today.replace(year=final_nb_year) # month elif time_type == 'm': # to convert nb of monthes in years nb_year = nb / 12 # nb_year = number of year to substract nb = nb % 12 if nb > today.month-1: # ex: july(07)-9 monthes = -1year -3monthes nb_year += 1 nb_month = 12 - (today.month % nb) else: nb_month = today.month - nb final_nb_year = today.year - nb_year # final_nb_year = number of year to print yesterday = today.replace(year=final_nb_year, month=nb_month) # week elif time_type == 'w': delta = timedelta(weeks=nb) yesterday = today - delta # day elif time_type == 'd': delta = timedelta(days=nb) yesterday = today - delta return yesterday.strftime("%Y-%m-%d %H:%M:%S") | b3331e5a9c1da552c6ace8d0804aa3e4e7916f01 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/3302/b3331e5a9c1da552c6ace8d0804aa3e4e7916f01/webcomment.py |
||
if nb > today.month-1: | if nb > today.month-1: | def calculate_start_date(display_since): """ Private function Returns the datetime of display_since argument in MYSQL datetime format calculated according to the local time. @param display_since: = all= no filtering nd = n days ago nw = n weeks ago nm = n months ago ny = n years ago where n is a single digit number @return: string of wanted datetime. If 'all' given as argument, will return datetext_default datetext_default is defined in miscutils/lib/dateutils and equals 0000-00-00 00:00:00 => MySQL format If bad arguement given, will return datetext_default """ time_types = {'d':0, 'w':0, 'm':0, 'y':0} today = datetime.today() try: nb = int(display_since[:-1]) except: return datetext_default if display_since in [None, 'all']: return datetext_default if str(display_since[-1]) in time_types: time_type = str(display_since[-1]) else: return datetext_default # year if time_type == 'y': if (int(display_since[:-1]) > today.year - 1) or (int(display_since[:-1]) < 1): # 1 < nb years < 2008 return datetext_default else: final_nb_year = today.year - nb yesterday = today.replace(year=final_nb_year) # month elif time_type == 'm': # to convert nb of monthes in years nb_year = nb / 12 # nb_year = number of year to substract nb = nb % 12 if nb > today.month-1: # ex: july(07)-9 monthes = -1year -3monthes nb_year += 1 nb_month = 12 - (today.month % nb) else: nb_month = today.month - nb final_nb_year = today.year - nb_year # final_nb_year = number of year to print yesterday = today.replace(year=final_nb_year, month=nb_month) # week elif time_type == 'w': delta = timedelta(weeks=nb) yesterday = today - delta # day elif time_type == 'd': delta = timedelta(days=nb) yesterday = today - delta return yesterday.strftime("%Y-%m-%d %H:%M:%S") | b3331e5a9c1da552c6ace8d0804aa3e4e7916f01 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/3302/b3331e5a9c1da552c6ace8d0804aa3e4e7916f01/webcomment.py |
d = dict(zip(s, [1234]*len(s))) self.assertEqual(rencode.loads(rencode.dumps(d)), d) | d = dict(zip(s, ["foo"*120]*len(s))) d2 = {"foo": d, "bar": d, "baz": d} self.assertEqual(rencode.loads(rencode.dumps(d2)), d2) | def test_decode_dict(self): s = "abcdefghijklmnopqrstuvwxyz1234567890" d = dict(zip(s, [1234]*len(s))) self.assertEqual(rencode.loads(rencode.dumps(d)), d) | 01ec9f169ee1736935a252f0b029cdaf51bb1dba /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/5961/01ec9f169ee1736935a252f0b029cdaf51bb1dba/test_rencode.py |
log.info( "Instance '%s' found alive." % reservation.instances[0].id ) | log.info( "Instance '%s' found alive. Restarting instance so it can register with the master." % reservation.instances[0].id ) ec2_conn.reboot_instances([reservation.instances[0].id]) | def get_worker_instances( self ): instances = [] if self.app.TESTFLAG is True: # for i in range(5): # instance = Instance( self.app, inst=None, m_state="Pending" ) # instance.id = "WorkerInstance" # instances.append(instance) return instances log.debug("Trying to discover any worker instances associated with this cluster...") filters = {'tag:clusterName': self.app.ud['cluster_name'], 'tag:role': 'worker'} try: ec2_conn = self.app.cloud_interface.get_ec2_connection() reservations = ec2_conn.get_all_instances(filters=filters) for reservation in reservations: if reservation.instances[0].state != 'terminated' and reservation.instances[0].state != 'shutting-down': i = Instance( self.app, inst=reservation.instances[0], m_state=reservation.instances[0].state ) instances.append( i ) log.info( "Instance '%s' found alive." % reservation.instances[0].id ) except EC2ResponseError, e: log.debug( "Error checking for live instances: %s" % e ) return instances | d943af084217bc17559783cb9d670cf3afc6a237 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11241/d943af084217bc17559783cb9d670cf3afc6a237/master.py |
log.info( "Setting up Galaxy" ) | log.info( "Setting up Galaxy application" ) | def manage_galaxy( self, to_be_started=True ): if self.app.TESTFLAG is True: log.debug( "Attempted to manage Galaxy, but TESTFLAG is set." ) return os.putenv( "GALAXY_HOME", self.galaxy_home ) os.putenv( "TEMP", '/mnt/galaxyData/tmp' ) if to_be_started: self.status() if not self.configured: log.info( "Setting up Galaxy" ) s3_conn = self.app.cloud_interface.get_s3_connection() if not os.path.exists(self.galaxy_home): log.error("Galaxy application directory '%s' does not exist! Aborting." % self.galaxy_home) log.debug("ls /mnt/: %s" % os.listdir('/mnt/')) return False | 0b22386a42579657e2d68650b928181fb4bb4eee /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11241/0b22386a42579657e2d68650b928181fb4bb4eee/galaxy.py |
if os.path.exists('/mnt/galaxyIndices/locfiles/sam_fa_indices.loc'): shutil.copy('/mnt/galaxyIndices/locfiles/sam_fa_indices.loc', '/mnt/galaxyTools/galaxy-central/tool-data/sam_fa_indices.loc') | def manage_galaxy( self, to_be_started=True ): if self.app.TESTFLAG is True: log.debug( "Attempted to manage Galaxy, but TESTFLAG is set." ) return os.putenv( "GALAXY_HOME", self.galaxy_home ) os.putenv( "TEMP", '/mnt/galaxyData/tmp' ) if to_be_started: self.status() if not self.configured: log.info( "Setting up Galaxy" ) s3_conn = self.app.cloud_interface.get_s3_connection() if not os.path.exists(self.galaxy_home): log.error("Galaxy application directory '%s' does not exist! Aborting." % self.galaxy_home) log.debug("ls /mnt/: %s" % os.listdir('/mnt/')) return False | 0b22386a42579657e2d68650b928181fb4bb4eee /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11241/0b22386a42579657e2d68650b928181fb4bb4eee/galaxy.py |
|
try: misc.run("cd %s; sed 's/pyhton/python -ES/g' setup.sh > setup.sh.custom" % self.galaxy_home, "Failed to edit setup.sh", "Successfully adjusted setup.sh") shutil.copy( self.galaxy_home + '/setup.sh.custom', self.galaxy_home + '/setup.sh' ) os.chown( self.galaxy_home + '/setup.sh', pwd.getpwnam( "galaxy" )[2], grp.getgrnam( "galaxy" )[2] ) except Exception, e: log.error("Error adjusting setup.sh: %s" % e) | def manage_galaxy( self, to_be_started=True ): if self.app.TESTFLAG is True: log.debug( "Attempted to manage Galaxy, but TESTFLAG is set." ) return os.putenv( "GALAXY_HOME", self.galaxy_home ) os.putenv( "TEMP", '/mnt/galaxyData/tmp' ) if to_be_started: self.status() if not self.configured: log.info( "Setting up Galaxy" ) s3_conn = self.app.cloud_interface.get_s3_connection() if not os.path.exists(self.galaxy_home): log.error("Galaxy application directory '%s' does not exist! Aborting." % self.galaxy_home) log.debug("ls /mnt/: %s" % os.listdir('/mnt/')) return False | 0b22386a42579657e2d68650b928181fb4bb4eee /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11241/0b22386a42579657e2d68650b928181fb4bb4eee/galaxy.py |
|
with open('/etc/profile', 'a') as f: f.write('export PATH=/mnt/galaxyTools/tools/bin:/mnt/galaxyTools/tools/pkg/fastx_toolkit_0.0.13:/mnt/galaxyTools/tools/pkg/bowtie-0.12.5:/mnt/galaxyTools/tools/pkg/samtools-0.1.7_x86_64-linux:/mnt/galaxyTools/tools/pkg/gnuplot-4.4.0/bin:/opt/PostgreSQL/8.4/bin:$PATH\n') os.chown(self.galaxy_home + '/universe_wsgi.ini', pwd.getpwnam("galaxy")[2], grp.getgrnam("galaxy")[2]) | def manage_galaxy( self, to_be_started=True ): if self.app.TESTFLAG is True: log.debug( "Attempted to manage Galaxy, but TESTFLAG is set." ) return os.putenv( "GALAXY_HOME", self.galaxy_home ) os.putenv( "TEMP", '/mnt/galaxyData/tmp' ) if to_be_started: self.status() if not self.configured: log.info( "Setting up Galaxy" ) s3_conn = self.app.cloud_interface.get_s3_connection() if not os.path.exists(self.galaxy_home): log.error("Galaxy application directory '%s' does not exist! Aborting." % self.galaxy_home) log.debug("ls /mnt/: %s" % os.listdir('/mnt/')) return False | 0b22386a42579657e2d68650b928181fb4bb4eee /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11241/0b22386a42579657e2d68650b928181fb4bb4eee/galaxy.py |
|
'snapshot' : {'progress' : str(self.app.manager.snapshot_progress), 'status' : str(self.app.manager.snapshot_status)}, | 'snapshot' : {'progress' : str(ss_progress), 'status' : str(ss_status)}, | def instance_state_json(self, trans, no_json=False): g_s = self.app.manager.get_services('Galaxy') if g_s and g_s[0].state == service_states.RUNNING: dns = 'http://%s' % str( self.app.cloud_interface.get_self_public_ip() ) else: # dns = '<a href="http://%s" target="_blank">Access Galaxy</a>' % str( 'localhost:8080' ) dns = '#' ret_dict = {'instance_state':self.app.manager.get_instance_state(), 'cluster_status':self.app.manager.get_cluster_status(), 'dns':dns, 'instance_status':{'idle': str(len(self.app.manager.get_idle_instances())), 'available' : str(self.app.manager.get_num_available_workers()), 'requested' : str(len(self.app.manager.worker_instances))}, 'disk_usage':{'used':str(self.app.manager.disk_used), 'total':str(self.app.manager.disk_total), 'pct':str(self.app.manager.disk_pct)}, 'data_status':self.app.manager.get_data_status(), 'app_status':self.app.manager.get_app_status(), # 'services' : {'fs' : self.app.manager.fs_status_text(), # 'pg' : self.app.manager.pg_status_text(), # 'sge' : self.app.manager.sge_status_text(), # 'galaxy' : self.app.manager.galaxy_status_text()}, 'all_fs' : self.app.manager.all_fs_status_array(), 'snapshot' : {'progress' : str(self.app.manager.snapshot_progress), 'status' : str(self.app.manager.snapshot_status)}, 'autoscaling': {'use_autoscaling': bool(self.app.manager.get_services('Autoscale')), 'as_min': 'N/A' if not self.app.manager.get_services('Autoscale') else self.app.manager.get_services('Autoscale')[0].as_min, 'as_max': 'N/A' if not self.app.manager.get_services('Autoscale') else self.app.manager.get_services('Autoscale')[0].as_max} } if no_json: return ret_dict else: return to_json_string(ret_dict) | b092e742642def3940eb5e198e3e5499ba9b8cf5 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11241/b092e742642def3940eb5e198e3e5499ba9b8cf5/root.py |
def update_galaxy(self, trans, repository="http://bitbucket.org/galaxy/cloudman"): | def update_galaxy(self, trans, repository="http://bitbucket.org/galaxy/galaxy-central"): | def update_galaxy(self, trans, repository="http://bitbucket.org/galaxy/cloudman"): log.debug("Updating Galaxy... Using repository %s" % repository) svcs = self.app.manager.get_services('Galaxy') for service in svcs: service.remove() misc.run('su galaxy -c "cd %s; hg pull %s --update"' % (paths.P_GALAXY_HOME, repository)) misc.run('su galaxy -c "cd %s; sh setup.sh; sh manage_db.sh upgrade"' % (paths.P_GALAXY_HOME)) for service in svcs: service.add() | 78a047bc5efd72a9276af90a4f65e67acf0949a8 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11241/78a047bc5efd72a9276af90a4f65e67acf0949a8/root.py |
misc.run('su galaxy -c "cd %s; hg pull %s --update"' % (paths.P_GALAXY_HOME, repository)) misc.run('su galaxy -c "cd %s; sh setup.sh; sh manage_db.sh upgrade"' % (paths.P_GALAXY_HOME)) | cmd = '%s - galaxy -c "cd %s; hg --config ui.merge=internal:local pull %s --update"' % (paths.P_SU, paths.P_GALAXY_HOME, repository) retval = os.system(cmd) log.debug("Galaxy update cmd '%s'; return value %s" % (cmd, retval)) cmd = '%s - galaxy -c "cd %s; sh manage_db.sh upgrade"' % (paths.P_SU, paths.P_GALAXY_HOME) retval = os.system(cmd) log.debug("Galaxy DB update cmd '%s'; return value %s" % (cmd, retval)) | def update_galaxy(self, trans, repository="http://bitbucket.org/galaxy/cloudman"): log.debug("Updating Galaxy... Using repository %s" % repository) svcs = self.app.manager.get_services('Galaxy') for service in svcs: service.remove() misc.run('su galaxy -c "cd %s; hg pull %s --update"' % (paths.P_GALAXY_HOME, repository)) misc.run('su galaxy -c "cd %s; sh setup.sh; sh manage_db.sh upgrade"' % (paths.P_GALAXY_HOME)) for service in svcs: service.add() | 78a047bc5efd72a9276af90a4f65e67acf0949a8 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11241/78a047bc5efd72a9276af90a4f65e67acf0949a8/root.py |
service.add() | service.start() log.debug("Done updating Galaxy") | def update_galaxy(self, trans, repository="http://bitbucket.org/galaxy/cloudman"): log.debug("Updating Galaxy... Using repository %s" % repository) svcs = self.app.manager.get_services('Galaxy') for service in svcs: service.remove() misc.run('su galaxy -c "cd %s; hg pull %s --update"' % (paths.P_GALAXY_HOME, repository)) misc.run('su galaxy -c "cd %s; sh setup.sh; sh manage_db.sh upgrade"' % (paths.P_GALAXY_HOME)) for service in svcs: service.add() | 78a047bc5efd72a9276af90a4f65e67acf0949a8 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11241/78a047bc5efd72a9276af90a4f65e67acf0949a8/root.py |
<input type="text" value="http://bitbucket.org/galaxy/cloudman" name="repository"> | <input type="text" value="http://bitbucket.org/galaxy/galaxy-central" name="repository"> | def admin(self, trans): return """ <ul> <li>This admin panel is only a very temporary way to control galaxy services. Use with caution.</li> <li><strong>Service Control</strong></li> <li><a href='manage_galaxy'>Start Galaxy</a></li> <li><a href='manage_galaxy?to_be_started=False'>Stop Galaxy</a></li> <form action="update_galaxy" method="get"> <input type="text" value="http://bitbucket.org/galaxy/cloudman" name="repository"> <input type="submit" value="Update Galaxy"> </form> <li><a href='manage_postgres'>Start Postgres</a></li> <li><a href='manage_postgres?to_be_started=False'>Start Postgres</a></li> <li><a href='manage_sge'>Start SGE</a></li> <li><a href='manage_sge?to_be_started=False'>Stop SGE</a></li> <li><strong>Emergency Tools -use with care.</strong></li> <li><a href='recover_monitor'>Recover monitor.</a></li> <li><a href='recover_monitor?force=True'>Recover monitor *with Force*.</a></li> <li><a href='add_instances?number_nodes=1'>Add one instance</a></li> <li><a href='remove_instances?number_nodes=1'>Remove one instance</a></li> <li><a href='remove_instances?number_nodes=1&force=True'>Remove one instance *with Force*.</a></li> <li><a href='cleanup'>Cleanup - shutdown all services/instances, keep volumes</a></li> <li><a href='kill_all'>Kill all - shutdown everything, disconnect/delete all.</a></li> </ul> """ | 78a047bc5efd72a9276af90a4f65e67acf0949a8 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11241/78a047bc5efd72a9276af90a4f65e67acf0949a8/root.py |
worker_ud['password'] = self.app.ud['password'] | if self.app.ud.has_key('password'): worker_ud['password'] = self.app.ud['password'] | def add_instances( self, num_nodes, instance_type=''): num_nodes = int( num_nodes ) ec2_conn = self.app.cloud_interface.get_ec2_connection() log.info( "Adding %s instance(s)..." % num_nodes ) # Compose worker instance user data worker_ud = {} worker_ud['access_key'] = self.app.ud['access_key'] worker_ud['secret_key'] = self.app.ud['secret_key'] worker_ud['password'] = self.app.ud['password'] worker_ud['cluster_name'] = self.app.ud['cluster_name'] worker_ud['role'] = 'worker' worker_ud['master_ip'] = self.app.cloud_interface.get_self_private_ip() worker_ud_str = "\n".join(['%s: %s' % (key, value) for key, value in worker_ud.iteritems()]) #log.debug( "Worker user data: %s " % worker_ud ) reservation = None if instance_type == '': instance_type = self.app.cloud_interface.get_type() log.debug( "Using following command: ec2_conn.run_instances( image_id='%s', min_count=1, max_count='%s', key_name='%s', security_groups=['%s'], user_data=[%s], instance_type='%s', placement='%s' )" % ( self.app.cloud_interface.get_ami(), num_nodes, self.app.cloud_interface.get_key_pair_name(), ", ".join( self.app.cloud_interface.get_security_groups() ), worker_ud_str, instance_type, self.app.cloud_interface.get_zone() ) ) try: # log.debug( "Would be starting worker instance(s)..." ) reservation = ec2_conn.run_instances( image_id=self.app.cloud_interface.get_ami(), min_count=1, max_count=num_nodes, key_name=self.app.cloud_interface.get_key_pair_name(), security_groups=self.app.cloud_interface.get_security_groups(), user_data=worker_ud_str, instance_type=instance_type, placement=self.app.cloud_interface.get_zone() ) if reservation: for instance in reservation.instances: i = Instance( self.app, inst=instance, m_state=instance.state ) self.worker_instances.append( i ) # Save list of started instances into a file on S3 to be used in case of cluster restart self.save_worker_instance_IDs_to_S3( self.worker_instances ) except BotoServerError, e: log.error( "EC2 insufficient capacity error: %s" % str( e ) ) return False except EC2ResponseError, e: err = "EC2 response error when starting worker nodes: %s" % str( e ) log.error( err ) return False # Update cluster status # self.master_state = master_states.ERROR # self.console_monitor.last_state_change_time = dt.datetime.utcnow() # log.debug( "Changed state to '%s'" % self.master_state ) except Exception, ex: err = "Error when starting worker nodes: %s" % str( ex ) log.error( err ) return False # self.master_state = master_states.ERROR # self.console_monitor.last_state_change_time = dt.datetime.utcnow() # log.debug( "Changed state to '%s'" % self.master_state ) log.debug( "Started %s instance(s)" % num_nodes ) return True | b5a8fb4b17a65058e4bce4310dac3d156b9dafc6 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11241/b5a8fb4b17a65058e4bce4310dac3d156b9dafc6/master.py |
self.app.manager.update_users_CM() return trans.fill_template('index.mako') | return to_json_string({'updated':self.app.manager.update_users_CM()}) | def update_users_CM(self, trans): self.app.manager.update_users_CM() return trans.fill_template('index.mako') | 157057b13f5380edd7fc3e58057f038ada42bdbd /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11241/157057b13f5380edd7fc3e58057f038ada42bdbd/root.py |
CM_url = trans.app.config.get( "CM_url", "http://bitbucket.org/galaxy/cloudman/changesets/" ) | def get_CM_url(self, trans): CM_url = trans.app.config.get( "CM_url", "http://bitbucket.org/galaxy/cloudman/changesets/" ) changesets = self.app.manager.check_for_new_version_of_CM() if changesets.has_key('default_CM_rev') and changesets.has_key('user_CM_rev'): try: num_changes = int(changesets['default_CM_rev']) - int(changesets['user_CM_rev']) CM_url += changesets['default_CM_rev'] + '/' + str(num_changes) except Exception, e: log.debug("Error calculating changeset range for CM 'What's new' link: %s" % e) return CM_url | f91170760a7e8b495377486bc187299e52c2b543 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11241/f91170760a7e8b495377486bc187299e52c2b543/root.py |
|
return CM_url | return None | def get_CM_url(self, trans): CM_url = trans.app.config.get( "CM_url", "http://bitbucket.org/galaxy/cloudman/changesets/" ) changesets = self.app.manager.check_for_new_version_of_CM() if changesets.has_key('default_CM_rev') and changesets.has_key('user_CM_rev'): try: num_changes = int(changesets['default_CM_rev']) - int(changesets['user_CM_rev']) CM_url += changesets['default_CM_rev'] + '/' + str(num_changes) except Exception, e: log.debug("Error calculating changeset range for CM 'What's new' link: %s" % e) return CM_url | f91170760a7e8b495377486bc187299e52c2b543 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11241/f91170760a7e8b495377486bc187299e52c2b543/root.py |
import time if time.gmtime().tm_sec < 20 or time.gmtime().tm_sec > 40: ss_status = "Working" ss_progress = (time.gmtime().tm_sec % 20) * 5 else: ss_progress = None ss_status = None | def instance_state_json(self, trans, no_json=False): g_s = self.app.manager.get_services('Galaxy') if g_s and g_s[0].state == service_states.RUNNING: dns = 'http://%s' % str( self.app.cloud_interface.get_self_public_ip() ) else: # dns = '<a href="http://%s" target="_blank">Access Galaxy</a>' % str( 'localhost:8080' ) dns = '#' # TEMP TEST FOR RESIZING import time if time.gmtime().tm_sec < 20 or time.gmtime().tm_sec > 40: ss_status = "Working" ss_progress = (time.gmtime().tm_sec % 20) * 5 else: ss_progress = None ss_status = None ret_dict = {'instance_state':self.app.manager.get_instance_state(), 'cluster_status':self.app.manager.get_cluster_status(), 'dns':dns, 'instance_status':{'idle': str(len(self.app.manager.get_idle_instances())), 'available' : str(self.app.manager.get_num_available_workers()), 'requested' : str(len(self.app.manager.worker_instances))}, 'disk_usage':{'used':str(self.app.manager.disk_used), 'total':str(self.app.manager.disk_total), 'pct':str(self.app.manager.disk_pct)}, 'data_status':self.app.manager.get_data_status(), 'app_status':self.app.manager.get_app_status(), # 'services' : {'fs' : self.app.manager.fs_status_text(), # 'pg' : self.app.manager.pg_status_text(), # 'sge' : self.app.manager.sge_status_text(), # 'galaxy' : self.app.manager.galaxy_status_text()}, 'all_fs' : self.app.manager.all_fs_status_array(), # 'snapshot' : {'progress' : str(self.app.manager.snapshot_progress), # 'status' : str(self.app.manager.snapshot_status)}, 'snapshot' : {'progress' : str(ss_progress), 'status' : str(ss_status)}, 'autoscaling': {'use_autoscaling': bool(self.app.manager.get_services('Autoscale')), 'as_min': 'N/A' if not self.app.manager.get_services('Autoscale') else self.app.manager.get_services('Autoscale')[0].as_min, 'as_max': 'N/A' if not self.app.manager.get_services('Autoscale') else self.app.manager.get_services('Autoscale')[0].as_max} } if no_json: return ret_dict else: return to_json_string(ret_dict) | ae4e0df8e2176479c03ed851987eb5a12a9836e1 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11241/ae4e0df8e2176479c03ed851987eb5a12a9836e1/root.py |
|
'snapshot' : {'progress' : str(ss_progress), 'status' : str(ss_status)}, | 'snapshot' : {'progress' : str(self.app.manager.snapshot_progress), 'status' : str(self.app.manager.snapshot_status)}, | def instance_state_json(self, trans, no_json=False): g_s = self.app.manager.get_services('Galaxy') if g_s and g_s[0].state == service_states.RUNNING: dns = 'http://%s' % str( self.app.cloud_interface.get_self_public_ip() ) else: # dns = '<a href="http://%s" target="_blank">Access Galaxy</a>' % str( 'localhost:8080' ) dns = '#' # TEMP TEST FOR RESIZING import time if time.gmtime().tm_sec < 20 or time.gmtime().tm_sec > 40: ss_status = "Working" ss_progress = (time.gmtime().tm_sec % 20) * 5 else: ss_progress = None ss_status = None ret_dict = {'instance_state':self.app.manager.get_instance_state(), 'cluster_status':self.app.manager.get_cluster_status(), 'dns':dns, 'instance_status':{'idle': str(len(self.app.manager.get_idle_instances())), 'available' : str(self.app.manager.get_num_available_workers()), 'requested' : str(len(self.app.manager.worker_instances))}, 'disk_usage':{'used':str(self.app.manager.disk_used), 'total':str(self.app.manager.disk_total), 'pct':str(self.app.manager.disk_pct)}, 'data_status':self.app.manager.get_data_status(), 'app_status':self.app.manager.get_app_status(), # 'services' : {'fs' : self.app.manager.fs_status_text(), # 'pg' : self.app.manager.pg_status_text(), # 'sge' : self.app.manager.sge_status_text(), # 'galaxy' : self.app.manager.galaxy_status_text()}, 'all_fs' : self.app.manager.all_fs_status_array(), # 'snapshot' : {'progress' : str(self.app.manager.snapshot_progress), # 'status' : str(self.app.manager.snapshot_status)}, 'snapshot' : {'progress' : str(ss_progress), 'status' : str(ss_status)}, 'autoscaling': {'use_autoscaling': bool(self.app.manager.get_services('Autoscale')), 'as_min': 'N/A' if not self.app.manager.get_services('Autoscale') else self.app.manager.get_services('Autoscale')[0].as_min, 'as_max': 'N/A' if not self.app.manager.get_services('Autoscale') else self.app.manager.get_services('Autoscale')[0].as_max} } if no_json: return ret_dict else: return to_json_string(ret_dict) | ae4e0df8e2176479c03ed851987eb5a12a9836e1 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/11241/ae4e0df8e2176479c03ed851987eb5a12a9836e1/root.py |
self.reconnecting = False | def __init__(self, owner_bot, xmpp_room_jid, irc_room, irc_server, mode, say_level, irc_port=6667, irc_connection_interval=None, irc_charsets=None): """Create a new bridge.""" self.bot = owner_bot self.irc_server = irc_server self.irc_port = irc_port self.irc_room = irc_room.lower() self.irc_connection_interval = irc_connection_interval self.irc_charsets = irc_charsets self.irc_op = False self.xmpp_room_jid = xmpp_room_jid self.say_level = say_level self.participants = [] self.reconnecting = False if mode not in self.__class__.modes: raise Exception('[Error] "'+mode+'" is not a correct value for a bridge\'s "mode" attribute') self.mode = mode self.lock = threading.RLock() self.init2() | c452eafaa4502bd655de3d0dd9d7fef0daa19247 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/c452eafaa4502bd655de3d0dd9d7fef0daa19247/bridge.py |
|
except ServerNotConnectedError: | except irclib.ServerNotConnectedError: | def _say_on_irc(self, message): try: self.irc_connection.privmsg(self.irc_room, message) except ServerNotConnectedError: bridges = self.bot.iter_bridges(irc_server=self.irc_server) self.bot.restart_bridges_delayed(bridges, 0, say_levels.error, 'Lost bot IRC connection', protocol='irc') | 6d1b546fd869783fb1fb175db6562a88a674cc5c /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/6d1b546fd869783fb1fb175db6562a88a674cc5c/bridge.py |
except ServerNotConnectedError: c = e.args[1] | except ServerNotConnectedError as e: if len(e.args) > 0: c = e.args[0] else: self.bot.error(say_levels.error, 'Unkonwn exception on IRC thread:\n'+str(e.args)) continue | def process_forever(self, timeout=0.2): """Run an infinite loop, processing data from connections. | 3b8fce5d1026baa024494243f1b3178ac3c79c67 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/3b8fce5d1026baa024494243f1b3178ac3c79c67/irclib.py |
self.irc_id = prefix if DEBUG: print "irc_id: %s" % (prefix) | if self.irc_id != prefix: self.irc_id = prefix if DEBUG: print "irc_id: %s" % (prefix) | def process_data(self): """[Internal]""" | 29f0268dfee4fc0977650ea17c594b7a7db4c172 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/29f0268dfee4fc0977650ea17c594b7a7db4c172/irclib.py |
if command in ["nick", "welcome"]: self.logged_in = True self.real_nickname = arguments[0] if self.new_nickname != arguments[0]: if len(self.new_nickname) > len(arguments[0]): self._handle_event(Event('nicknametoolong', None, None, None)) else: self._handle_event(Event('erroneusnickname', None, None, None)) else: self._call_nick_callbacks(None) self.new_nickname = None | def process_data(self): """[Internal]""" | 129d2ef4b8971c2d1bed3c6006a3b5ffcc9e52ab /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/129d2ef4b8971c2d1bed3c6006a3b5ffcc9e52ab/irclib.py |
|
elif self.socket: | elif self.socket and hasattr(self.socket, 'recv'): | def process_data(self): """[Internal]""" | 833c88a06c7ad5b6080ab3800aa7127dcbe98dda /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/833c88a06c7ad5b6080ab3800aa7127dcbe98dda/irclib.py |
leave_message = 'kicked by '+nickname | leave_message = 'kicked by '+source_nickname | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey', 'topic', 'noorigin']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return source_nickname = None if event.source() and '!' in event.source(): source_nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str handled = False # Private message if event.eventtype() in ['privmsg', 'action']: if event.target() == self.nickname: # message is for the bot connection.privmsg(source_nickname, self.respond(event.arguments()[0])) return elif not irclib.is_channel(event.target()[0]): # search if the IRC user who sent the message is in one of the bridges for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) # he is, forward the message on XMPP if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp_to(connection.nickname, event.arguments()[0], action=action) return except Bridge.NoSuchParticipantException: continue # he isn't, send an error connection.privmsg(source_nickname, 'XIB error: you cannot send a private message to an XMPP user if you are not in one of the chans he is in') # Connection errors if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Server events if event.eventtype() in ['quit', 'nick']: for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: continue handled = True # Quit event if event.eventtype() == 'quit': if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left server.' bridge.remove_participant('irc', from_.nickname, leave_message) continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') continue if handled: return # Chan events if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'mode', 'join']: if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'join'] and not source_nickname: self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event'+event_str) return if event.eventtype() in ['kick', 'mode'] and len(event.arguments()) == 0: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event'+event_str) return chan = event.target().lower() bridge = self.get_bridge(irc_room=chan, irc_server=connection.server) from_ = None if source_nickname: try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: pass # Join event if event.eventtype() == 'join': bridge.add_participant('irc', source_nickname) return # kick handling if event.eventtype() == 'kick': try: kicked = bridge.get_participant(event.arguments()[0]) except Bridge.NoSuchParticipantException: self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?'+event_str) return leave_message = 'kicked by '+nickname if len(event.arguments()) > 1: leave_message += ' with reason: '+event.arguments()[1] else: leave_message += ' (no reason was given)' log_message = '"'+kicked.nickname+'" has been '+leave_message self.error(say_levels.warning, log_message) if isinstance(kicked.irc_connection, irclib.ServerConnection): # an IRC duplicate of an XMPP user has been kicked, auto-rejoin kicked.irc_connection.join(bridge.irc_room) elif isinstance(kicked.xmpp_c, xmpp.client.Client): # an IRC user has been kicked, make its duplicate leave kicked.leave(m) else: # an IRC user with no duplicate on XMPP has been kicked, say it on XMPP bridge.say(say_levels.warning, log_message, on_irc=False) return # Part event if event.eventtype() == 'part': if not from_: self.error(say_levels.debug, 'a participant that wasn\'t here left:'+event_str) return if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left channel.' bridge.remove_participant('irc', from_.nickname, leave_message) return # Chan message if event.eventtype() in ['pubmsg', 'action']: message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False if isinstance(from_, Participant): from_.say_on_xmpp(message, action=action) else: bridge.say_on_behalf(source_nickname, message, 'xmpp', action=action) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) == 1: # chan mode self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for chan "'+event.target()+'"', debug=True) elif len(event.arguments()) == 2: # participant mode if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'" in chan "'+event.target()+'"', debug=True) return if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+chan) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+chan, send_to_admins=True) bridge.irc_op = False else: # unknown mode self.error(say_levels.debug, 'unknown IRC "mode" event (has 3 arguments):'+event_str) return # Namreply event if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return # Unhandled events self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | 5b31c83aeeeacecbc60b62e840741ce8f9d005cf /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/5b31c83aeeeacecbc60b62e840741ce8f9d005cf/bot.py |
if not self.mode: | if self.stopped: | def _irc_nick_callback(self, error, arguments=None): if not error: if not self.mode: return self.irc_connection.join(self.irc_room, callback=self._irc_join_callback) else: self.mode = None self.say(say_levels.error, 'failed to connect to the IRC chan, leaving ...', on_irc=False) if error in ['nicknameinuse', 'nickcollision']: reason = '"'+self.bot.nickname+'" is already used or reserved on the IRC server' elif error == 'erroneusnickname': reason = '"'+self.bot.nickname+'" got "erroneusnickname"' elif error == 'nicknametoolong': reason = '"'+self.bot.nickname+'" got "nicknametoolong", limit seems to be '+str(len(self.irc_connection.real_nickname)) else: reason = error self._join_irc_failed(reason) | 1c428761fad5529b2fa3940d261d3286f3d1fd2e /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/1c428761fad5529b2fa3940d261d3286f3d1fd2e/bridge.py |
self.mode = None | self.stopped = True | def _irc_nick_callback(self, error, arguments=None): if not error: if not self.mode: return self.irc_connection.join(self.irc_room, callback=self._irc_join_callback) else: self.mode = None self.say(say_levels.error, 'failed to connect to the IRC chan, leaving ...', on_irc=False) if error in ['nicknameinuse', 'nickcollision']: reason = '"'+self.bot.nickname+'" is already used or reserved on the IRC server' elif error == 'erroneusnickname': reason = '"'+self.bot.nickname+'" got "erroneusnickname"' elif error == 'nicknametoolong': reason = '"'+self.bot.nickname+'" got "nicknametoolong", limit seems to be '+str(len(self.irc_connection.real_nickname)) else: reason = error self._join_irc_failed(reason) | 1c428761fad5529b2fa3940d261d3286f3d1fd2e /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/1c428761fad5529b2fa3940d261d3286f3d1fd2e/bridge.py |
if not self.mode: | if self.stopped: | def _xmpp_join_callback(self, errors): """Called by muc._xmpp_presence_handler""" if len(errors) == 0: self.reconnecting = False if not self.mode: return self.bot.error(3, 'succesfully connected on XMPP side of bridge "'+str(self)+'"', debug=True) self.say(say_levels.notice, 'bridge "'+str(self)+'" is running in '+self.mode+' mode', on_irc=False) else: self.mode = None self.say(say_levels.error, 'failed to connect to the XMPP room, leaving ...', on_xmpp=False) for error in errors: try: raise error except xmpp.muc.RemoteServerNotFound: self._RemoteServerNotFound_handler() except: trace = traceback.format_exc().splitlines()[-1] self.bot.error(say_levels.error, 'failed to connect to the XMPP room of bridge "'+str(self)+'", stopping bridge\n'+trace, send_to_admins=True) self.stop(message='Failed to connect to the XMPP room, stopping bridge', log=False) | 1c428761fad5529b2fa3940d261d3286f3d1fd2e /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/1c428761fad5529b2fa3940d261d3286f3d1fd2e/bridge.py |
self.mode = None | self.stopped = True | def _xmpp_join_callback(self, errors): """Called by muc._xmpp_presence_handler""" if len(errors) == 0: self.reconnecting = False if not self.mode: return self.bot.error(3, 'succesfully connected on XMPP side of bridge "'+str(self)+'"', debug=True) self.say(say_levels.notice, 'bridge "'+str(self)+'" is running in '+self.mode+' mode', on_irc=False) else: self.mode = None self.say(say_levels.error, 'failed to connect to the XMPP room, leaving ...', on_xmpp=False) for error in errors: try: raise error except xmpp.muc.RemoteServerNotFound: self._RemoteServerNotFound_handler() except: trace = traceback.format_exc().splitlines()[-1] self.bot.error(say_levels.error, 'failed to connect to the XMPP room of bridge "'+str(self)+'", stopping bridge\n'+trace, send_to_admins=True) self.stop(message='Failed to connect to the XMPP room, stopping bridge', log=False) | 1c428761fad5529b2fa3940d261d3286f3d1fd2e /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/1c428761fad5529b2fa3940d261d3286f3d1fd2e/bridge.py |
self.error('==> Debug: Received XMPP message of unknown type "'+message.getType()+'".', debug=True) | self.error('==> Debug: Received XMPP message of unknown type "'+str(message.getType())+'".', debug=True) | def _xmpp_message_handler(self, dispatcher, message): """[Internal] Manage XMPP messages.""" xmpp_c = dispatcher._owner if message.getBody() == None: return if message.getType() == 'chat': from_bare_jid = unicode(message.getFrom().getNode()+'@'+message.getFrom().getDomain()) for bridge in self.bridges: if from_bare_jid == bridge.xmpp_room_jid: # message comes from a room participant self.error('==> Debug: Received XMPP chat message.', debug=True) self.error(message.__str__(fancy=1), debug=True) try: from_ = bridge.getParticipant(message.getFrom().getResource()) to_ = bridge.getParticipant(xmpp_c.nickname) from_.sayOnIRCTo(to_.nickname, message.getBody()) except Bridge.NoSuchParticipantException: if xmpp_c.nickname == self.nickname: r = self.respond(str(message.getBody()), participant=from_) if isinstance(r, basestring) and len(r) > 0: s = xmpp.protocol.Message(to=message.getFrom(), body=r, typ='chat') self.error('==> Debug: Sending', debug=True) self.error(s.__str__(fancy=1), debug=True) xmpp_c.send(s) else: self.error('=> Debug: won\'t answer.', debug=True) return self.error('=> Debug: XMPP chat message not relayed', debug=True) return # message does not come from a room if xmpp_c.nickname == self.nickname: self.error('==> Debug: Received XMPP chat message.', debug=True) self.error(message.__str__(fancy=1), debug=True) # Find out if the message comes from a bot admin bot_admin = False for jid in self.admins_jid: if xmpp.protocol.JID(jid).bareMatch(message.getFrom()): bot_admin = True break # Respond r = self.respond(str(message.getBody()), bot_admin=bot_admin) if isinstance(r, basestring) and len(r) > 0: s = xmpp.protocol.Message(to=message.getFrom(), body=r, typ='chat') self.error('==> Debug: Sending', debug=True) self.error(s.__str__(fancy=1), debug=True) xmpp_c.send(s) else: self.error('=> Debug: Ignoring XMPP chat message not received on bot connection.', debug=True) elif message.getType() == 'groupchat': # message comes from a room for child in message.getChildren(): if child.getName() == 'delay': # MUC delayed message return if xmpp_c.nickname != self.nickname: self.error('=> Debug: Ignoring XMPP MUC message not received on bot connection.', debug=True) return from_ = xmpp.protocol.JID(message.getFrom()) if unicode(from_.getResource()) == self.nickname: self.error('=> Debug: Ignoring XMPP MUC message sent by self.', debug=True) return room_jid = unicode(from_.getNode()+'@'+from_.getDomain()) for bridge in self.bridges: if room_jid == bridge.xmpp_room_jid: resource = unicode(from_.getResource()) if resource == '': # message comes from the room itself self.error('=> Debug: Ignoring XMPP groupchat message sent by the room.', debug=True) return else: # message comes from a participant of the room self.error('==> Debug: Received XMPP groupchat message.', debug=True) self.error(message.__str__(fancy=1), debug=True) try: participant = bridge.getParticipant(resource) except Bridge.NoSuchParticipantException: if resource != self.nickname: self.error('=> Debug: NoSuchParticipantException "'+resource+'" on "'+str(bridge)+'", WTF ?', debug=True) return participant.sayOnIRC(message.getBody()) return elif message.getType() == 'error': for b in self.bridges: if message.getFrom() == b.xmpp_room_jid: # message comes from a room for c in message.getChildren(): if c.getName() == 'error': for cc in c.getChildren(): if cc.getNamespace() == 'urn:ietf:params:xml:ns:xmpp-stanzas' and cc.getName() != 'text': err = cc.getName() if err == 'not-acceptable': # we sent a message to a room we are not in # probable cause is a MUC server restart # let's restart the bot self.restart() elif err == 'forbidden': # we don't have the permission to speak # let's remove the bridge and tell admins self.error('[Error] Not allowed to speak on the XMPP MUC of bridge '+str(b)+', stopping it', send_to_admins=True) b.stop(message='Not allowed to speak on the XMPP MUC, stopping bridge.') else: self.error('==> Debug: recevied unknown error message', debug=True) self.error(message.__str__(fancy=1), debug=True) return self.error('==> Debug: recevied unknown error message', debug=True) self.error(message.__str__(fancy=1), debug=True) else: self.error('==> Debug: Received XMPP message of unknown type "'+message.getType()+'".', debug=True) self.error(message.__str__(fancy=1), debug=True) | 0b470413dd5d970912c875ad51d84d2d99c7c36d /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/0b470413dd5d970912c875ad51d84d2d99c7c36d/bot.py |
raise Exception('[Error] unknown error for "'+self.bot.nickname+'" on bridge "'+str(self)+'", limit seems to be '+str(arguments[0])) | raise Exception('[Error] unknown error for "'+self.bot.nickname+'" on bridge "'+str(self)+'"') | def _irc_nick_callback(self, error, arguments=[]): if error == None: if self.mode == None: return self.irc_connection.join(self.irc_room) self.bot.error('===> Debug: successfully connected on IRC side of bridge "'+str(self)+'"', debug=True) self.say('[Notice] bridge "'+str(self)+'" is running in '+self.mode+' mode', on_xmpp=False) else: self.mode = None if self.xmpp_room.connected == True: self.say('[Error] failed to connect to the IRC chan, leaving ...', on_irc=False) try: if error == 'nicknameinuse': raise Exception('[Error] "'+self.bot.nickname+'" is already used in the IRC chan or reserved on the IRC server of bridge "'+str(self)+'"') elif error == 'nickcollision': raise Exception('[Error] "'+self.bot.nickname+'" is already used or reserved on the IRC server of bridge "'+str(self)+'"') elif error == 'erroneusnickname': raise Exception('[Error] "'+self.bot.nickname+'" got "erroneusnickname" on bridge "'+str(self)+'"') elif error == 'nicknametoolong': raise Exception('[Error] "'+self.bot.nickname+'" got "nicknametoolong" on bridge "'+str(self)+'", limit seems to be '+str(arguments[0])) else: raise Exception('[Error] unknown error for "'+self.bot.nickname+'" on bridge "'+str(self)+'", limit seems to be '+str(arguments[0])) except: traceback.print_exc() self.bot.error('[Error] failed to connect to the IRC chan of bridge "'+str(self)+'", stopping bridge', send_to_admins=True) self.stop(message='failed to connect to the IRC chan') | ce50101a01b0559af8845fa4c4bfbc1432c29caf /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/ce50101a01b0559af8845fa4c4bfbc1432c29caf/bridge.py |
ret += ' - say_level='+bridge._say_levels[b.say_level] | ret += ' - say_level='+Bridge._say_levels[b.say_level] | def respond(self, message, participant=None, bot_admin=False): ret = '' command = shlex.split(message) args_array = [] if len(command) > 1: args_array = command[1:] command = command[0] if isinstance(participant, Participant) and bot_admin != participant.bot_admin: bot_admin = participant.bot_admin if command == 'xmpp-participants': if not isinstance(participant, Participant): for b in self.bridges: xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp']) ret += '\nparticipants on '+b.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) return ret else: xmpp_participants_nicknames = participant.bridge.get_participants_nicknames_list(protocols=['xmpp']) return '\nparticipants on '+participant.bridge.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) elif command == 'irc-participants': if not isinstance(participant, Participant): for b in self.bridges: irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc']) ret += '\nparticipants on '+b.irc_room+' at '+b.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) return ret else: irc_participants_nicknames = participant.bridge.get_participants_nicknames_list(protocols=['irc']) return '\nparticipants on '+participant.bridge.irc_room+' at '+participant.bridge.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) elif command == 'bridges': parser = ArgumentParser(prog=command) parser.add_argument('--show-mode', default=False, action='store_true') parser.add_argument('--show-say-level', default=False, action='store_true') parser.add_argument('--show-participants', default=False, action='store_true') try: args = parser.parse_args(args_array) except ArgumentParser.ParseException as e: return '\n'+e.args[1] ret = 'List of bridges:' for i, b in enumerate(self.bridges): ret += '\n'+str(i+1)+' - '+str(b) if args.show_mode: ret += ' - mode='+b.mode if args.show_say_level: ret += ' - say_level='+bridge._say_levels[b.say_level] if args.show_participants: xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp']) ret += '\nparticipants on XMPP ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc']) ret += '\nparticipants on IRC ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) if b.irc_connection == None: ret += ' - this bridge is stopped, use "restart-bridge '+str(i+1)+'" to restart it' return ret elif command in Bot.admin_commands: if bot_admin == False: return 'You have to be a bot admin to use this command.' if command == 'add-bridge': parser = ArgumentParser(prog=command) parser.add_argument('xmpp_room_jid', type=str) parser.add_argument('irc_chan', type=str) parser.add_argument('irc_server', type=str) parser.add_argument('--mode', choices=bridge._modes, default='normal') parser.add_argument('--say-level', choices=bridge._say_levels, default='all') parser.add_argument('--irc-port', type=int, default=6667) try: args = parser.parse_args(args_array) except ArgumentParser.ParseException as e: return '\n'+e.args[1] self.new_bridge(args.xmpp_room_jid, args.irc_chan, args.irc_server, args.mode, args.say_level, irc_port=args.irc_port) return 'Bridge added.' elif command == 'add-xmpp-admin': parser = ArgumentParser(prog=command) parser.add_argument('jid', type=str) try: args = parser.parse_args(args_array) except ArgumentParser.ParseException as e: return '\n'+e.args[1] self.admins_jid.append(args.jid) for b in self.bridges: for p in b.participants: if p.real_jid != None and xmpp.protocol.JID(args.jid).bareMatch(p.real_jid): p.bot_admin = True return 'XMPP admin added.' elif command == 'restart-bot': self.restart() return elif command == 'halt': self.stop() return elif command in ['remove-bridge', 'restart-bridge', 'stop-bridge']: # we need to know which bridge the command is for if len(args_array) == 0: if isinstance(participant, Participant): b = participant.bridge else: return 'You must specify a bridge. '+self.respond('bridges') else: try: bn = int(args_array[0]) if bn < 1: raise IndexError b = self.bridges[bn-1] except IndexError: return 'Invalid bridge number "'+str(bn)+'". '+self.respond('bridges') except ValueError: bridges = self.findBridges(args_array) if len(bridges) == 0: return 'No bridge found matching "'+' '.join(args_array)+'". '+self.respond('bridges') elif len(bridges) == 1: b = bridges[0] elif len(bridges) > 1: return 'More than one bridge matches "'+' '.join(args_array)+'", please be more specific. '+self.respond('bridges') if command == 'remove-bridge': self.removeBridge(b) return 'Bridge removed.' elif command == 'restart-bridge': b.restart() return 'Bridge restarted.' elif command == 'stop-bridge': b.stop() return 'Bridge stopped.' else: ret = 'Error: "'+command+'" is not a valid command.\ncommands: '+' '.join(Bot.commands) if bot_admin == True: return ret+'\n'+'admin commands: '+' '.join(Bot.admin_commands) else: return ret | 275ec36042aca0f6bbdba8a20d1dc9ac7d0bf12e /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/275ec36042aca0f6bbdba8a20d1dc9ac7d0bf12e/bot.py |
parser.add_argument('--mode', choices=bridge._modes, default='normal') parser.add_argument('--say-level', choices=bridge._say_levels, default='all') | parser.add_argument('--mode', choices=Bridge._modes, default='normal') parser.add_argument('--say-level', choices=Bridge._say_levels, default='all') | def respond(self, message, participant=None, bot_admin=False): ret = '' command = shlex.split(message) args_array = [] if len(command) > 1: args_array = command[1:] command = command[0] if isinstance(participant, Participant) and bot_admin != participant.bot_admin: bot_admin = participant.bot_admin if command == 'xmpp-participants': if not isinstance(participant, Participant): for b in self.bridges: xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp']) ret += '\nparticipants on '+b.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) return ret else: xmpp_participants_nicknames = participant.bridge.get_participants_nicknames_list(protocols=['xmpp']) return '\nparticipants on '+participant.bridge.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) elif command == 'irc-participants': if not isinstance(participant, Participant): for b in self.bridges: irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc']) ret += '\nparticipants on '+b.irc_room+' at '+b.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) return ret else: irc_participants_nicknames = participant.bridge.get_participants_nicknames_list(protocols=['irc']) return '\nparticipants on '+participant.bridge.irc_room+' at '+participant.bridge.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) elif command == 'bridges': parser = ArgumentParser(prog=command) parser.add_argument('--show-mode', default=False, action='store_true') parser.add_argument('--show-say-level', default=False, action='store_true') parser.add_argument('--show-participants', default=False, action='store_true') try: args = parser.parse_args(args_array) except ArgumentParser.ParseException as e: return '\n'+e.args[1] ret = 'List of bridges:' for i, b in enumerate(self.bridges): ret += '\n'+str(i+1)+' - '+str(b) if args.show_mode: ret += ' - mode='+b.mode if args.show_say_level: ret += ' - say_level='+bridge._say_levels[b.say_level] if args.show_participants: xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp']) ret += '\nparticipants on XMPP ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc']) ret += '\nparticipants on IRC ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) if b.irc_connection == None: ret += ' - this bridge is stopped, use "restart-bridge '+str(i+1)+'" to restart it' return ret elif command in Bot.admin_commands: if bot_admin == False: return 'You have to be a bot admin to use this command.' if command == 'add-bridge': parser = ArgumentParser(prog=command) parser.add_argument('xmpp_room_jid', type=str) parser.add_argument('irc_chan', type=str) parser.add_argument('irc_server', type=str) parser.add_argument('--mode', choices=bridge._modes, default='normal') parser.add_argument('--say-level', choices=bridge._say_levels, default='all') parser.add_argument('--irc-port', type=int, default=6667) try: args = parser.parse_args(args_array) except ArgumentParser.ParseException as e: return '\n'+e.args[1] self.new_bridge(args.xmpp_room_jid, args.irc_chan, args.irc_server, args.mode, args.say_level, irc_port=args.irc_port) return 'Bridge added.' elif command == 'add-xmpp-admin': parser = ArgumentParser(prog=command) parser.add_argument('jid', type=str) try: args = parser.parse_args(args_array) except ArgumentParser.ParseException as e: return '\n'+e.args[1] self.admins_jid.append(args.jid) for b in self.bridges: for p in b.participants: if p.real_jid != None and xmpp.protocol.JID(args.jid).bareMatch(p.real_jid): p.bot_admin = True return 'XMPP admin added.' elif command == 'restart-bot': self.restart() return elif command == 'halt': self.stop() return elif command in ['remove-bridge', 'restart-bridge', 'stop-bridge']: # we need to know which bridge the command is for if len(args_array) == 0: if isinstance(participant, Participant): b = participant.bridge else: return 'You must specify a bridge. '+self.respond('bridges') else: try: bn = int(args_array[0]) if bn < 1: raise IndexError b = self.bridges[bn-1] except IndexError: return 'Invalid bridge number "'+str(bn)+'". '+self.respond('bridges') except ValueError: bridges = self.findBridges(args_array) if len(bridges) == 0: return 'No bridge found matching "'+' '.join(args_array)+'". '+self.respond('bridges') elif len(bridges) == 1: b = bridges[0] elif len(bridges) > 1: return 'More than one bridge matches "'+' '.join(args_array)+'", please be more specific. '+self.respond('bridges') if command == 'remove-bridge': self.removeBridge(b) return 'Bridge removed.' elif command == 'restart-bridge': b.restart() return 'Bridge restarted.' elif command == 'stop-bridge': b.stop() return 'Bridge stopped.' else: ret = 'Error: "'+command+'" is not a valid command.\ncommands: '+' '.join(Bot.commands) if bot_admin == True: return ret+'\n'+'admin commands: '+' '.join(Bot.admin_commands) else: return ret | 275ec36042aca0f6bbdba8a20d1dc9ac7d0bf12e /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/275ec36042aca0f6bbdba8a20d1dc9ac7d0bf12e/bot.py |
bridges = self.findBridges(args_array) | bridges = self.findBridges(args_array[0]) | def respond(self, message, participant=None, bot_admin=False): ret = '' command = shlex.split(message) args_array = [] if len(command) > 1: args_array = command[1:] command = command[0] if isinstance(participant, Participant) and bot_admin != participant.bot_admin: bot_admin = participant.bot_admin if command == 'xmpp-participants': if not isinstance(participant, Participant): for b in self.bridges: xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp']) ret += '\nparticipants on '+b.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) return ret else: xmpp_participants_nicknames = participant.bridge.get_participants_nicknames_list(protocols=['xmpp']) return '\nparticipants on '+participant.bridge.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) elif command == 'irc-participants': if not isinstance(participant, Participant): for b in self.bridges: irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc']) ret += '\nparticipants on '+b.irc_room+' at '+b.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) return ret else: irc_participants_nicknames = participant.bridge.get_participants_nicknames_list(protocols=['irc']) return '\nparticipants on '+participant.bridge.irc_room+' at '+participant.bridge.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) elif command == 'bridges': parser = ArgumentParser(prog=command) parser.add_argument('--show-mode', default=False, action='store_true') parser.add_argument('--show-say-level', default=False, action='store_true') parser.add_argument('--show-participants', default=False, action='store_true') try: args = parser.parse_args(args_array) except ArgumentParser.ParseException as e: return '\n'+e.args[1] ret = 'List of bridges:' for i, b in enumerate(self.bridges): ret += '\n'+str(i+1)+' - '+str(b) if args.show_mode: ret += ' - mode='+b.mode if args.show_say_level: ret += ' - say_level='+bridge._say_levels[b.say_level] if args.show_participants: xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp']) ret += '\nparticipants on XMPP ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc']) ret += '\nparticipants on IRC ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) if b.irc_connection == None: ret += ' - this bridge is stopped, use "restart-bridge '+str(i+1)+'" to restart it' return ret elif command in Bot.admin_commands: if bot_admin == False: return 'You have to be a bot admin to use this command.' if command == 'add-bridge': parser = ArgumentParser(prog=command) parser.add_argument('xmpp_room_jid', type=str) parser.add_argument('irc_chan', type=str) parser.add_argument('irc_server', type=str) parser.add_argument('--mode', choices=bridge._modes, default='normal') parser.add_argument('--say-level', choices=bridge._say_levels, default='all') parser.add_argument('--irc-port', type=int, default=6667) try: args = parser.parse_args(args_array) except ArgumentParser.ParseException as e: return '\n'+e.args[1] self.new_bridge(args.xmpp_room_jid, args.irc_chan, args.irc_server, args.mode, args.say_level, irc_port=args.irc_port) return 'Bridge added.' elif command == 'add-xmpp-admin': parser = ArgumentParser(prog=command) parser.add_argument('jid', type=str) try: args = parser.parse_args(args_array) except ArgumentParser.ParseException as e: return '\n'+e.args[1] self.admins_jid.append(args.jid) for b in self.bridges: for p in b.participants: if p.real_jid != None and xmpp.protocol.JID(args.jid).bareMatch(p.real_jid): p.bot_admin = True return 'XMPP admin added.' elif command == 'restart-bot': self.restart() return elif command == 'halt': self.stop() return elif command in ['remove-bridge', 'restart-bridge', 'stop-bridge']: # we need to know which bridge the command is for if len(args_array) == 0: if isinstance(participant, Participant): b = participant.bridge else: return 'You must specify a bridge. '+self.respond('bridges') else: try: bn = int(args_array[0]) if bn < 1: raise IndexError b = self.bridges[bn-1] except IndexError: return 'Invalid bridge number "'+str(bn)+'". '+self.respond('bridges') except ValueError: bridges = self.findBridges(args_array) if len(bridges) == 0: return 'No bridge found matching "'+' '.join(args_array)+'". '+self.respond('bridges') elif len(bridges) == 1: b = bridges[0] elif len(bridges) > 1: return 'More than one bridge matches "'+' '.join(args_array)+'", please be more specific. '+self.respond('bridges') if command == 'remove-bridge': self.removeBridge(b) return 'Bridge removed.' elif command == 'restart-bridge': b.restart() return 'Bridge restarted.' elif command == 'stop-bridge': b.stop() return 'Bridge stopped.' else: ret = 'Error: "'+command+'" is not a valid command.\ncommands: '+' '.join(Bot.commands) if bot_admin == True: return ret+'\n'+'admin commands: '+' '.join(Bot.admin_commands) else: return ret | 275ec36042aca0f6bbdba8a20d1dc9ac7d0bf12e /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/275ec36042aca0f6bbdba8a20d1dc9ac7d0bf12e/bot.py |
return 'No bridge found matching "'+' '.join(args_array)+'". '+self.respond('bridges') | return 'No bridge found matching "'+args_array[0]+'". '+self.respond('bridges') | def respond(self, message, participant=None, bot_admin=False): ret = '' command = shlex.split(message) args_array = [] if len(command) > 1: args_array = command[1:] command = command[0] if isinstance(participant, Participant) and bot_admin != participant.bot_admin: bot_admin = participant.bot_admin if command == 'xmpp-participants': if not isinstance(participant, Participant): for b in self.bridges: xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp']) ret += '\nparticipants on '+b.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) return ret else: xmpp_participants_nicknames = participant.bridge.get_participants_nicknames_list(protocols=['xmpp']) return '\nparticipants on '+participant.bridge.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) elif command == 'irc-participants': if not isinstance(participant, Participant): for b in self.bridges: irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc']) ret += '\nparticipants on '+b.irc_room+' at '+b.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) return ret else: irc_participants_nicknames = participant.bridge.get_participants_nicknames_list(protocols=['irc']) return '\nparticipants on '+participant.bridge.irc_room+' at '+participant.bridge.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) elif command == 'bridges': parser = ArgumentParser(prog=command) parser.add_argument('--show-mode', default=False, action='store_true') parser.add_argument('--show-say-level', default=False, action='store_true') parser.add_argument('--show-participants', default=False, action='store_true') try: args = parser.parse_args(args_array) except ArgumentParser.ParseException as e: return '\n'+e.args[1] ret = 'List of bridges:' for i, b in enumerate(self.bridges): ret += '\n'+str(i+1)+' - '+str(b) if args.show_mode: ret += ' - mode='+b.mode if args.show_say_level: ret += ' - say_level='+bridge._say_levels[b.say_level] if args.show_participants: xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp']) ret += '\nparticipants on XMPP ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc']) ret += '\nparticipants on IRC ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) if b.irc_connection == None: ret += ' - this bridge is stopped, use "restart-bridge '+str(i+1)+'" to restart it' return ret elif command in Bot.admin_commands: if bot_admin == False: return 'You have to be a bot admin to use this command.' if command == 'add-bridge': parser = ArgumentParser(prog=command) parser.add_argument('xmpp_room_jid', type=str) parser.add_argument('irc_chan', type=str) parser.add_argument('irc_server', type=str) parser.add_argument('--mode', choices=bridge._modes, default='normal') parser.add_argument('--say-level', choices=bridge._say_levels, default='all') parser.add_argument('--irc-port', type=int, default=6667) try: args = parser.parse_args(args_array) except ArgumentParser.ParseException as e: return '\n'+e.args[1] self.new_bridge(args.xmpp_room_jid, args.irc_chan, args.irc_server, args.mode, args.say_level, irc_port=args.irc_port) return 'Bridge added.' elif command == 'add-xmpp-admin': parser = ArgumentParser(prog=command) parser.add_argument('jid', type=str) try: args = parser.parse_args(args_array) except ArgumentParser.ParseException as e: return '\n'+e.args[1] self.admins_jid.append(args.jid) for b in self.bridges: for p in b.participants: if p.real_jid != None and xmpp.protocol.JID(args.jid).bareMatch(p.real_jid): p.bot_admin = True return 'XMPP admin added.' elif command == 'restart-bot': self.restart() return elif command == 'halt': self.stop() return elif command in ['remove-bridge', 'restart-bridge', 'stop-bridge']: # we need to know which bridge the command is for if len(args_array) == 0: if isinstance(participant, Participant): b = participant.bridge else: return 'You must specify a bridge. '+self.respond('bridges') else: try: bn = int(args_array[0]) if bn < 1: raise IndexError b = self.bridges[bn-1] except IndexError: return 'Invalid bridge number "'+str(bn)+'". '+self.respond('bridges') except ValueError: bridges = self.findBridges(args_array) if len(bridges) == 0: return 'No bridge found matching "'+' '.join(args_array)+'". '+self.respond('bridges') elif len(bridges) == 1: b = bridges[0] elif len(bridges) > 1: return 'More than one bridge matches "'+' '.join(args_array)+'", please be more specific. '+self.respond('bridges') if command == 'remove-bridge': self.removeBridge(b) return 'Bridge removed.' elif command == 'restart-bridge': b.restart() return 'Bridge restarted.' elif command == 'stop-bridge': b.stop() return 'Bridge stopped.' else: ret = 'Error: "'+command+'" is not a valid command.\ncommands: '+' '.join(Bot.commands) if bot_admin == True: return ret+'\n'+'admin commands: '+' '.join(Bot.admin_commands) else: return ret | 275ec36042aca0f6bbdba8a20d1dc9ac7d0bf12e /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/275ec36042aca0f6bbdba8a20d1dc9ac7d0bf12e/bot.py |
return 'More than one bridge matches "'+' '.join(args_array)+'", please be more specific. '+self.respond('bridges') | return 'More than one bridge matches "'+args_array[0]+'", please be more specific. '+self.respond('bridges') | def respond(self, message, participant=None, bot_admin=False): ret = '' command = shlex.split(message) args_array = [] if len(command) > 1: args_array = command[1:] command = command[0] if isinstance(participant, Participant) and bot_admin != participant.bot_admin: bot_admin = participant.bot_admin if command == 'xmpp-participants': if not isinstance(participant, Participant): for b in self.bridges: xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp']) ret += '\nparticipants on '+b.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) return ret else: xmpp_participants_nicknames = participant.bridge.get_participants_nicknames_list(protocols=['xmpp']) return '\nparticipants on '+participant.bridge.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) elif command == 'irc-participants': if not isinstance(participant, Participant): for b in self.bridges: irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc']) ret += '\nparticipants on '+b.irc_room+' at '+b.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) return ret else: irc_participants_nicknames = participant.bridge.get_participants_nicknames_list(protocols=['irc']) return '\nparticipants on '+participant.bridge.irc_room+' at '+participant.bridge.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) elif command == 'bridges': parser = ArgumentParser(prog=command) parser.add_argument('--show-mode', default=False, action='store_true') parser.add_argument('--show-say-level', default=False, action='store_true') parser.add_argument('--show-participants', default=False, action='store_true') try: args = parser.parse_args(args_array) except ArgumentParser.ParseException as e: return '\n'+e.args[1] ret = 'List of bridges:' for i, b in enumerate(self.bridges): ret += '\n'+str(i+1)+' - '+str(b) if args.show_mode: ret += ' - mode='+b.mode if args.show_say_level: ret += ' - say_level='+bridge._say_levels[b.say_level] if args.show_participants: xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp']) ret += '\nparticipants on XMPP ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc']) ret += '\nparticipants on IRC ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) if b.irc_connection == None: ret += ' - this bridge is stopped, use "restart-bridge '+str(i+1)+'" to restart it' return ret elif command in Bot.admin_commands: if bot_admin == False: return 'You have to be a bot admin to use this command.' if command == 'add-bridge': parser = ArgumentParser(prog=command) parser.add_argument('xmpp_room_jid', type=str) parser.add_argument('irc_chan', type=str) parser.add_argument('irc_server', type=str) parser.add_argument('--mode', choices=bridge._modes, default='normal') parser.add_argument('--say-level', choices=bridge._say_levels, default='all') parser.add_argument('--irc-port', type=int, default=6667) try: args = parser.parse_args(args_array) except ArgumentParser.ParseException as e: return '\n'+e.args[1] self.new_bridge(args.xmpp_room_jid, args.irc_chan, args.irc_server, args.mode, args.say_level, irc_port=args.irc_port) return 'Bridge added.' elif command == 'add-xmpp-admin': parser = ArgumentParser(prog=command) parser.add_argument('jid', type=str) try: args = parser.parse_args(args_array) except ArgumentParser.ParseException as e: return '\n'+e.args[1] self.admins_jid.append(args.jid) for b in self.bridges: for p in b.participants: if p.real_jid != None and xmpp.protocol.JID(args.jid).bareMatch(p.real_jid): p.bot_admin = True return 'XMPP admin added.' elif command == 'restart-bot': self.restart() return elif command == 'halt': self.stop() return elif command in ['remove-bridge', 'restart-bridge', 'stop-bridge']: # we need to know which bridge the command is for if len(args_array) == 0: if isinstance(participant, Participant): b = participant.bridge else: return 'You must specify a bridge. '+self.respond('bridges') else: try: bn = int(args_array[0]) if bn < 1: raise IndexError b = self.bridges[bn-1] except IndexError: return 'Invalid bridge number "'+str(bn)+'". '+self.respond('bridges') except ValueError: bridges = self.findBridges(args_array) if len(bridges) == 0: return 'No bridge found matching "'+' '.join(args_array)+'". '+self.respond('bridges') elif len(bridges) == 1: b = bridges[0] elif len(bridges) > 1: return 'More than one bridge matches "'+' '.join(args_array)+'", please be more specific. '+self.respond('bridges') if command == 'remove-bridge': self.removeBridge(b) return 'Bridge removed.' elif command == 'restart-bridge': b.restart() return 'Bridge restarted.' elif command == 'stop-bridge': b.stop() return 'Bridge stopped.' else: ret = 'Error: "'+command+'" is not a valid command.\ncommands: '+' '.join(Bot.commands) if bot_admin == True: return ret+'\n'+'admin commands: '+' '.join(Bot.admin_commands) else: return ret | 275ec36042aca0f6bbdba8a20d1dc9ac7d0bf12e /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/275ec36042aca0f6bbdba8a20d1dc9ac7d0bf12e/bot.py |
if isinstance(self.xmpp_c, xmpp.client.Client): self.bridge.bot.close_xmpp_connection(self.nickname) self.xmpp_c = None | self._close_xmpp_connection() | def _xmpp_join_callback(self, errors): if len(errors) == 0: m = '"'+self.nickname+'" duplicate succesfully created on XMPP side of bridge "'+str(self.bridge)+'"' if self.nickname != self.duplicate_nickname: m += ' using nickname "'+self.duplicate_nickname+'"' self.bridge.say(say_levels.info, '"'+self.nickname+'" will appear as "'+self.duplicate_nickname+'" on XMPP because its real nickname is reserved or contains unauthorized characters') self.bridge.bot.error(3, m, debug=True) elif self.xmpp_c != 'both': for error in errors: try: raise error except xmpp.muc.NicknameConflict as e: if xmpp.protocol.JID(e.args[0]).getResource() != self.duplicate_nickname: return if self.bridge.mode == 'bypass': new_duplicate_nickname = self._get_new_duplicate_nickname() if new_duplicate_nickname != None: self.bridge.bot.error(3, '"'+self.duplicate_nickname+'" is already used in the XMPP MUC or reserved on the XMPP server of bridge "'+str(self.bridge)+'", trying "'+new_duplicate_nickname+'"', debug=True) if self.duplicate_nickname == self.nickname: self.bridge.say(say_levels.info, 'The nickname "'+self.duplicate_nickname+'" is used on both rooms or reserved on the XMPP server') self.duplicate_nickname = new_duplicate_nickname if isinstance(self.xmpp_c, xmpp.client.Client): self.bridge.bot.close_xmpp_connection(self.nickname) self.xmpp_c = None self.create_duplicate_on_xmpp() return else: self.bridge.say(say_levels.warning, 'The nickname "'+self.nickname+'" is used on both rooms or reserved on the XMPP server', log=True) if isinstance(self.muc, xmpp.muc) and self.muc.connected: self.muc.leave('Changed nickname to "'+self.nickname+'"') except xmpp.muc.RoomIsFull: self.bridge.say(say_levels.warning, 'XMPP room is full', log=True) except xmpp.muc.RemoteServerNotFound: self.bridge._RemoteServerNotFound_handler() if isinstance(self.xmpp_c, xmpp.client.Client): self.bridge.bot.close_xmpp_connection(self.nickname) self.xmpp_c = None | 165527f248716d349e5a71d2c46d0acb7618f09d /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/165527f248716d349e5a71d2c46d0acb7618f09d/participant.py |
if event.eventtype() == 'quit' and ( bridge.mode != 'normal' or isinstance(from_.irc_connection, irclib.ServerConnection) ): continue | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return nickname = None if event.source() != None: if '!' in event.source(): nickname = event.source().split('!')[0] # Events that we want to ignore only in some cases if event.eventtype() in ['umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns']: if connection.really_connected == False: if event.target() == connection.nickname: connection.really_connected = True connection._call_nick_callbacks(None) elif len(connection.nick_callbacks) > 0: self.error(3, 'event target ('+event.target()+') and connection nickname ('+connection.nickname+') don\'t match') connection._call_nick_callbacks('nicknametoolong', arguments=[len(event.target())]) self.error(1, 'ignoring '+event.eventtype(), debug=True) return # A string representation of the event event_str = 'connection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.\n'+event_str printed_event = False if event.eventtype() in ['pubmsg', 'action', 'privmsg', 'quit', 'part', 'nick', 'kick']: if nickname == None: return handled = False if event.eventtype() in ['quit', 'part'] and nickname == self.nickname: return if event.eventtype() in ['quit', 'part', 'nick', 'kick']: if connection.get_nickname() != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return else: self.error(2, debug_str, debug=True) printed_event = True if event.eventtype() == 'kick' and len(event.arguments()) < 1: self.error(1, 'length of arguments should be greater than 0 for a '+event.eventtype()+' event') return if event.eventtype() in ['pubmsg', 'action']: if connection.get_nickname() != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return if nickname == self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' sent by self', debug=True) return # TODO: lock self.bridges for thread safety for bridge in self.bridges: if connection.server != bridge.irc_server: continue try: from_ = bridge.getParticipant(nickname) except Bridge.NoSuchParticipantException: continue # Private message if event.eventtype() == 'privmsg': if event.target() == None: return try: to_ = bridge.getParticipant(event.target().split('!')[0]) self.error(2, debug_str, debug=True) from_.sayOnXMPPTo(to_.nickname, event.arguments()[0]) return except Bridge.NoSuchParticipantException: if event.target().split('!')[0] == self.nickname: # Message is for the bot self.error(2, debug_str, debug=True) connection.privmsg(from_.nickname, self.respond(event.arguments()[0])) return else: continue # kick handling if event.eventtype() == 'kick': if event.target().lower() == bridge.irc_room: try: kicked = bridge.getParticipant(event.arguments()[0]) if isinstance(kicked.irc_connection, irclib.ServerConnection): kicked.irc_connection.join(bridge.irc_room) else: if len(event.arguments()) > 1: bridge.removeParticipant('irc', kicked.nickname, 'Kicked by '+nickname+' with reason: '+event.arguments()[1]) else: bridge.removeParticipant('irc', kicked.nickname, 'Kicked by '+nickname+' (no reason was given)') return except Bridge.NoSuchParticipantException: self.error(1, 'a participant that was not here has been kicked ? WTF ?') return else: continue # Leaving events if event.eventtype() == 'quit' or event.eventtype() == 'part' and event.target().lower() == bridge.irc_room: if event.eventtype() == 'quit' and ( bridge.mode != 'normal' or isinstance(from_.irc_connection, irclib.ServerConnection) ): continue if len(event.arguments()) > 0: leave_message = event.arguments()[0] elif event.eventtype() == 'quit': leave_message = 'Left server.' elif event.eventtype() == 'part': leave_message = 'Left channel.' else: leave_message = '' bridge.removeParticipant('irc', from_.nickname, leave_message) handled = True continue # Nickname change if event.eventtype() == 'nick': from_.changeNickname(event.target(), 'xmpp') handled = True continue # Chan message if event.eventtype() in ['pubmsg', 'action']: if bridge.irc_room == event.target().lower() and bridge.irc_server == connection.server: self.error(2, debug_str, debug=True) message = event.arguments()[0] if event.eventtype() == 'action': message = '/me '+message from_.sayOnXMPP(message) return else: continue if handled: return # Handle bannedfromchan if event.eventtype() == 'bannedfromchan': if len(event.arguments()) < 1: self.error(1, 'length of arguments should be greater than 0 for a '+event.eventtype()+' event') return for bridge in self.bridges: if connection.server != bridge.irc_server or event.arguments()[0].lower() != bridge.irc_room: continue if event.target() == self.nickname: self.error(say_levels.error, 'the nickname "'+event.target()+'" is banned from the IRC chan of bridge "'+str(bridge)+'"') raise Exception('[Error] the nickname "'+event.target()+'" is banned from the IRC chan of bridge "'+str(bridge)+'"') else: try: banned = bridge.getParticipant(event.target()) if banned.irc_connection != 'bannedfromchan': banned.irc_connection = 'bannedfromchan' self.error(2, debug_str, debug=True) bridge.say(say_levels.warning, 'the nickname "'+event.target()+'" is banned from the IRC chan', log=True) else: self.error(1, 'ignoring '+event.eventtype(), debug=True) except Bridge.NoSuchParticipantException: self.error(1, 'no such participant. WTF ?') return return # Joining events if event.eventtype() in ['namreply', 'join']: if connection.get_nickname() != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return if event.eventtype() == 'namreply': for bridge in self.getBridges(irc_room=event.arguments()[1].lower(), irc_server=connection.server): for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.addParticipant('irc', nickname) return elif event.eventtype() == 'join': bridges = self.getBridges(irc_room=event.target().lower(), irc_server=connection.server) if len(bridges) == 0: self.error(2, debug_str, debug=True) self.error(3, 'no bridge found for "'+event.target().lower()+' at '+connection.server+'"', debug=True) return for bridge in bridges: bridge.addParticipant('irc', nickname, irc_id=event.source()) return if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(2, debug_str, send_to_admins=True) return if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridges = self.getBridges(irc_room=event.arguments()[0], irc_server=connection.server) if len(bridges) > 1: raise Exception, 'more than one bridge for one irc chan, WTF ?' bridge = bridges[0] if connection.get_nickname() == self.nickname: bridge._join_irc_failed() else: p = bridge.getParticipant(connection.get_nickname()) p._close_irc_connection('') p.irc_connection = error return # Unhandled events if not printed_event: self.error(say_levels.debug, 'The following IRC event was not handled:\n'+event_str+'\n', send_to_admins=True) else: self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:\n'+event_str) | e03914fb70c84a5cbb53ca2fda4efa26003363d9 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/e03914fb70c84a5cbb53ca2fda4efa26003363d9/bot.py |
|
self.disconnect("Connection reset by peer.") | self.disconnect("Connection reset by peer") | def send_raw(self, string): """Send raw string to the server. | 30d79e85854b7dc034c00c4ae9de3eb9fcf959b0 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/30d79e85854b7dc034c00c4ae9de3eb9fcf959b0/irclib.py |
self.disconnect("Connection reset by peer.") | self.disconnect("Connection reset by peer") | def privmsg(self, string): """Send data to DCC peer. | 30d79e85854b7dc034c00c4ae9de3eb9fcf959b0 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/30d79e85854b7dc034c00c4ae9de3eb9fcf959b0/irclib.py |
for bridge in [b for b in bridges]: | for bridge in self.bridges: | def findBridges(self, str_array): # TODO: lock self.bridges for thread safety bridges = [b for b in self.bridges] for bridge in [b for b in bridges]: for s in str_array: if not s in str(bridge): bridges.remove(bridge) break return bridges | c93a7ccdc6c9b4ab53659246a60b0508a00f7633 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/c93a7ccdc6c9b4ab53659246a60b0508a00f7633/bot.py |
self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() == 'kick' and len(event.arguments()) == 0: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() == 'mode' and len(event.arguments()) < 2: self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event'+event_str) | self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event'+event_str) return if event.eventtype() in ['kick', 'mode'] and len(event.arguments()) == 0: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event'+event_str) | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey', 'topic', 'noorigin']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return source_nickname = None if event.source() and '!' in event.source(): source_nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str handled = False # Private message if event.eventtype() in ['privmsg', 'action']: if event.target() == self.nickname: # message is for the bot connection.privmsg(source_nickname, self.respond(event.arguments()[0])) return elif not irclib.is_channel(event.target()[0]): # search if the IRC user who sent the message is in one of the bridges for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) # he is, forward the message on XMPP if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp_to(connection.nickname, event.arguments()[0], action=action) return except Bridge.NoSuchParticipantException: continue # he isn't, send an error connection.privmsg(source_nickname, 'XIB error: you cannot send a private message to an XMPP user if you are not in one of the chans he is in') # Connection errors if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Server events if event.eventtype() in ['quit', 'nick']: for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: continue handled = True # Quit event if event.eventtype() == 'quit': if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left server.' bridge.remove_participant('irc', from_.nickname, leave_message) continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') continue if handled: return # Chan events if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'mode', 'join']: if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'join'] and not source_nickname: self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() == 'kick' and len(event.arguments()) == 0: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() == 'mode' and len(event.arguments()) < 2: self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event'+event_str) return chan = event.target().lower() bridge = self.get_bridge(irc_room=chan, irc_server=connection.server) try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: from_ = None # Join event if event.eventtype() == 'join': bridge.add_participant('irc', source_nickname) return # kick handling if event.eventtype() == 'kick': try: kicked = bridge.get_participant(event.arguments()[0]) except Bridge.NoSuchParticipantException: self.error(2, debug_str, debug=True) self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return leave_message = 'kicked by '+nickname if len(event.arguments()) > 1: leave_message += ' with reason: '+event.arguments()[1] else: leave_message += ' (no reason was given)' log_message = '"'+kicked.nickname+'" has been '+leave_message self.error(say_levels.warning, log_message) if isinstance(kicked.irc_connection, irclib.ServerConnection): # an IRC duplicate of an XMPP user has been kicked, auto-rejoin kicked.irc_connection.join(bridge.irc_room) elif isinstance(kicked.xmpp_c, xmpp.client.Client): # an IRC user has been kicked, make its duplicate leave kicked.leave(m) else: # an IRC user with no duplicate on XMPP has been kicked, say it on XMPP bridge.say(say_levels.warning, log_message, on_irc=False) return # Part event if event.eventtype() == 'part': if not from_: self.error(say_levels.debug, 'a participant that wasn\'t here left:'+event_str) return if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left channel.' bridge.remove_participant('irc', from_.nickname, leave_message) return # Chan message if event.eventtype() in ['pubmsg', 'action']: message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False if isinstance(from_, Participant): from_.say_on_xmpp(message, action=action) else: bridge.say_on_behalf(source_nickname, message, 'xmpp', action=action) return # Mode event if event.eventtype() == 'mode': if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+chan) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+chan, send_to_admins=True) bridge.irc_op = False return # Namreply event if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return # Unhandled events self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | 63ac797d46d708b05ad3e73b81c316969f231103 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/63ac797d46d708b05ad3e73b81c316969f231103/bot.py |
self.error(2, debug_str, debug=True) self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) | self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?'+event_str) | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey', 'topic', 'noorigin']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return source_nickname = None if event.source() and '!' in event.source(): source_nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str handled = False # Private message if event.eventtype() in ['privmsg', 'action']: if event.target() == self.nickname: # message is for the bot connection.privmsg(source_nickname, self.respond(event.arguments()[0])) return elif not irclib.is_channel(event.target()[0]): # search if the IRC user who sent the message is in one of the bridges for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) # he is, forward the message on XMPP if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp_to(connection.nickname, event.arguments()[0], action=action) return except Bridge.NoSuchParticipantException: continue # he isn't, send an error connection.privmsg(source_nickname, 'XIB error: you cannot send a private message to an XMPP user if you are not in one of the chans he is in') # Connection errors if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Server events if event.eventtype() in ['quit', 'nick']: for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: continue handled = True # Quit event if event.eventtype() == 'quit': if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left server.' bridge.remove_participant('irc', from_.nickname, leave_message) continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') continue if handled: return # Chan events if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'mode', 'join']: if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'join'] and not source_nickname: self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() == 'kick' and len(event.arguments()) == 0: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() == 'mode' and len(event.arguments()) < 2: self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event'+event_str) return chan = event.target().lower() bridge = self.get_bridge(irc_room=chan, irc_server=connection.server) try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: from_ = None # Join event if event.eventtype() == 'join': bridge.add_participant('irc', source_nickname) return # kick handling if event.eventtype() == 'kick': try: kicked = bridge.get_participant(event.arguments()[0]) except Bridge.NoSuchParticipantException: self.error(2, debug_str, debug=True) self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return leave_message = 'kicked by '+nickname if len(event.arguments()) > 1: leave_message += ' with reason: '+event.arguments()[1] else: leave_message += ' (no reason was given)' log_message = '"'+kicked.nickname+'" has been '+leave_message self.error(say_levels.warning, log_message) if isinstance(kicked.irc_connection, irclib.ServerConnection): # an IRC duplicate of an XMPP user has been kicked, auto-rejoin kicked.irc_connection.join(bridge.irc_room) elif isinstance(kicked.xmpp_c, xmpp.client.Client): # an IRC user has been kicked, make its duplicate leave kicked.leave(m) else: # an IRC user with no duplicate on XMPP has been kicked, say it on XMPP bridge.say(say_levels.warning, log_message, on_irc=False) return # Part event if event.eventtype() == 'part': if not from_: self.error(say_levels.debug, 'a participant that wasn\'t here left:'+event_str) return if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left channel.' bridge.remove_participant('irc', from_.nickname, leave_message) return # Chan message if event.eventtype() in ['pubmsg', 'action']: message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False if isinstance(from_, Participant): from_.say_on_xmpp(message, action=action) else: bridge.say_on_behalf(source_nickname, message, 'xmpp', action=action) return # Mode event if event.eventtype() == 'mode': if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+chan) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+chan, send_to_admins=True) bridge.irc_op = False return # Namreply event if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return # Unhandled events self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | 63ac797d46d708b05ad3e73b81c316969f231103 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/63ac797d46d708b05ad3e73b81c316969f231103/bot.py |
if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return if re.search('\+[^\-]*o', event.arguments()[0]): bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+chan) elif re.search('\-[^\+]*o', event.arguments()[0]): if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+chan, send_to_admins=True) bridge.irc_op = False | if len(event.arguments()) == 1: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for chan "'+event.target()+'"', debug=True) elif len(event.arguments()) == 2: if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'" in chan "'+event.target()+'"', debug=True) return if re.search('\+[^\-]*o', event.arguments()[0]): bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+chan) elif re.search('\-[^\+]*o', event.arguments()[0]): if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+chan, send_to_admins=True) bridge.irc_op = False else: self.error(say_levels.debug, 'unknown IRC "mode" event (has 3 arguments):'+event_str) | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey', 'topic', 'noorigin']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return source_nickname = None if event.source() and '!' in event.source(): source_nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str handled = False # Private message if event.eventtype() in ['privmsg', 'action']: if event.target() == self.nickname: # message is for the bot connection.privmsg(source_nickname, self.respond(event.arguments()[0])) return elif not irclib.is_channel(event.target()[0]): # search if the IRC user who sent the message is in one of the bridges for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) # he is, forward the message on XMPP if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp_to(connection.nickname, event.arguments()[0], action=action) return except Bridge.NoSuchParticipantException: continue # he isn't, send an error connection.privmsg(source_nickname, 'XIB error: you cannot send a private message to an XMPP user if you are not in one of the chans he is in') # Connection errors if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Server events if event.eventtype() in ['quit', 'nick']: for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: continue handled = True # Quit event if event.eventtype() == 'quit': if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left server.' bridge.remove_participant('irc', from_.nickname, leave_message) continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') continue if handled: return # Chan events if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'mode', 'join']: if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'join'] and not source_nickname: self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() == 'kick' and len(event.arguments()) == 0: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() == 'mode' and len(event.arguments()) < 2: self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event'+event_str) return chan = event.target().lower() bridge = self.get_bridge(irc_room=chan, irc_server=connection.server) try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: from_ = None # Join event if event.eventtype() == 'join': bridge.add_participant('irc', source_nickname) return # kick handling if event.eventtype() == 'kick': try: kicked = bridge.get_participant(event.arguments()[0]) except Bridge.NoSuchParticipantException: self.error(2, debug_str, debug=True) self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return leave_message = 'kicked by '+nickname if len(event.arguments()) > 1: leave_message += ' with reason: '+event.arguments()[1] else: leave_message += ' (no reason was given)' log_message = '"'+kicked.nickname+'" has been '+leave_message self.error(say_levels.warning, log_message) if isinstance(kicked.irc_connection, irclib.ServerConnection): # an IRC duplicate of an XMPP user has been kicked, auto-rejoin kicked.irc_connection.join(bridge.irc_room) elif isinstance(kicked.xmpp_c, xmpp.client.Client): # an IRC user has been kicked, make its duplicate leave kicked.leave(m) else: # an IRC user with no duplicate on XMPP has been kicked, say it on XMPP bridge.say(say_levels.warning, log_message, on_irc=False) return # Part event if event.eventtype() == 'part': if not from_: self.error(say_levels.debug, 'a participant that wasn\'t here left:'+event_str) return if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left channel.' bridge.remove_participant('irc', from_.nickname, leave_message) return # Chan message if event.eventtype() in ['pubmsg', 'action']: message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False if isinstance(from_, Participant): from_.say_on_xmpp(message, action=action) else: bridge.say_on_behalf(source_nickname, message, 'xmpp', action=action) return # Mode event if event.eventtype() == 'mode': if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+chan) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+chan, send_to_admins=True) bridge.irc_op = False return # Namreply event if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return # Unhandled events self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | 63ac797d46d708b05ad3e73b81c316969f231103 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/63ac797d46d708b05ad3e73b81c316969f231103/bot.py |
sockets = filter(lambda x: x != None, sockets) | sockets = filter(lambda x: x and not isinstance(x, basestring), sockets) | def process_once(self, timeout=0): """Process data from connections once. | 694949c3a9e94b59a3dfa01ca888716363ea23bc /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/694949c3a9e94b59a3dfa01ca888716363ea23bc/irclib.py |
if not self.socket or self.socket == 'closed': | if not self.socket or isinstance(self.socket, basestring): | def send_raw(self, string): """Send raw string to the server. | 694949c3a9e94b59a3dfa01ca888716363ea23bc /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/694949c3a9e94b59a3dfa01ca888716363ea23bc/irclib.py |
elif self.socket and self.socket != 'closed': | else: | def send_raw(self, string): """Send raw string to the server. | 694949c3a9e94b59a3dfa01ca888716363ea23bc /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/694949c3a9e94b59a3dfa01ca888716363ea23bc/irclib.py |
if event.eventtype() in ['pubmsg', 'action', 'part', 'kick'] and not source_nickname: | if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'join'] and not source_nickname: | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return source_nickname = None if event.source() and '!' in event.source(): source_nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str handled = False # Private message if event.eventtype() in ['privmsg', 'action']: if event.target() == self.nickname: # message is for the bot connection.privmsg(source_nickname, self.respond(event.arguments()[0])) return elif not irclib.is_channel(event.target()[0]): # search if the IRC user who sent the message is in one of the bridges for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) # he is, forward the message on XMPP if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp_to(connection.nickname, event.arguments()[0], action=action) return except Bridge.NoSuchParticipantException: continue # he isn't, send an error connection.privmsg(source_nickname, 'XIB error: you cannot send a private message to an XMPP user if you are not in one of the chans he is in') # Server events if event.eventtype() in ['quit', 'nick']: for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: continue handled = True # Quit event if event.eventtype() == 'quit': if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left server.' bridge.remove_participant('irc', from_.nickname, leave_message) continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') continue if handled: return # Connection errors if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Chan events if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'mode', 'join']: if event.eventtype() in ['pubmsg', 'action', 'part', 'kick'] and not source_nickname: self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() == 'kick' and len(event.arguments()) == 0: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: from_ = None # Join event if event.eventtype() == 'join': bridge.add_participant('irc', source_nickname) return # kick handling if event.eventtype() == 'kick': try: kicked = bridge.get_participant(event.arguments()[0]) except Bridge.NoSuchParticipantException: self.error(2, debug_str, debug=True) self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return leave_message = 'kicked by '+nickname if len(event.arguments()) > 1: leave_message += ' with reason: '+event.arguments()[1] else: leave_message += ' (no reason was given)' log_message = '"'+kicked.nickname+'" has been '+leave_message self.error(say_levels.warning, log_message) if isinstance(kicked.irc_connection, irclib.ServerConnection): # an IRC duplicate of an XMPP user has been kicked, auto-rejoin kicked.irc_connection.join(bridge.irc_room) elif isinstance(kicked.xmpp_c, xmpp.client.Client): # an IRC user has been kicked, make its duplicate leave kicked.leave(m) else: # an IRC user with no duplicate on XMPP has been kicked, say it on XMPP bridge.say(say_levels.warning, log_message, on_irc=False) return # Part event if event.eventtype() == 'part': if not from_: self.error(say_levels.debug, 'a participant that wasn\'t here left:\n'+event_str) return if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left channel.' bridge.remove_participant('irc', from_.nickname, leave_message) return # Chan message if event.eventtype() in ['pubmsg', 'action']: message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False if isinstance(from_, Participant): from_.say_on_xmpp(message, action=action) else: bridge.say_on_behalf(source_nickname, message, 'xmpp', action=action) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event\n'+event_str) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return bridge = self.get_bridge(irc_room=event.target(), irc_server=connection.server) if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False return # Namreply event if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return # Unhandled events self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | f0063ab3776d327f4aa7ceb4013e4a2618f25b63 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/f0063ab3776d327f4aa7ceb4013e4a2618f25b63/bot.py |
bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) | if event.eventtype() == 'mode' and len(event.arguments()) < 2: self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event'+event_str) return chan = event.target().lower() bridge = self.get_bridge(irc_room=chan, irc_server=connection.server) | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return source_nickname = None if event.source() and '!' in event.source(): source_nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str handled = False # Private message if event.eventtype() in ['privmsg', 'action']: if event.target() == self.nickname: # message is for the bot connection.privmsg(source_nickname, self.respond(event.arguments()[0])) return elif not irclib.is_channel(event.target()[0]): # search if the IRC user who sent the message is in one of the bridges for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) # he is, forward the message on XMPP if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp_to(connection.nickname, event.arguments()[0], action=action) return except Bridge.NoSuchParticipantException: continue # he isn't, send an error connection.privmsg(source_nickname, 'XIB error: you cannot send a private message to an XMPP user if you are not in one of the chans he is in') # Server events if event.eventtype() in ['quit', 'nick']: for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: continue handled = True # Quit event if event.eventtype() == 'quit': if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left server.' bridge.remove_participant('irc', from_.nickname, leave_message) continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') continue if handled: return # Connection errors if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Chan events if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'mode', 'join']: if event.eventtype() in ['pubmsg', 'action', 'part', 'kick'] and not source_nickname: self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() == 'kick' and len(event.arguments()) == 0: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: from_ = None # Join event if event.eventtype() == 'join': bridge.add_participant('irc', source_nickname) return # kick handling if event.eventtype() == 'kick': try: kicked = bridge.get_participant(event.arguments()[0]) except Bridge.NoSuchParticipantException: self.error(2, debug_str, debug=True) self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return leave_message = 'kicked by '+nickname if len(event.arguments()) > 1: leave_message += ' with reason: '+event.arguments()[1] else: leave_message += ' (no reason was given)' log_message = '"'+kicked.nickname+'" has been '+leave_message self.error(say_levels.warning, log_message) if isinstance(kicked.irc_connection, irclib.ServerConnection): # an IRC duplicate of an XMPP user has been kicked, auto-rejoin kicked.irc_connection.join(bridge.irc_room) elif isinstance(kicked.xmpp_c, xmpp.client.Client): # an IRC user has been kicked, make its duplicate leave kicked.leave(m) else: # an IRC user with no duplicate on XMPP has been kicked, say it on XMPP bridge.say(say_levels.warning, log_message, on_irc=False) return # Part event if event.eventtype() == 'part': if not from_: self.error(say_levels.debug, 'a participant that wasn\'t here left:\n'+event_str) return if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left channel.' bridge.remove_participant('irc', from_.nickname, leave_message) return # Chan message if event.eventtype() in ['pubmsg', 'action']: message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False if isinstance(from_, Participant): from_.say_on_xmpp(message, action=action) else: bridge.say_on_behalf(source_nickname, message, 'xmpp', action=action) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event\n'+event_str) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return bridge = self.get_bridge(irc_room=event.target(), irc_server=connection.server) if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False return # Namreply event if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return # Unhandled events self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | f0063ab3776d327f4aa7ceb4013e4a2618f25b63 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/f0063ab3776d327f4aa7ceb4013e4a2618f25b63/bot.py |
self.error(say_levels.debug, 'a participant that wasn\'t here left:\n'+event_str) | self.error(say_levels.debug, 'a participant that wasn\'t here left:'+event_str) | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return source_nickname = None if event.source() and '!' in event.source(): source_nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str handled = False # Private message if event.eventtype() in ['privmsg', 'action']: if event.target() == self.nickname: # message is for the bot connection.privmsg(source_nickname, self.respond(event.arguments()[0])) return elif not irclib.is_channel(event.target()[0]): # search if the IRC user who sent the message is in one of the bridges for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) # he is, forward the message on XMPP if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp_to(connection.nickname, event.arguments()[0], action=action) return except Bridge.NoSuchParticipantException: continue # he isn't, send an error connection.privmsg(source_nickname, 'XIB error: you cannot send a private message to an XMPP user if you are not in one of the chans he is in') # Server events if event.eventtype() in ['quit', 'nick']: for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: continue handled = True # Quit event if event.eventtype() == 'quit': if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left server.' bridge.remove_participant('irc', from_.nickname, leave_message) continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') continue if handled: return # Connection errors if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Chan events if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'mode', 'join']: if event.eventtype() in ['pubmsg', 'action', 'part', 'kick'] and not source_nickname: self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() == 'kick' and len(event.arguments()) == 0: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: from_ = None # Join event if event.eventtype() == 'join': bridge.add_participant('irc', source_nickname) return # kick handling if event.eventtype() == 'kick': try: kicked = bridge.get_participant(event.arguments()[0]) except Bridge.NoSuchParticipantException: self.error(2, debug_str, debug=True) self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return leave_message = 'kicked by '+nickname if len(event.arguments()) > 1: leave_message += ' with reason: '+event.arguments()[1] else: leave_message += ' (no reason was given)' log_message = '"'+kicked.nickname+'" has been '+leave_message self.error(say_levels.warning, log_message) if isinstance(kicked.irc_connection, irclib.ServerConnection): # an IRC duplicate of an XMPP user has been kicked, auto-rejoin kicked.irc_connection.join(bridge.irc_room) elif isinstance(kicked.xmpp_c, xmpp.client.Client): # an IRC user has been kicked, make its duplicate leave kicked.leave(m) else: # an IRC user with no duplicate on XMPP has been kicked, say it on XMPP bridge.say(say_levels.warning, log_message, on_irc=False) return # Part event if event.eventtype() == 'part': if not from_: self.error(say_levels.debug, 'a participant that wasn\'t here left:\n'+event_str) return if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left channel.' bridge.remove_participant('irc', from_.nickname, leave_message) return # Chan message if event.eventtype() in ['pubmsg', 'action']: message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False if isinstance(from_, Participant): from_.say_on_xmpp(message, action=action) else: bridge.say_on_behalf(source_nickname, message, 'xmpp', action=action) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event\n'+event_str) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return bridge = self.get_bridge(irc_room=event.target(), irc_server=connection.server) if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False return # Namreply event if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return # Unhandled events self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | f0063ab3776d327f4aa7ceb4013e4a2618f25b63 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/f0063ab3776d327f4aa7ceb4013e4a2618f25b63/bot.py |
if len(event.arguments()) < 2: self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event\n'+event_str) return | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return source_nickname = None if event.source() and '!' in event.source(): source_nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str handled = False # Private message if event.eventtype() in ['privmsg', 'action']: if event.target() == self.nickname: # message is for the bot connection.privmsg(source_nickname, self.respond(event.arguments()[0])) return elif not irclib.is_channel(event.target()[0]): # search if the IRC user who sent the message is in one of the bridges for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) # he is, forward the message on XMPP if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp_to(connection.nickname, event.arguments()[0], action=action) return except Bridge.NoSuchParticipantException: continue # he isn't, send an error connection.privmsg(source_nickname, 'XIB error: you cannot send a private message to an XMPP user if you are not in one of the chans he is in') # Server events if event.eventtype() in ['quit', 'nick']: for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: continue handled = True # Quit event if event.eventtype() == 'quit': if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left server.' bridge.remove_participant('irc', from_.nickname, leave_message) continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') continue if handled: return # Connection errors if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Chan events if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'mode', 'join']: if event.eventtype() in ['pubmsg', 'action', 'part', 'kick'] and not source_nickname: self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() == 'kick' and len(event.arguments()) == 0: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: from_ = None # Join event if event.eventtype() == 'join': bridge.add_participant('irc', source_nickname) return # kick handling if event.eventtype() == 'kick': try: kicked = bridge.get_participant(event.arguments()[0]) except Bridge.NoSuchParticipantException: self.error(2, debug_str, debug=True) self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return leave_message = 'kicked by '+nickname if len(event.arguments()) > 1: leave_message += ' with reason: '+event.arguments()[1] else: leave_message += ' (no reason was given)' log_message = '"'+kicked.nickname+'" has been '+leave_message self.error(say_levels.warning, log_message) if isinstance(kicked.irc_connection, irclib.ServerConnection): # an IRC duplicate of an XMPP user has been kicked, auto-rejoin kicked.irc_connection.join(bridge.irc_room) elif isinstance(kicked.xmpp_c, xmpp.client.Client): # an IRC user has been kicked, make its duplicate leave kicked.leave(m) else: # an IRC user with no duplicate on XMPP has been kicked, say it on XMPP bridge.say(say_levels.warning, log_message, on_irc=False) return # Part event if event.eventtype() == 'part': if not from_: self.error(say_levels.debug, 'a participant that wasn\'t here left:\n'+event_str) return if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left channel.' bridge.remove_participant('irc', from_.nickname, leave_message) return # Chan message if event.eventtype() in ['pubmsg', 'action']: message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False if isinstance(from_, Participant): from_.say_on_xmpp(message, action=action) else: bridge.say_on_behalf(source_nickname, message, 'xmpp', action=action) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event\n'+event_str) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return bridge = self.get_bridge(irc_room=event.target(), irc_server=connection.server) if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False return # Namreply event if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return # Unhandled events self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | f0063ab3776d327f4aa7ceb4013e4a2618f25b63 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/f0063ab3776d327f4aa7ceb4013e4a2618f25b63/bot.py |
|
bridge = self.get_bridge(irc_room=event.target(), irc_server=connection.server) | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return source_nickname = None if event.source() and '!' in event.source(): source_nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str handled = False # Private message if event.eventtype() in ['privmsg', 'action']: if event.target() == self.nickname: # message is for the bot connection.privmsg(source_nickname, self.respond(event.arguments()[0])) return elif not irclib.is_channel(event.target()[0]): # search if the IRC user who sent the message is in one of the bridges for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) # he is, forward the message on XMPP if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp_to(connection.nickname, event.arguments()[0], action=action) return except Bridge.NoSuchParticipantException: continue # he isn't, send an error connection.privmsg(source_nickname, 'XIB error: you cannot send a private message to an XMPP user if you are not in one of the chans he is in') # Server events if event.eventtype() in ['quit', 'nick']: for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: continue handled = True # Quit event if event.eventtype() == 'quit': if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left server.' bridge.remove_participant('irc', from_.nickname, leave_message) continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') continue if handled: return # Connection errors if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Chan events if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'mode', 'join']: if event.eventtype() in ['pubmsg', 'action', 'part', 'kick'] and not source_nickname: self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() == 'kick' and len(event.arguments()) == 0: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: from_ = None # Join event if event.eventtype() == 'join': bridge.add_participant('irc', source_nickname) return # kick handling if event.eventtype() == 'kick': try: kicked = bridge.get_participant(event.arguments()[0]) except Bridge.NoSuchParticipantException: self.error(2, debug_str, debug=True) self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return leave_message = 'kicked by '+nickname if len(event.arguments()) > 1: leave_message += ' with reason: '+event.arguments()[1] else: leave_message += ' (no reason was given)' log_message = '"'+kicked.nickname+'" has been '+leave_message self.error(say_levels.warning, log_message) if isinstance(kicked.irc_connection, irclib.ServerConnection): # an IRC duplicate of an XMPP user has been kicked, auto-rejoin kicked.irc_connection.join(bridge.irc_room) elif isinstance(kicked.xmpp_c, xmpp.client.Client): # an IRC user has been kicked, make its duplicate leave kicked.leave(m) else: # an IRC user with no duplicate on XMPP has been kicked, say it on XMPP bridge.say(say_levels.warning, log_message, on_irc=False) return # Part event if event.eventtype() == 'part': if not from_: self.error(say_levels.debug, 'a participant that wasn\'t here left:\n'+event_str) return if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left channel.' bridge.remove_participant('irc', from_.nickname, leave_message) return # Chan message if event.eventtype() in ['pubmsg', 'action']: message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False if isinstance(from_, Participant): from_.say_on_xmpp(message, action=action) else: bridge.say_on_behalf(source_nickname, message, 'xmpp', action=action) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event\n'+event_str) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return bridge = self.get_bridge(irc_room=event.target(), irc_server=connection.server) if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False return # Namreply event if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return # Unhandled events self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | f0063ab3776d327f4aa7ceb4013e4a2618f25b63 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/f0063ab3776d327f4aa7ceb4013e4a2618f25b63/bot.py |
|
self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) | self.error(say_levels.notice, 'bot has IRC operator privileges in '+chan) | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return source_nickname = None if event.source() and '!' in event.source(): source_nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str handled = False # Private message if event.eventtype() in ['privmsg', 'action']: if event.target() == self.nickname: # message is for the bot connection.privmsg(source_nickname, self.respond(event.arguments()[0])) return elif not irclib.is_channel(event.target()[0]): # search if the IRC user who sent the message is in one of the bridges for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) # he is, forward the message on XMPP if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp_to(connection.nickname, event.arguments()[0], action=action) return except Bridge.NoSuchParticipantException: continue # he isn't, send an error connection.privmsg(source_nickname, 'XIB error: you cannot send a private message to an XMPP user if you are not in one of the chans he is in') # Server events if event.eventtype() in ['quit', 'nick']: for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: continue handled = True # Quit event if event.eventtype() == 'quit': if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left server.' bridge.remove_participant('irc', from_.nickname, leave_message) continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') continue if handled: return # Connection errors if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Chan events if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'mode', 'join']: if event.eventtype() in ['pubmsg', 'action', 'part', 'kick'] and not source_nickname: self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() == 'kick' and len(event.arguments()) == 0: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: from_ = None # Join event if event.eventtype() == 'join': bridge.add_participant('irc', source_nickname) return # kick handling if event.eventtype() == 'kick': try: kicked = bridge.get_participant(event.arguments()[0]) except Bridge.NoSuchParticipantException: self.error(2, debug_str, debug=True) self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return leave_message = 'kicked by '+nickname if len(event.arguments()) > 1: leave_message += ' with reason: '+event.arguments()[1] else: leave_message += ' (no reason was given)' log_message = '"'+kicked.nickname+'" has been '+leave_message self.error(say_levels.warning, log_message) if isinstance(kicked.irc_connection, irclib.ServerConnection): # an IRC duplicate of an XMPP user has been kicked, auto-rejoin kicked.irc_connection.join(bridge.irc_room) elif isinstance(kicked.xmpp_c, xmpp.client.Client): # an IRC user has been kicked, make its duplicate leave kicked.leave(m) else: # an IRC user with no duplicate on XMPP has been kicked, say it on XMPP bridge.say(say_levels.warning, log_message, on_irc=False) return # Part event if event.eventtype() == 'part': if not from_: self.error(say_levels.debug, 'a participant that wasn\'t here left:\n'+event_str) return if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left channel.' bridge.remove_participant('irc', from_.nickname, leave_message) return # Chan message if event.eventtype() in ['pubmsg', 'action']: message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False if isinstance(from_, Participant): from_.say_on_xmpp(message, action=action) else: bridge.say_on_behalf(source_nickname, message, 'xmpp', action=action) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event\n'+event_str) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return bridge = self.get_bridge(irc_room=event.target(), irc_server=connection.server) if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False return # Namreply event if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return # Unhandled events self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | f0063ab3776d327f4aa7ceb4013e4a2618f25b63 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/f0063ab3776d327f4aa7ceb4013e4a2618f25b63/bot.py |
self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) | self.error(say_levels.notice, 'bot lost IRC operator privileges in '+chan, send_to_admins=True) | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return source_nickname = None if event.source() and '!' in event.source(): source_nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str handled = False # Private message if event.eventtype() in ['privmsg', 'action']: if event.target() == self.nickname: # message is for the bot connection.privmsg(source_nickname, self.respond(event.arguments()[0])) return elif not irclib.is_channel(event.target()[0]): # search if the IRC user who sent the message is in one of the bridges for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) # he is, forward the message on XMPP if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp_to(connection.nickname, event.arguments()[0], action=action) return except Bridge.NoSuchParticipantException: continue # he isn't, send an error connection.privmsg(source_nickname, 'XIB error: you cannot send a private message to an XMPP user if you are not in one of the chans he is in') # Server events if event.eventtype() in ['quit', 'nick']: for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: continue handled = True # Quit event if event.eventtype() == 'quit': if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left server.' bridge.remove_participant('irc', from_.nickname, leave_message) continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') continue if handled: return # Connection errors if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Chan events if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'mode', 'join']: if event.eventtype() in ['pubmsg', 'action', 'part', 'kick'] and not source_nickname: self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() == 'kick' and len(event.arguments()) == 0: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: from_ = None # Join event if event.eventtype() == 'join': bridge.add_participant('irc', source_nickname) return # kick handling if event.eventtype() == 'kick': try: kicked = bridge.get_participant(event.arguments()[0]) except Bridge.NoSuchParticipantException: self.error(2, debug_str, debug=True) self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return leave_message = 'kicked by '+nickname if len(event.arguments()) > 1: leave_message += ' with reason: '+event.arguments()[1] else: leave_message += ' (no reason was given)' log_message = '"'+kicked.nickname+'" has been '+leave_message self.error(say_levels.warning, log_message) if isinstance(kicked.irc_connection, irclib.ServerConnection): # an IRC duplicate of an XMPP user has been kicked, auto-rejoin kicked.irc_connection.join(bridge.irc_room) elif isinstance(kicked.xmpp_c, xmpp.client.Client): # an IRC user has been kicked, make its duplicate leave kicked.leave(m) else: # an IRC user with no duplicate on XMPP has been kicked, say it on XMPP bridge.say(say_levels.warning, log_message, on_irc=False) return # Part event if event.eventtype() == 'part': if not from_: self.error(say_levels.debug, 'a participant that wasn\'t here left:\n'+event_str) return if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left channel.' bridge.remove_participant('irc', from_.nickname, leave_message) return # Chan message if event.eventtype() in ['pubmsg', 'action']: message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False if isinstance(from_, Participant): from_.say_on_xmpp(message, action=action) else: bridge.say_on_behalf(source_nickname, message, 'xmpp', action=action) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event\n'+event_str) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return bridge = self.get_bridge(irc_room=event.target(), irc_server=connection.server) if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False return # Namreply event if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return # Unhandled events self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | f0063ab3776d327f4aa7ceb4013e4a2618f25b63 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/f0063ab3776d327f4aa7ceb4013e4a2618f25b63/bot.py |
self.lock.acquire() | def addParticipant(self, from_protocol, nickname, real_jid=None, irc_id=None): """Add a participant to the bridge.""" if (from_protocol == 'irc' and nickname == self.bot.nickname) or (from_protocol == 'xmpp' and nickname == self.bot.nickname): self.bot.error(3, 'not adding self ('+self.bot.nickname+') to bridge "'+str(self)+'"', debug=True) return try: p = self.getParticipant(nickname) if p.protocol != from_protocol: if from_protocol == 'irc' and isinstance(p.irc_connection, ServerConnection) and p.irc_connection.really_connected == True and p.irc_connection.real_nickname == nickname or from_protocol == 'xmpp' and isinstance(p.xmpp_c, xmpp.client.Client) and isinstance(p.muc, xmpp.muc) and p.xmpp_c.nickname == nickname: if irc_id: p.irc_connection.irc_id = irc_id return p p.set_both_sides() return p except self.NoSuchParticipantException: pass if nickname == 'ChanServ' and from_protocol == 'irc': return self.lock.acquire() self.bot.error(3, 'adding participant "'+nickname+'" from "'+from_protocol+'" to bridge "'+str(self)+'"', debug=True) try: p = Participant(self, from_protocol, nickname, real_jid=real_jid) except IOError: self.bot.error(3, 'IOError while adding participant "'+nickname+'" from "'+from_protocol+'" to bridge "'+str(self)+'", reconnectiong ...', debug=True) p.xmpp_c.reconnectAndReauth() except: self.bot.error(3, 'unknown error while adding participant "'+nickname+'" from "'+from_protocol+'" to bridge "'+str(self)+'"', debug=True) traceback.print_exc() return self.participants.append(p) self.lock.release() if self.mode not in ['normal', 'bypass']: if from_protocol == 'xmpp': self.show_participants_list_on(protocols=['irc']) elif self.mode == 'minimal' and from_protocol == 'irc': self.show_participants_list_on(protocols=['xmpp']) return p | 89bce1c8246e864b1a5a5de9c0335cb6e347e81d /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/89bce1c8246e864b1a5a5de9c0335cb6e347e81d/bridge.py |
|
except IOError: self.bot.error(3, 'IOError while adding participant "'+nickname+'" from "'+from_protocol+'" to bridge "'+str(self)+'", reconnectiong ...', debug=True) p.xmpp_c.reconnectAndReauth() | def addParticipant(self, from_protocol, nickname, real_jid=None, irc_id=None): """Add a participant to the bridge.""" if (from_protocol == 'irc' and nickname == self.bot.nickname) or (from_protocol == 'xmpp' and nickname == self.bot.nickname): self.bot.error(3, 'not adding self ('+self.bot.nickname+') to bridge "'+str(self)+'"', debug=True) return try: p = self.getParticipant(nickname) if p.protocol != from_protocol: if from_protocol == 'irc' and isinstance(p.irc_connection, ServerConnection) and p.irc_connection.really_connected == True and p.irc_connection.real_nickname == nickname or from_protocol == 'xmpp' and isinstance(p.xmpp_c, xmpp.client.Client) and isinstance(p.muc, xmpp.muc) and p.xmpp_c.nickname == nickname: if irc_id: p.irc_connection.irc_id = irc_id return p p.set_both_sides() return p except self.NoSuchParticipantException: pass if nickname == 'ChanServ' and from_protocol == 'irc': return self.lock.acquire() self.bot.error(3, 'adding participant "'+nickname+'" from "'+from_protocol+'" to bridge "'+str(self)+'"', debug=True) try: p = Participant(self, from_protocol, nickname, real_jid=real_jid) except IOError: self.bot.error(3, 'IOError while adding participant "'+nickname+'" from "'+from_protocol+'" to bridge "'+str(self)+'", reconnectiong ...', debug=True) p.xmpp_c.reconnectAndReauth() except: self.bot.error(3, 'unknown error while adding participant "'+nickname+'" from "'+from_protocol+'" to bridge "'+str(self)+'"', debug=True) traceback.print_exc() return self.participants.append(p) self.lock.release() if self.mode not in ['normal', 'bypass']: if from_protocol == 'xmpp': self.show_participants_list_on(protocols=['irc']) elif self.mode == 'minimal' and from_protocol == 'irc': self.show_participants_list_on(protocols=['xmpp']) return p | 89bce1c8246e864b1a5a5de9c0335cb6e347e81d /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/89bce1c8246e864b1a5a5de9c0335cb6e347e81d/bridge.py |
|
if hasattr(self, 'reconnecting'): del self.reconnecting | self.reconnecting = False | def _xmpp_join_callback(self, errors): """Called by muc._xmpp_presence_handler""" if len(errors) == 0: if hasattr(self, 'reconnecting'): del self.reconnecting if self.mode == None: return self.bot.error(3, 'succesfully connected on XMPP side of bridge "'+str(self)+'"', debug=True) self.say(say_levels.notice, 'bridge "'+str(self)+'" is running in '+self.mode+' mode', on_irc=False) else: self.mode = None self.say(say_levels.error, 'failed to connect to the XMPP room, leaving ...', on_xmpp=False) for error in errors: try: raise error except xmpp.muc.RemoteServerNotFound: self._RemoteServerNotFound_handler() except: trace = traceback.format_exc() self.bot.error(say_levels.error, 'failed to connect to the XMPP room of bridge "'+str(self)+'", stopping bridge\n'+trace, send_to_admins=True) self.stop(message='Failed to connect to the XMPP room, stopping bridge') | 2b146a80a7fc30f39c66b987530d6d9f418ec31f /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/2b146a80a7fc30f39c66b987530d6d9f418ec31f/bridge.py |
if (from_protocol == 'irc' and nickname == self.irc_connection.get_nickname()) or (from_protocol == 'xmpp' and nickname == self.xmpp_room.nickname): | if (from_protocol == 'irc' and nickname == self.bot.nickname) or (from_protocol == 'xmpp' and nickname == self.bot.nickname): | def addParticipant(self, from_protocol, nickname, real_jid=None, irc_id=None): """Add a participant to the bridge.""" if (from_protocol == 'irc' and nickname == self.irc_connection.get_nickname()) or (from_protocol == 'xmpp' and nickname == self.xmpp_room.nickname): self.bot.error('===> Debug: not adding self ('+self.bot.nickname+') to bridge "'+str(self)+'"', debug=True) return try: p = self.getParticipant(nickname) if p.protocol != from_protocol: if from_protocol == 'irc' and isinstance(p.irc_connection, ServerConnection) and p.irc_connection.really_connected == True and p.irc_connection.real_nickname == nickname or from_protocol == 'xmpp' and isinstance(p.xmpp_c, xmpp.client.Client) and isinstance(p.muc, xmpp.muc) and p.xmpp_c.nickname == nickname: if irc_id: p.irc_connection.irc_id = irc_id return p p.set_both_sides() return p except self.NoSuchParticipantException: pass if nickname == 'ChanServ' and from_protocol == 'irc': return self.lock.acquire() self.bot.error('===> Debug: adding participant "'+nickname+'" from "'+from_protocol+'" to bridge "'+str(self)+'"', debug=True) try: p = Participant(self, from_protocol, nickname, real_jid=real_jid) except IOError: self.bot.error('===> Debug: IOError while adding participant "'+nickname+'" from "'+from_protocol+'" to bridge "'+str(self)+'", reconnectiong ...', debug=True) p.xmpp_c.reconnectAndReauth() except: self.bot.error('===> Debug: unknown error while adding participant "'+nickname+'" from "'+from_protocol+'" to bridge "'+str(self)+'"', debug=True) traceback.print_exc() return self.participants.append(p) self.lock.release() if self.mode not in ['normal', 'bypass']: if from_protocol == 'xmpp': self.show_participants_list_on(protocols=['irc']) elif self.mode == 'minimal' and from_protocol == 'irc': self.show_participants_list_on(protocols=['xmpp']) return p | 1640f287d8442c92907cfdb505ab3bfeae99b8c1 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/1640f287d8442c92907cfdb505ab3bfeae99b8c1/bridge.py |
def restart(self, log=True): | def restart(self, message='Restarting bridge', log=True): | def restart(self, log=True): """Restart the bridge""" # Stop the bridge self.stop(message='Restarting bridge', log=log) # Recreate the bridge self.init2() | bee65239670c15723df88d30d2482975d45821af /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/bee65239670c15723df88d30d2482975d45821af/bridge.py |
self.stop(message='Restarting bridge', log=log) | self.stop(message=message, log=log) | def restart(self, log=True): """Restart the bridge""" # Stop the bridge self.stop(message='Restarting bridge', log=log) # Recreate the bridge self.init2() | bee65239670c15723df88d30d2482975d45821af /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/bee65239670c15723df88d30d2482975d45821af/bridge.py |
try: bot_say = False if message[:4] == '/me ': action = True message = message[4:] else: action = False if isinstance(self.irc_connection, ServerConnection): try: if action: self.irc_connection.action(self.bridge.irc_room, message) else: self.irc_connection.privmsg(self.bridge.irc_room, message) except ServerNotConnectedError: self.irc_connection.connect() bot_say = True elif not isinstance(self.xmpp_c, xmpp.client.Client): | bot_say = False if message[:4] == '/me ': action = True message = message[4:] else: action = False if isinstance(self.irc_connection, ServerConnection): try: if action: self.irc_connection.action(self.bridge.irc_room, message) else: self.irc_connection.privmsg(self.bridge.irc_room, message) except ServerNotConnectedError: self.irc_connection.connect() | def sayOnIRC(self, message): try: bot_say = False if message[:4] == '/me ': action = True message = message[4:] else: action = False if isinstance(self.irc_connection, ServerConnection): try: if action: self.irc_connection.action(self.bridge.irc_room, message) else: self.irc_connection.privmsg(self.bridge.irc_room, message) except ServerNotConnectedError: self.irc_connection.connect() bot_say = True elif not isinstance(self.xmpp_c, xmpp.client.Client): bot_say = True if bot_say: if action: self.bridge.irc_connection.privmsg(self.bridge.irc_room, '* '+self.nickname+' '+message) else: self.bridge.irc_connection.privmsg(self.bridge.irc_room, '<'+self.nickname+'> '+message) except EncodingException: self.bridge.say(say_levels.warning, '"'+self.nickname+'" is sending messages using an unknown encoding', log=True) | f927b30ff1c23546422090e563886a9083bb5bd3 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/f927b30ff1c23546422090e563886a9083bb5bd3/participant.py |
if bot_say: if action: self.bridge.irc_connection.privmsg(self.bridge.irc_room, '* '+self.nickname+' '+message) else: self.bridge.irc_connection.privmsg(self.bridge.irc_room, '<'+self.nickname+'> '+message) except EncodingException: self.bridge.say(say_levels.warning, '"'+self.nickname+'" is sending messages using an unknown encoding', log=True) | elif not isinstance(self.xmpp_c, xmpp.client.Client): bot_say = True if bot_say: if action: self.bridge.irc_connection.privmsg(self.bridge.irc_room, '* '+self.nickname+' '+message) else: self.bridge.irc_connection.privmsg(self.bridge.irc_room, '<'+self.nickname+'> '+message) | def sayOnIRC(self, message): try: bot_say = False if message[:4] == '/me ': action = True message = message[4:] else: action = False if isinstance(self.irc_connection, ServerConnection): try: if action: self.irc_connection.action(self.bridge.irc_room, message) else: self.irc_connection.privmsg(self.bridge.irc_room, message) except ServerNotConnectedError: self.irc_connection.connect() bot_say = True elif not isinstance(self.xmpp_c, xmpp.client.Client): bot_say = True if bot_say: if action: self.bridge.irc_connection.privmsg(self.bridge.irc_room, '* '+self.nickname+' '+message) else: self.bridge.irc_connection.privmsg(self.bridge.irc_room, '<'+self.nickname+'> '+message) except EncodingException: self.bridge.say(say_levels.warning, '"'+self.nickname+'" is sending messages using an unknown encoding', log=True) | f927b30ff1c23546422090e563886a9083bb5bd3 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/f927b30ff1c23546422090e563886a9083bb5bd3/participant.py |
try: self.irc_connection.privmsg(to, message) except EncodingException: self.bridge.say(say_levels.warning, '"'+self.nickname+'" is sending messages using an unknown encoding', log=True) | self.irc_connection.privmsg(to, message) | def sayOnIRCTo(self, to, message): if isinstance(self.irc_connection, ServerConnection): try: self.irc_connection.privmsg(to, message) except EncodingException: self.bridge.say(say_levels.warning, '"'+self.nickname+'" is sending messages using an unknown encoding', log=True) elif not isinstance(self.xmpp_c, xmpp.client.Client): if self.bridge.mode != 'normal': self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.') else: self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but you cannot send cross-protocol private messages because I don\'t have an IRC duplicate with your nickname.') | f927b30ff1c23546422090e563886a9083bb5bd3 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/f927b30ff1c23546422090e563886a9083bb5bd3/participant.py |
try: if isinstance(self.xmpp_c, xmpp.client.Client): self.muc.say(message) elif not isinstance(self.irc_connection, ServerConnection): if message[:4] == '/me ': self.bridge.xmpp_room.say('* '+self.nickname+' '+message[4:]) else: self.bridge.xmpp_room.say('<'+self.nickname+'> '+message) except EncodingException: self.bridge.say(say_levels.warning, '"'+self.nickname+'" is sending messages using an unknown encoding', log=True) | if isinstance(self.xmpp_c, xmpp.client.Client): self.muc.say(message) elif not isinstance(self.irc_connection, ServerConnection): if message[:4] == '/me ': self.bridge.xmpp_room.say('* '+self.nickname+' '+message[4:]) else: self.bridge.xmpp_room.say('<'+self.nickname+'> '+message) | def sayOnXMPP(self, message): try: if isinstance(self.xmpp_c, xmpp.client.Client): self.muc.say(message) elif not isinstance(self.irc_connection, ServerConnection): if message[:4] == '/me ': self.bridge.xmpp_room.say('* '+self.nickname+' '+message[4:]) else: self.bridge.xmpp_room.say('<'+self.nickname+'> '+message) except EncodingException: self.bridge.say(say_levels.warning, '"'+self.nickname+'" is sending messages using an unknown encoding', log=True) | f927b30ff1c23546422090e563886a9083bb5bd3 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/f927b30ff1c23546422090e563886a9083bb5bd3/participant.py |
try: if isinstance(self.xmpp_c, xmpp.client.Client): self.muc.sayTo(to, message) elif not isinstance(self.irc_connection, ServerConnection): if self.bridge.mode != 'normal': self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.') else: self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but you cannot send cross-protocol private messages because I don\'t have an XMPP duplicate with your nickname.') except EncodingException: self.bridge.say(say_levels.warning, '"'+self.nickname+'" is sending messages using an unknown encoding', log=True) | if isinstance(self.xmpp_c, xmpp.client.Client): self.muc.sayTo(to, message) elif not isinstance(self.irc_connection, ServerConnection): if self.bridge.mode != 'normal': self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.') else: self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but you cannot send cross-protocol private messages because I don\'t have an XMPP duplicate with your nickname.') | def sayOnXMPPTo(self, to, message): try: if isinstance(self.xmpp_c, xmpp.client.Client): self.muc.sayTo(to, message) elif not isinstance(self.irc_connection, ServerConnection): if self.bridge.mode != 'normal': self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.') else: self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but you cannot send cross-protocol private messages because I don\'t have an XMPP duplicate with your nickname.') except EncodingException: self.bridge.say(say_levels.warning, '"'+self.nickname+'" is sending messages using an unknown encoding', log=True) | f927b30ff1c23546422090e563886a9083bb5bd3 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/f927b30ff1c23546422090e563886a9083bb5bd3/participant.py |
if not self.connected: return | def disconnect(self, message="", volontary=False): """Hang up the connection. | 8445c04d75ea5033ea75d46637922a54ab654cec /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/8445c04d75ea5033ea75d46637922a54ab654cec/irclib.py |
|
self.connected = False self.quit(message) try: self.socket.close() except socket.error, x: pass self.socket = 'closed' | if self.connected: self.connected = False if self.socket and self.socket != 'closed': self.quit(message) try: self.socket.close() except socket.error, x: pass self.socket = 'closed' | def disconnect(self, message="", volontary=False): """Hang up the connection. | 8445c04d75ea5033ea75d46637922a54ab654cec /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/8445c04d75ea5033ea75d46637922a54ab654cec/irclib.py |
try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: from_ = None | from_ = None if source_nickname: try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: pass | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey', 'topic', 'noorigin']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return source_nickname = None if event.source() and '!' in event.source(): source_nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str handled = False # Private message if event.eventtype() in ['privmsg', 'action']: if event.target() == self.nickname: # message is for the bot connection.privmsg(source_nickname, self.respond(event.arguments()[0])) return elif not irclib.is_channel(event.target()[0]): # search if the IRC user who sent the message is in one of the bridges for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) # he is, forward the message on XMPP if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp_to(connection.nickname, event.arguments()[0], action=action) return except Bridge.NoSuchParticipantException: continue # he isn't, send an error connection.privmsg(source_nickname, 'XIB error: you cannot send a private message to an XMPP user if you are not in one of the chans he is in') # Connection errors if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Server events if event.eventtype() in ['quit', 'nick']: for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: continue handled = True # Quit event if event.eventtype() == 'quit': if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left server.' bridge.remove_participant('irc', from_.nickname, leave_message) continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') continue if handled: return # Chan events if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'mode', 'join']: if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'join'] and not source_nickname: self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event'+event_str) return if event.eventtype() in ['kick', 'mode'] and len(event.arguments()) == 0: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event'+event_str) return chan = event.target().lower() bridge = self.get_bridge(irc_room=chan, irc_server=connection.server) try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: from_ = None # Join event if event.eventtype() == 'join': bridge.add_participant('irc', source_nickname) return # kick handling if event.eventtype() == 'kick': try: kicked = bridge.get_participant(event.arguments()[0]) except Bridge.NoSuchParticipantException: self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?'+event_str) return leave_message = 'kicked by '+nickname if len(event.arguments()) > 1: leave_message += ' with reason: '+event.arguments()[1] else: leave_message += ' (no reason was given)' log_message = '"'+kicked.nickname+'" has been '+leave_message self.error(say_levels.warning, log_message) if isinstance(kicked.irc_connection, irclib.ServerConnection): # an IRC duplicate of an XMPP user has been kicked, auto-rejoin kicked.irc_connection.join(bridge.irc_room) elif isinstance(kicked.xmpp_c, xmpp.client.Client): # an IRC user has been kicked, make its duplicate leave kicked.leave(m) else: # an IRC user with no duplicate on XMPP has been kicked, say it on XMPP bridge.say(say_levels.warning, log_message, on_irc=False) return # Part event if event.eventtype() == 'part': if not from_: self.error(say_levels.debug, 'a participant that wasn\'t here left:'+event_str) return if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left channel.' bridge.remove_participant('irc', from_.nickname, leave_message) return # Chan message if event.eventtype() in ['pubmsg', 'action']: message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False if isinstance(from_, Participant): from_.say_on_xmpp(message, action=action) else: bridge.say_on_behalf(source_nickname, message, 'xmpp', action=action) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) == 1: # chan mode self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for chan "'+event.target()+'"', debug=True) elif len(event.arguments()) == 2: # participant mode if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'" in chan "'+event.target()+'"', debug=True) return if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+chan) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+chan, send_to_admins=True) bridge.irc_op = False else: # unknown mode self.error(say_levels.debug, 'unknown IRC "mode" event (has 3 arguments):'+event_str) return # Namreply event if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return # Unhandled events self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | 30d7feb5a6be6812c77dd1e07ccddf08475194df /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/30d7feb5a6be6812c77dd1e07ccddf08475194df/bot.py |
for i in range(math.ceil(l_size/available_size)): | for i in range(int(math.ceil(l_size/available_size))): | def privmsg(self, target, text): """Send a PRIVMSG command.""" for l in text.split('\n'): l_size = len(l.encode('utf-8')) available_size = float(510-len('%s PRIVMSG %s :' % (self.irc_id, target))) # 510 is the size limit for IRC messages defined in RFC 2812 e = 0 for i in range(math.ceil(l_size/available_size)): s = e e = s+int(available_size) while len(l[s:e].encode('utf-8')) >= available_size: e -= 1 self.send_raw("PRIVMSG %s :%s" % (target, l[s:e])) | 7e500174f42994e7a52e2491e62bd70bd6d3d40b /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/7e500174f42994e7a52e2491e62bd70bd6d3d40b/irclib.py |
self.stop(message='Failed to connect to the XMPP room, stopping bridge') | self.stop(message='Failed to connect to the XMPP room, stopping bridge', log=False) | def _xmpp_join_callback(self, errors): """Called by muc._xmpp_presence_handler""" if len(errors) == 0: self.reconnecting = False if not self.mode: return self.bot.error(3, 'succesfully connected on XMPP side of bridge "'+str(self)+'"', debug=True) self.say(say_levels.notice, 'bridge "'+str(self)+'" is running in '+self.mode+' mode', on_irc=False) else: self.mode = None self.say(say_levels.error, 'failed to connect to the XMPP room, leaving ...', on_xmpp=False) for error in errors: try: raise error except xmpp.muc.RemoteServerNotFound: self._RemoteServerNotFound_handler() except: trace = traceback.format_exc() self.bot.error(say_levels.error, 'failed to connect to the XMPP room of bridge "'+str(self)+'", stopping bridge\n'+trace, send_to_admins=True) self.stop(message='Failed to connect to the XMPP room, stopping bridge') | c37b0c993335b7c98725bd3326e8df2a04f31a71 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/c37b0c993335b7c98725bd3326e8df2a04f31a71/bridge.py |
raise UnknownChannel, (channels, message, self) | raise UnknownChannel, (channels, message, str(self)) | def part(self, channels, message=""): """Send a PART command.""" try: if isinstance(channels, basestring): try: self.channels[channels].part(message=message) except KeyError: raise UnknownChannel, (channels, message, self) else: for channel in channels: try: self.channels[channel].part(message=message) except KeyError: raise UnknownChannel, (channel, message, self) except ServerNotConnectedError: self.disconnect(volontary=True) self.connect() | a3cda9bc31f3340020d142fee0ea79a6475137c7 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/a3cda9bc31f3340020d142fee0ea79a6475137c7/irclib.py |
nickname = None | source_nickname = None | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return nickname = None if event.source() and '!' in event.source(): nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str printed_event = False if event.eventtype() in ['pubmsg', 'action', 'privmsg', 'quit', 'part', 'nick', 'kick']: if nickname == None: return handled = False if event.eventtype() in ['quit', 'part'] and nickname == self.nickname: return if event.eventtype() in ['quit', 'part', 'nick', 'kick']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return else: self.error(2, debug_str, debug=True) printed_event = True if event.eventtype() == 'kick' and len(event.arguments()) < 1: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() in ['pubmsg', 'action']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return if nickname == self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' sent by self', debug=True) return for bridge in self.bridges: if connection.server != bridge.irc_server: continue try: from_ = bridge.get_participant(nickname) except Bridge.NoSuchParticipantException: continue # Private message if event.eventtype() == 'privmsg': if event.target() == None: return try: to_ = bridge.get_participant(event.target().split('!')[0]) self.error(2, debug_str, debug=True) from_.say_on_xmpp_to(to_.nickname, event.arguments()[0]) return except Bridge.NoSuchParticipantException: if event.target().split('!')[0] == self.nickname: # Message is for the bot self.error(2, debug_str, debug=True) connection.privmsg(from_.nickname, self.respond(event.arguments()[0])) return else: continue # kick handling if event.eventtype() == 'kick': if event.target().lower() == bridge.irc_room: try: kicked = bridge.get_participant(event.arguments()[0]) if isinstance(kicked.irc_connection, irclib.ServerConnection): kicked.irc_connection.join(bridge.irc_room) else: if len(event.arguments()) > 1: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' with reason: '+event.arguments()[1]) else: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' (no reason was given)') return except Bridge.NoSuchParticipantException: self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return else: continue # Leaving events if event.eventtype() == 'quit' or event.eventtype() == 'part' and event.target().lower() == bridge.irc_room: if len(event.arguments()) > 0: leave_message = event.arguments()[0] elif event.eventtype() == 'quit': leave_message = 'Left server.' elif event.eventtype() == 'part': leave_message = 'Left channel.' else: leave_message = '' bridge.remove_participant('irc', from_.nickname, leave_message) handled = True continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') handled = True continue # Chan message if event.eventtype() in ['pubmsg', 'action']: if bridge.irc_room == event.target().lower() and bridge.irc_server == connection.server: self.error(2, debug_str, debug=True) message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp(message, action=action) return else: continue if handled: return if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.real_nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.real_nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Joining events if event.eventtype() in ['namreply', 'join']: if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return elif event.eventtype() == 'join': bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) bridge.add_participant('irc', nickname) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(2, debug_str, debug=True) self.error(1, '2 arguments are needed for a '+event.eventtype()+' event', debug=True) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return self.error(2, debug_str, debug=True) bridges = self.iter_bridges(irc_room=event.target(), irc_server=connection.server) if len(bridges) > 1: raise Exception, 'more than one bridge for one irc chan, WTF ?' bridge = bridges[0] if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False return # Unhandled events if not printed_event: self.error(say_levels.debug, 'The following IRC event was not handled:'+event_str+'\n', send_to_admins=True) else: self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | 7af2a8a810665cc96ac01e14451dec4dfa2e27ba /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/7af2a8a810665cc96ac01e14451dec4dfa2e27ba/bot.py |
nickname = event.source().split('!')[0] | source_nickname = event.source().split('!')[0] | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return nickname = None if event.source() and '!' in event.source(): nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str printed_event = False if event.eventtype() in ['pubmsg', 'action', 'privmsg', 'quit', 'part', 'nick', 'kick']: if nickname == None: return handled = False if event.eventtype() in ['quit', 'part'] and nickname == self.nickname: return if event.eventtype() in ['quit', 'part', 'nick', 'kick']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return else: self.error(2, debug_str, debug=True) printed_event = True if event.eventtype() == 'kick' and len(event.arguments()) < 1: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() in ['pubmsg', 'action']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return if nickname == self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' sent by self', debug=True) return for bridge in self.bridges: if connection.server != bridge.irc_server: continue try: from_ = bridge.get_participant(nickname) except Bridge.NoSuchParticipantException: continue # Private message if event.eventtype() == 'privmsg': if event.target() == None: return try: to_ = bridge.get_participant(event.target().split('!')[0]) self.error(2, debug_str, debug=True) from_.say_on_xmpp_to(to_.nickname, event.arguments()[0]) return except Bridge.NoSuchParticipantException: if event.target().split('!')[0] == self.nickname: # Message is for the bot self.error(2, debug_str, debug=True) connection.privmsg(from_.nickname, self.respond(event.arguments()[0])) return else: continue # kick handling if event.eventtype() == 'kick': if event.target().lower() == bridge.irc_room: try: kicked = bridge.get_participant(event.arguments()[0]) if isinstance(kicked.irc_connection, irclib.ServerConnection): kicked.irc_connection.join(bridge.irc_room) else: if len(event.arguments()) > 1: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' with reason: '+event.arguments()[1]) else: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' (no reason was given)') return except Bridge.NoSuchParticipantException: self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return else: continue # Leaving events if event.eventtype() == 'quit' or event.eventtype() == 'part' and event.target().lower() == bridge.irc_room: if len(event.arguments()) > 0: leave_message = event.arguments()[0] elif event.eventtype() == 'quit': leave_message = 'Left server.' elif event.eventtype() == 'part': leave_message = 'Left channel.' else: leave_message = '' bridge.remove_participant('irc', from_.nickname, leave_message) handled = True continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') handled = True continue # Chan message if event.eventtype() in ['pubmsg', 'action']: if bridge.irc_room == event.target().lower() and bridge.irc_server == connection.server: self.error(2, debug_str, debug=True) message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp(message, action=action) return else: continue if handled: return if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.real_nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.real_nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Joining events if event.eventtype() in ['namreply', 'join']: if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return elif event.eventtype() == 'join': bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) bridge.add_participant('irc', nickname) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(2, debug_str, debug=True) self.error(1, '2 arguments are needed for a '+event.eventtype()+' event', debug=True) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return self.error(2, debug_str, debug=True) bridges = self.iter_bridges(irc_room=event.target(), irc_server=connection.server) if len(bridges) > 1: raise Exception, 'more than one bridge for one irc chan, WTF ?' bridge = bridges[0] if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False return # Unhandled events if not printed_event: self.error(say_levels.debug, 'The following IRC event was not handled:'+event_str+'\n', send_to_admins=True) else: self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | 7af2a8a810665cc96ac01e14451dec4dfa2e27ba /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/7af2a8a810665cc96ac01e14451dec4dfa2e27ba/bot.py |
printed_event = False if event.eventtype() in ['pubmsg', 'action', 'privmsg', 'quit', 'part', 'nick', 'kick']: if nickname == None: return handled = False if event.eventtype() in ['quit', 'part'] and nickname == self.nickname: return if event.eventtype() in ['quit', 'part', 'nick', 'kick']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return else: self.error(2, debug_str, debug=True) printed_event = True if event.eventtype() == 'kick' and len(event.arguments()) < 1: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() in ['pubmsg', 'action']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return if nickname == self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' sent by self', debug=True) return for bridge in self.bridges: if connection.server != bridge.irc_server: continue try: from_ = bridge.get_participant(nickname) except Bridge.NoSuchParticipantException: continue if event.eventtype() == 'privmsg': if event.target() == None: return | handled = False if event.eventtype() in ['privmsg', 'action']: if event.target() == self.nickname: connection.privmsg(source_nickname, self.respond(event.arguments()[0])) return elif not irclib.is_channel(event.target()[0]): for bridge in self.iter_bridges(irc_server=connection.server): | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return nickname = None if event.source() and '!' in event.source(): nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str printed_event = False if event.eventtype() in ['pubmsg', 'action', 'privmsg', 'quit', 'part', 'nick', 'kick']: if nickname == None: return handled = False if event.eventtype() in ['quit', 'part'] and nickname == self.nickname: return if event.eventtype() in ['quit', 'part', 'nick', 'kick']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return else: self.error(2, debug_str, debug=True) printed_event = True if event.eventtype() == 'kick' and len(event.arguments()) < 1: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() in ['pubmsg', 'action']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return if nickname == self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' sent by self', debug=True) return for bridge in self.bridges: if connection.server != bridge.irc_server: continue try: from_ = bridge.get_participant(nickname) except Bridge.NoSuchParticipantException: continue # Private message if event.eventtype() == 'privmsg': if event.target() == None: return try: to_ = bridge.get_participant(event.target().split('!')[0]) self.error(2, debug_str, debug=True) from_.say_on_xmpp_to(to_.nickname, event.arguments()[0]) return except Bridge.NoSuchParticipantException: if event.target().split('!')[0] == self.nickname: # Message is for the bot self.error(2, debug_str, debug=True) connection.privmsg(from_.nickname, self.respond(event.arguments()[0])) return else: continue # kick handling if event.eventtype() == 'kick': if event.target().lower() == bridge.irc_room: try: kicked = bridge.get_participant(event.arguments()[0]) if isinstance(kicked.irc_connection, irclib.ServerConnection): kicked.irc_connection.join(bridge.irc_room) else: if len(event.arguments()) > 1: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' with reason: '+event.arguments()[1]) else: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' (no reason was given)') return except Bridge.NoSuchParticipantException: self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return else: continue # Leaving events if event.eventtype() == 'quit' or event.eventtype() == 'part' and event.target().lower() == bridge.irc_room: if len(event.arguments()) > 0: leave_message = event.arguments()[0] elif event.eventtype() == 'quit': leave_message = 'Left server.' elif event.eventtype() == 'part': leave_message = 'Left channel.' else: leave_message = '' bridge.remove_participant('irc', from_.nickname, leave_message) handled = True continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') handled = True continue # Chan message if event.eventtype() in ['pubmsg', 'action']: if bridge.irc_room == event.target().lower() and bridge.irc_server == connection.server: self.error(2, debug_str, debug=True) message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp(message, action=action) return else: continue if handled: return if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.real_nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.real_nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Joining events if event.eventtype() in ['namreply', 'join']: if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return elif event.eventtype() == 'join': bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) bridge.add_participant('irc', nickname) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(2, debug_str, debug=True) self.error(1, '2 arguments are needed for a '+event.eventtype()+' event', debug=True) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return self.error(2, debug_str, debug=True) bridges = self.iter_bridges(irc_room=event.target(), irc_server=connection.server) if len(bridges) > 1: raise Exception, 'more than one bridge for one irc chan, WTF ?' bridge = bridges[0] if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False return # Unhandled events if not printed_event: self.error(say_levels.debug, 'The following IRC event was not handled:'+event_str+'\n', send_to_admins=True) else: self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | 7af2a8a810665cc96ac01e14451dec4dfa2e27ba /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/7af2a8a810665cc96ac01e14451dec4dfa2e27ba/bot.py |
to_ = bridge.get_participant(event.target().split('!')[0]) self.error(2, debug_str, debug=True) from_.say_on_xmpp_to(to_.nickname, event.arguments()[0]) return except Bridge.NoSuchParticipantException: if event.target().split('!')[0] == self.nickname: self.error(2, debug_str, debug=True) connection.privmsg(from_.nickname, self.respond(event.arguments()[0])) return else: continue if event.eventtype() == 'kick': if event.target().lower() == bridge.irc_room: try: kicked = bridge.get_participant(event.arguments()[0]) if isinstance(kicked.irc_connection, irclib.ServerConnection): kicked.irc_connection.join(bridge.irc_room) else: if len(event.arguments()) > 1: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' with reason: '+event.arguments()[1]) else: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' (no reason was given)') return except Bridge.NoSuchParticipantException: self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return else: continue if event.eventtype() == 'quit' or event.eventtype() == 'part' and event.target().lower() == bridge.irc_room: if len(event.arguments()) > 0: leave_message = event.arguments()[0] elif event.eventtype() == 'quit': leave_message = 'Left server.' elif event.eventtype() == 'part': leave_message = 'Left channel.' else: leave_message = '' bridge.remove_participant('irc', from_.nickname, leave_message) handled = True continue if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') handled = True continue if event.eventtype() in ['pubmsg', 'action']: if bridge.irc_room == event.target().lower() and bridge.irc_server == connection.server: self.error(2, debug_str, debug=True) message = event.arguments()[0] | from_ = bridge.get_participant(source_nickname) | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return nickname = None if event.source() and '!' in event.source(): nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str printed_event = False if event.eventtype() in ['pubmsg', 'action', 'privmsg', 'quit', 'part', 'nick', 'kick']: if nickname == None: return handled = False if event.eventtype() in ['quit', 'part'] and nickname == self.nickname: return if event.eventtype() in ['quit', 'part', 'nick', 'kick']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return else: self.error(2, debug_str, debug=True) printed_event = True if event.eventtype() == 'kick' and len(event.arguments()) < 1: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() in ['pubmsg', 'action']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return if nickname == self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' sent by self', debug=True) return for bridge in self.bridges: if connection.server != bridge.irc_server: continue try: from_ = bridge.get_participant(nickname) except Bridge.NoSuchParticipantException: continue # Private message if event.eventtype() == 'privmsg': if event.target() == None: return try: to_ = bridge.get_participant(event.target().split('!')[0]) self.error(2, debug_str, debug=True) from_.say_on_xmpp_to(to_.nickname, event.arguments()[0]) return except Bridge.NoSuchParticipantException: if event.target().split('!')[0] == self.nickname: # Message is for the bot self.error(2, debug_str, debug=True) connection.privmsg(from_.nickname, self.respond(event.arguments()[0])) return else: continue # kick handling if event.eventtype() == 'kick': if event.target().lower() == bridge.irc_room: try: kicked = bridge.get_participant(event.arguments()[0]) if isinstance(kicked.irc_connection, irclib.ServerConnection): kicked.irc_connection.join(bridge.irc_room) else: if len(event.arguments()) > 1: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' with reason: '+event.arguments()[1]) else: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' (no reason was given)') return except Bridge.NoSuchParticipantException: self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return else: continue # Leaving events if event.eventtype() == 'quit' or event.eventtype() == 'part' and event.target().lower() == bridge.irc_room: if len(event.arguments()) > 0: leave_message = event.arguments()[0] elif event.eventtype() == 'quit': leave_message = 'Left server.' elif event.eventtype() == 'part': leave_message = 'Left channel.' else: leave_message = '' bridge.remove_participant('irc', from_.nickname, leave_message) handled = True continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') handled = True continue # Chan message if event.eventtype() in ['pubmsg', 'action']: if bridge.irc_room == event.target().lower() and bridge.irc_server == connection.server: self.error(2, debug_str, debug=True) message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp(message, action=action) return else: continue if handled: return if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.real_nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.real_nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Joining events if event.eventtype() in ['namreply', 'join']: if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return elif event.eventtype() == 'join': bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) bridge.add_participant('irc', nickname) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(2, debug_str, debug=True) self.error(1, '2 arguments are needed for a '+event.eventtype()+' event', debug=True) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return self.error(2, debug_str, debug=True) bridges = self.iter_bridges(irc_room=event.target(), irc_server=connection.server) if len(bridges) > 1: raise Exception, 'more than one bridge for one irc chan, WTF ?' bridge = bridges[0] if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False return # Unhandled events if not printed_event: self.error(say_levels.debug, 'The following IRC event was not handled:'+event_str+'\n', send_to_admins=True) else: self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | 7af2a8a810665cc96ac01e14451dec4dfa2e27ba /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/7af2a8a810665cc96ac01e14451dec4dfa2e27ba/bot.py |
from_.say_on_xmpp(message, action=action) | from_.say_on_xmpp_to(connection.nickname, event.arguments()[0], action=action) | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return nickname = None if event.source() and '!' in event.source(): nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str printed_event = False if event.eventtype() in ['pubmsg', 'action', 'privmsg', 'quit', 'part', 'nick', 'kick']: if nickname == None: return handled = False if event.eventtype() in ['quit', 'part'] and nickname == self.nickname: return if event.eventtype() in ['quit', 'part', 'nick', 'kick']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return else: self.error(2, debug_str, debug=True) printed_event = True if event.eventtype() == 'kick' and len(event.arguments()) < 1: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() in ['pubmsg', 'action']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return if nickname == self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' sent by self', debug=True) return for bridge in self.bridges: if connection.server != bridge.irc_server: continue try: from_ = bridge.get_participant(nickname) except Bridge.NoSuchParticipantException: continue # Private message if event.eventtype() == 'privmsg': if event.target() == None: return try: to_ = bridge.get_participant(event.target().split('!')[0]) self.error(2, debug_str, debug=True) from_.say_on_xmpp_to(to_.nickname, event.arguments()[0]) return except Bridge.NoSuchParticipantException: if event.target().split('!')[0] == self.nickname: # Message is for the bot self.error(2, debug_str, debug=True) connection.privmsg(from_.nickname, self.respond(event.arguments()[0])) return else: continue # kick handling if event.eventtype() == 'kick': if event.target().lower() == bridge.irc_room: try: kicked = bridge.get_participant(event.arguments()[0]) if isinstance(kicked.irc_connection, irclib.ServerConnection): kicked.irc_connection.join(bridge.irc_room) else: if len(event.arguments()) > 1: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' with reason: '+event.arguments()[1]) else: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' (no reason was given)') return except Bridge.NoSuchParticipantException: self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return else: continue # Leaving events if event.eventtype() == 'quit' or event.eventtype() == 'part' and event.target().lower() == bridge.irc_room: if len(event.arguments()) > 0: leave_message = event.arguments()[0] elif event.eventtype() == 'quit': leave_message = 'Left server.' elif event.eventtype() == 'part': leave_message = 'Left channel.' else: leave_message = '' bridge.remove_participant('irc', from_.nickname, leave_message) handled = True continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') handled = True continue # Chan message if event.eventtype() in ['pubmsg', 'action']: if bridge.irc_room == event.target().lower() and bridge.irc_server == connection.server: self.error(2, debug_str, debug=True) message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp(message, action=action) return else: continue if handled: return if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.real_nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.real_nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Joining events if event.eventtype() in ['namreply', 'join']: if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return elif event.eventtype() == 'join': bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) bridge.add_participant('irc', nickname) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(2, debug_str, debug=True) self.error(1, '2 arguments are needed for a '+event.eventtype()+' event', debug=True) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return self.error(2, debug_str, debug=True) bridges = self.iter_bridges(irc_room=event.target(), irc_server=connection.server) if len(bridges) > 1: raise Exception, 'more than one bridge for one irc chan, WTF ?' bridge = bridges[0] if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False return # Unhandled events if not printed_event: self.error(say_levels.debug, 'The following IRC event was not handled:'+event_str+'\n', send_to_admins=True) else: self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | 7af2a8a810665cc96ac01e14451dec4dfa2e27ba /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/7af2a8a810665cc96ac01e14451dec4dfa2e27ba/bot.py |
continue | leave_message = 'Left server.' bridge.remove_participant('irc', from_.nickname, leave_message) continue if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') continue | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return nickname = None if event.source() and '!' in event.source(): nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str printed_event = False if event.eventtype() in ['pubmsg', 'action', 'privmsg', 'quit', 'part', 'nick', 'kick']: if nickname == None: return handled = False if event.eventtype() in ['quit', 'part'] and nickname == self.nickname: return if event.eventtype() in ['quit', 'part', 'nick', 'kick']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return else: self.error(2, debug_str, debug=True) printed_event = True if event.eventtype() == 'kick' and len(event.arguments()) < 1: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() in ['pubmsg', 'action']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return if nickname == self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' sent by self', debug=True) return for bridge in self.bridges: if connection.server != bridge.irc_server: continue try: from_ = bridge.get_participant(nickname) except Bridge.NoSuchParticipantException: continue # Private message if event.eventtype() == 'privmsg': if event.target() == None: return try: to_ = bridge.get_participant(event.target().split('!')[0]) self.error(2, debug_str, debug=True) from_.say_on_xmpp_to(to_.nickname, event.arguments()[0]) return except Bridge.NoSuchParticipantException: if event.target().split('!')[0] == self.nickname: # Message is for the bot self.error(2, debug_str, debug=True) connection.privmsg(from_.nickname, self.respond(event.arguments()[0])) return else: continue # kick handling if event.eventtype() == 'kick': if event.target().lower() == bridge.irc_room: try: kicked = bridge.get_participant(event.arguments()[0]) if isinstance(kicked.irc_connection, irclib.ServerConnection): kicked.irc_connection.join(bridge.irc_room) else: if len(event.arguments()) > 1: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' with reason: '+event.arguments()[1]) else: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' (no reason was given)') return except Bridge.NoSuchParticipantException: self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return else: continue # Leaving events if event.eventtype() == 'quit' or event.eventtype() == 'part' and event.target().lower() == bridge.irc_room: if len(event.arguments()) > 0: leave_message = event.arguments()[0] elif event.eventtype() == 'quit': leave_message = 'Left server.' elif event.eventtype() == 'part': leave_message = 'Left channel.' else: leave_message = '' bridge.remove_participant('irc', from_.nickname, leave_message) handled = True continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') handled = True continue # Chan message if event.eventtype() in ['pubmsg', 'action']: if bridge.irc_room == event.target().lower() and bridge.irc_server == connection.server: self.error(2, debug_str, debug=True) message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp(message, action=action) return else: continue if handled: return if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.real_nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.real_nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Joining events if event.eventtype() in ['namreply', 'join']: if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return elif event.eventtype() == 'join': bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) bridge.add_participant('irc', nickname) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(2, debug_str, debug=True) self.error(1, '2 arguments are needed for a '+event.eventtype()+' event', debug=True) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return self.error(2, debug_str, debug=True) bridges = self.iter_bridges(irc_room=event.target(), irc_server=connection.server) if len(bridges) > 1: raise Exception, 'more than one bridge for one irc chan, WTF ?' bridge = bridges[0] if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False return # Unhandled events if not printed_event: self.error(say_levels.debug, 'The following IRC event was not handled:'+event_str+'\n', send_to_admins=True) else: self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | 7af2a8a810665cc96ac01e14451dec4dfa2e27ba /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/7af2a8a810665cc96ac01e14451dec4dfa2e27ba/bot.py |
if event.eventtype() in ['namreply', 'join']: if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return elif event.eventtype() == 'join': bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) | if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'mode', 'join']: if event.eventtype() in ['pubmsg', 'action', 'part', 'kick'] and not source_nickname: self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() == 'kick' and len(event.arguments()) == 0: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: from_ = None if event.eventtype() == 'join': bridge.add_participant('irc', source_nickname) return if event.eventtype() == 'kick': try: kicked = bridge.get_participant(event.arguments()[0]) except Bridge.NoSuchParticipantException: self.error(2, debug_str, debug=True) self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return leave_message = 'kicked by '+nickname if len(event.arguments()) > 1: leave_message += ' with reason: '+event.arguments()[1] else: leave_message += ' (no reason was given)' log_message = '"'+kicked.nickname+'" has been '+leave_message self.error(say_levels.warning, log_message) if isinstance(kicked.irc_connection, irclib.ServerConnection): kicked.irc_connection.join(bridge.irc_room) elif isinstance(kicked.xmpp_c, xmpp.client.Client): kicked.leave(m) else: bridge.say(say_levels.warning, log_message, on_irc=False) return if event.eventtype() == 'part': if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left channel.' bridge.remove_participant('irc', from_.nickname, leave_message) return if event.eventtype() in ['pubmsg', 'action']: message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False if isinstance(from_, Participant): from_.say_on_xmpp(message, action=action) else: bridge.say_on_behalf(source_nickname, message, action=action) return if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(2, debug_str, debug=True) self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return bridge = self.get_bridge(irc_room=event.target(), irc_server=connection.server) if re.search('\+[^\-]*o', event.arguments()[0]): bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False return if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return nickname = None if event.source() and '!' in event.source(): nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str printed_event = False if event.eventtype() in ['pubmsg', 'action', 'privmsg', 'quit', 'part', 'nick', 'kick']: if nickname == None: return handled = False if event.eventtype() in ['quit', 'part'] and nickname == self.nickname: return if event.eventtype() in ['quit', 'part', 'nick', 'kick']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return else: self.error(2, debug_str, debug=True) printed_event = True if event.eventtype() == 'kick' and len(event.arguments()) < 1: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() in ['pubmsg', 'action']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return if nickname == self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' sent by self', debug=True) return for bridge in self.bridges: if connection.server != bridge.irc_server: continue try: from_ = bridge.get_participant(nickname) except Bridge.NoSuchParticipantException: continue # Private message if event.eventtype() == 'privmsg': if event.target() == None: return try: to_ = bridge.get_participant(event.target().split('!')[0]) self.error(2, debug_str, debug=True) from_.say_on_xmpp_to(to_.nickname, event.arguments()[0]) return except Bridge.NoSuchParticipantException: if event.target().split('!')[0] == self.nickname: # Message is for the bot self.error(2, debug_str, debug=True) connection.privmsg(from_.nickname, self.respond(event.arguments()[0])) return else: continue # kick handling if event.eventtype() == 'kick': if event.target().lower() == bridge.irc_room: try: kicked = bridge.get_participant(event.arguments()[0]) if isinstance(kicked.irc_connection, irclib.ServerConnection): kicked.irc_connection.join(bridge.irc_room) else: if len(event.arguments()) > 1: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' with reason: '+event.arguments()[1]) else: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' (no reason was given)') return except Bridge.NoSuchParticipantException: self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return else: continue # Leaving events if event.eventtype() == 'quit' or event.eventtype() == 'part' and event.target().lower() == bridge.irc_room: if len(event.arguments()) > 0: leave_message = event.arguments()[0] elif event.eventtype() == 'quit': leave_message = 'Left server.' elif event.eventtype() == 'part': leave_message = 'Left channel.' else: leave_message = '' bridge.remove_participant('irc', from_.nickname, leave_message) handled = True continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') handled = True continue # Chan message if event.eventtype() in ['pubmsg', 'action']: if bridge.irc_room == event.target().lower() and bridge.irc_server == connection.server: self.error(2, debug_str, debug=True) message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp(message, action=action) return else: continue if handled: return if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.real_nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.real_nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Joining events if event.eventtype() in ['namreply', 'join']: if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return elif event.eventtype() == 'join': bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) bridge.add_participant('irc', nickname) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(2, debug_str, debug=True) self.error(1, '2 arguments are needed for a '+event.eventtype()+' event', debug=True) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return self.error(2, debug_str, debug=True) bridges = self.iter_bridges(irc_room=event.target(), irc_server=connection.server) if len(bridges) > 1: raise Exception, 'more than one bridge for one irc chan, WTF ?' bridge = bridges[0] if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False return # Unhandled events if not printed_event: self.error(say_levels.debug, 'The following IRC event was not handled:'+event_str+'\n', send_to_admins=True) else: self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | 7af2a8a810665cc96ac01e14451dec4dfa2e27ba /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/7af2a8a810665cc96ac01e14451dec4dfa2e27ba/bot.py |
return if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(2, debug_str, debug=True) self.error(1, '2 arguments are needed for a '+event.eventtype()+' event', debug=True) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return self.error(2, debug_str, debug=True) bridges = self.iter_bridges(irc_room=event.target(), irc_server=connection.server) if len(bridges) > 1: raise Exception, 'more than one bridge for one irc chan, WTF ?' bridge = bridges[0] if re.search('\+[^\-]*o', event.arguments()[0]): bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return nickname = None if event.source() and '!' in event.source(): nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str printed_event = False if event.eventtype() in ['pubmsg', 'action', 'privmsg', 'quit', 'part', 'nick', 'kick']: if nickname == None: return handled = False if event.eventtype() in ['quit', 'part'] and nickname == self.nickname: return if event.eventtype() in ['quit', 'part', 'nick', 'kick']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return else: self.error(2, debug_str, debug=True) printed_event = True if event.eventtype() == 'kick' and len(event.arguments()) < 1: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() in ['pubmsg', 'action']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return if nickname == self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' sent by self', debug=True) return for bridge in self.bridges: if connection.server != bridge.irc_server: continue try: from_ = bridge.get_participant(nickname) except Bridge.NoSuchParticipantException: continue # Private message if event.eventtype() == 'privmsg': if event.target() == None: return try: to_ = bridge.get_participant(event.target().split('!')[0]) self.error(2, debug_str, debug=True) from_.say_on_xmpp_to(to_.nickname, event.arguments()[0]) return except Bridge.NoSuchParticipantException: if event.target().split('!')[0] == self.nickname: # Message is for the bot self.error(2, debug_str, debug=True) connection.privmsg(from_.nickname, self.respond(event.arguments()[0])) return else: continue # kick handling if event.eventtype() == 'kick': if event.target().lower() == bridge.irc_room: try: kicked = bridge.get_participant(event.arguments()[0]) if isinstance(kicked.irc_connection, irclib.ServerConnection): kicked.irc_connection.join(bridge.irc_room) else: if len(event.arguments()) > 1: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' with reason: '+event.arguments()[1]) else: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' (no reason was given)') return except Bridge.NoSuchParticipantException: self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return else: continue # Leaving events if event.eventtype() == 'quit' or event.eventtype() == 'part' and event.target().lower() == bridge.irc_room: if len(event.arguments()) > 0: leave_message = event.arguments()[0] elif event.eventtype() == 'quit': leave_message = 'Left server.' elif event.eventtype() == 'part': leave_message = 'Left channel.' else: leave_message = '' bridge.remove_participant('irc', from_.nickname, leave_message) handled = True continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') handled = True continue # Chan message if event.eventtype() in ['pubmsg', 'action']: if bridge.irc_room == event.target().lower() and bridge.irc_server == connection.server: self.error(2, debug_str, debug=True) message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp(message, action=action) return else: continue if handled: return if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.real_nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.real_nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Joining events if event.eventtype() in ['namreply', 'join']: if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return elif event.eventtype() == 'join': bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) bridge.add_participant('irc', nickname) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(2, debug_str, debug=True) self.error(1, '2 arguments are needed for a '+event.eventtype()+' event', debug=True) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return self.error(2, debug_str, debug=True) bridges = self.iter_bridges(irc_room=event.target(), irc_server=connection.server) if len(bridges) > 1: raise Exception, 'more than one bridge for one irc chan, WTF ?' bridge = bridges[0] if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False return # Unhandled events if not printed_event: self.error(say_levels.debug, 'The following IRC event was not handled:'+event_str+'\n', send_to_admins=True) else: self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | 7af2a8a810665cc96ac01e14451dec4dfa2e27ba /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/7af2a8a810665cc96ac01e14451dec4dfa2e27ba/bot.py |
|
if not printed_event: self.error(say_levels.debug, 'The following IRC event was not handled:'+event_str+'\n', send_to_admins=True) else: self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return nickname = None if event.source() and '!' in event.source(): nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str printed_event = False if event.eventtype() in ['pubmsg', 'action', 'privmsg', 'quit', 'part', 'nick', 'kick']: if nickname == None: return handled = False if event.eventtype() in ['quit', 'part'] and nickname == self.nickname: return if event.eventtype() in ['quit', 'part', 'nick', 'kick']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return else: self.error(2, debug_str, debug=True) printed_event = True if event.eventtype() == 'kick' and len(event.arguments()) < 1: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() in ['pubmsg', 'action']: if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return if nickname == self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' sent by self', debug=True) return for bridge in self.bridges: if connection.server != bridge.irc_server: continue try: from_ = bridge.get_participant(nickname) except Bridge.NoSuchParticipantException: continue # Private message if event.eventtype() == 'privmsg': if event.target() == None: return try: to_ = bridge.get_participant(event.target().split('!')[0]) self.error(2, debug_str, debug=True) from_.say_on_xmpp_to(to_.nickname, event.arguments()[0]) return except Bridge.NoSuchParticipantException: if event.target().split('!')[0] == self.nickname: # Message is for the bot self.error(2, debug_str, debug=True) connection.privmsg(from_.nickname, self.respond(event.arguments()[0])) return else: continue # kick handling if event.eventtype() == 'kick': if event.target().lower() == bridge.irc_room: try: kicked = bridge.get_participant(event.arguments()[0]) if isinstance(kicked.irc_connection, irclib.ServerConnection): kicked.irc_connection.join(bridge.irc_room) else: if len(event.arguments()) > 1: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' with reason: '+event.arguments()[1]) else: bridge.remove_participant('irc', kicked.nickname, 'Kicked by '+nickname+' (no reason was given)') return except Bridge.NoSuchParticipantException: self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return else: continue # Leaving events if event.eventtype() == 'quit' or event.eventtype() == 'part' and event.target().lower() == bridge.irc_room: if len(event.arguments()) > 0: leave_message = event.arguments()[0] elif event.eventtype() == 'quit': leave_message = 'Left server.' elif event.eventtype() == 'part': leave_message = 'Left channel.' else: leave_message = '' bridge.remove_participant('irc', from_.nickname, leave_message) handled = True continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') handled = True continue # Chan message if event.eventtype() in ['pubmsg', 'action']: if bridge.irc_room == event.target().lower() and bridge.irc_server == connection.server: self.error(2, debug_str, debug=True) message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp(message, action=action) return else: continue if handled: return if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.real_nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.real_nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Joining events if event.eventtype() in ['namreply', 'join']: if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return elif event.eventtype() == 'join': bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) bridge.add_participant('irc', nickname) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(2, debug_str, debug=True) self.error(1, '2 arguments are needed for a '+event.eventtype()+' event', debug=True) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return self.error(2, debug_str, debug=True) bridges = self.iter_bridges(irc_room=event.target(), irc_server=connection.server) if len(bridges) > 1: raise Exception, 'more than one bridge for one irc chan, WTF ?' bridge = bridges[0] if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False return # Unhandled events if not printed_event: self.error(say_levels.debug, 'The following IRC event was not handled:'+event_str+'\n', send_to_admins=True) else: self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | 7af2a8a810665cc96ac01e14451dec4dfa2e27ba /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/7af2a8a810665cc96ac01e14451dec4dfa2e27ba/bot.py |
self.error(2, debug_str, debug=True) self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event', no_debug_add=event_str) | self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event\n'+event_str) | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return source_nickname = None if event.source() and '!' in event.source(): source_nickname = event.source().split('!')[0] # A string representation of the event event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.'+event_str handled = False # Private message if event.eventtype() in ['privmsg', 'action']: if event.target() == self.nickname: # message is for the bot connection.privmsg(source_nickname, self.respond(event.arguments()[0])) return elif not irclib.is_channel(event.target()[0]): # search if the IRC user who sent the message is in one of the bridges for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) # he is, forward the message on XMPP if event.eventtype() == 'action': action = True else: action = False from_.say_on_xmpp_to(connection.nickname, event.arguments()[0], action=action) return except Bridge.NoSuchParticipantException: continue # he isn't, send an error connection.privmsg(source_nickname, 'XIB error: you cannot send a private message to an XMPP user if you are not in one of the chans he is in') # Server events if event.eventtype() in ['quit', 'nick']: for bridge in self.iter_bridges(irc_server=connection.server): try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: continue handled = True # Quit event if event.eventtype() == 'quit': if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left server.' bridge.remove_participant('irc', from_.nickname, leave_message) continue # Nickname change if event.eventtype() == 'nick': from_.change_nickname(event.target(), 'xmpp') continue if handled: return # Connection errors if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return # Chan errors if event.eventtype() in ['cannotsendtochan', 'notonchannel']: self.error(2, debug_str, debug=True) bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server) if event.eventtype() == 'cannotsendtochan': if connection.real_nickname == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p._close_irc_connection(event.eventtype()) p.irc_connection = event.eventtype() elif event.eventtype() == 'notonchannel': if connection.real_nickname == self.nickname: bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype()) else: p = bridge.get_participant(connection.real_nickname) p.irc_connection.join(bridge.irc_room) return # Ignore events not received on bot connection if connection.real_nickname != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Chan events if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'mode', 'join']: if event.eventtype() in ['pubmsg', 'action', 'part', 'kick'] and not source_nickname: self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.eventtype() == 'kick' and len(event.arguments()) == 0: self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) return bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) try: from_ = bridge.get_participant(source_nickname) except Bridge.NoSuchParticipantException: from_ = None # Join event if event.eventtype() == 'join': bridge.add_participant('irc', source_nickname) return # kick handling if event.eventtype() == 'kick': try: kicked = bridge.get_participant(event.arguments()[0]) except Bridge.NoSuchParticipantException: self.error(2, debug_str, debug=True) self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str) return leave_message = 'kicked by '+nickname if len(event.arguments()) > 1: leave_message += ' with reason: '+event.arguments()[1] else: leave_message += ' (no reason was given)' log_message = '"'+kicked.nickname+'" has been '+leave_message self.error(say_levels.warning, log_message) if isinstance(kicked.irc_connection, irclib.ServerConnection): # an IRC duplicate of an XMPP user has been kicked, auto-rejoin kicked.irc_connection.join(bridge.irc_room) elif isinstance(kicked.xmpp_c, xmpp.client.Client): # an IRC user has been kicked, make its duplicate leave kicked.leave(m) else: # an IRC user with no duplicate on XMPP has been kicked, say it on XMPP bridge.say(say_levels.warning, log_message, on_irc=False) return # Part event if event.eventtype() == 'part': if len(event.arguments()) > 0: leave_message = event.arguments()[0] else: leave_message = 'Left channel.' bridge.remove_participant('irc', from_.nickname, leave_message) return # Chan message if event.eventtype() in ['pubmsg', 'action']: message = event.arguments()[0] if event.eventtype() == 'action': action = True else: action = False if isinstance(from_, Participant): from_.say_on_xmpp(message, action=action) else: bridge.say_on_behalf(source_nickname, message, 'xmpp', action=action) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(2, debug_str, debug=True) self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event', no_debug_add=event_str) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return bridge = self.get_bridge(irc_room=event.target(), irc_server=connection.server) if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False return # Namreply event if event.eventtype() == 'namreply': bridge = self.get_bridge(irc_room=event.arguments()[1].lower(), irc_server=connection.server) for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.add_participant('irc', nickname) return # Unhandled events self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:'+event_str) | bad2287ee12b303a17c9ab800f27ee646429bea3 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/bad2287ee12b303a17c9ab800f27ee646429bea3/bot.py |
if from_protocol == 'irc' and isinstance(p.irc_connection, ServerConnection) and p.irc_connection.really_connected == True or from_protocol == 'xmpp' and isinstance(p.xmpp_c, xmpp.client.Client) and isinstance(p.muc, xmpp.muc): | if from_protocol == 'irc' and isinstance(p.irc_connection, ServerConnection) and p.irc_connection.really_connected == True and p.irc_connection.real_nickname == nickname or from_protocol == 'xmpp' and isinstance(p.xmpp_c, xmpp.client.Client) and isinstance(p.muc, xmpp.muc) and p.xmpp_c.nickname == nickname: | def addParticipant(self, from_protocol, nickname, real_jid=None, irc_id=None): """Add a participant to the bridge.""" if (from_protocol == 'irc' and nickname == self.irc_connection.get_nickname()) or (from_protocol == 'xmpp' and nickname == self.xmpp_room.nickname): self.bot.error('===> Debug: not adding self ('+self.bot.nickname+') to bridge "'+str(self)+'"', debug=True) return try: p = self.getParticipant(nickname) if p.protocol != from_protocol: if from_protocol == 'irc' and isinstance(p.irc_connection, ServerConnection) and p.irc_connection.really_connected == True or from_protocol == 'xmpp' and isinstance(p.xmpp_c, xmpp.client.Client) and isinstance(p.muc, xmpp.muc): if irc_id: p.irc_connection.irc_id = irc_id return p self.bot.error('===> Debug: "'+nickname+'" is on both sides of bridge "'+str(self)+'"', debug=True) self.say('[Warning] The nickname "'+nickname+'" is used on both sides of the bridge, please avoid that if possible') if isinstance(p.irc_connection, ServerConnection): p.irc_connection.close('') if p.irc_connection != 'both': p.irc_connection = 'both' if isinstance(p.muc, xmpp.muc): p.muc.leave('') self.bot.close_xmpp_connection(p.nickname) if p.xmpp_c != 'both': p.xmpp_c = 'both' return p except NoSuchParticipantException: pass if nickname == 'ChanServ' and from_protocol == 'irc': return self.lock.acquire() self.bot.error('===> Debug: adding participant "'+nickname+'" from "'+from_protocol+'" to bridge "'+str(self)+'"', debug=True) try: p = participant(self, from_protocol, nickname, real_jid=real_jid) except IOError: self.bot.error('===> Debug: IOError while adding participant "'+nickname+'" from "'+from_protocol+'" to bridge "'+str(self)+'", reconnectiong ...', debug=True) p.xmpp_c.reconnectAndReauth() except: self.bot.error('===> Debug: unknown error while adding participant "'+nickname+'" from "'+from_protocol+'" to bridge "'+str(self)+'"', debug=True) traceback.print_exc() return self.participants.append(p) self.lock.release() if self.mode not in ['normal', 'bypass']: if from_protocol == 'xmpp': xmpp_participants_nicknames = self.get_participants_nicknames_list(protocols=['xmpp']) self.say('[Info] Participants on XMPP: '+' '.join(xmpp_participants_nicknames), on_xmpp=False) elif self.mode == 'minimal' and from_protocol == 'irc': irc_participants_nicknames = self.get_participants_nicknames_list(protocols=['irc']) self.say('[Info] Participants on IRC: '+' '.join(irc_participants_nicknames), on_irc=False) return p | 0023f60cc5e80478b03a81c89bc07b82063e5a81 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/0023f60cc5e80478b03a81c89bc07b82063e5a81/bridge.py |
self.__del__() | self.stop() | def respond(self, message, participant=None, bot_admin=False): ret = '' command = shlex.split(message) args_array = [] if len(command) > 1: args_array = command[1:] command = command[0] if isinstance(participant, Participant) and bot_admin != participant.bot_admin: bot_admin = participant.bot_admin if command == 'xmpp-participants': if not isinstance(participant, Participant): for b in self.bridges: xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp']) ret += '\nparticipants on '+b.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) return ret else: xmpp_participants_nicknames = participant.bridge.get_participants_nicknames_list(protocols=['xmpp']) return '\nparticipants on '+participant.bridge.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) elif command == 'irc-participants': if not isinstance(participant, Participant): for b in self.bridges: irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc']) ret += '\nparticipants on '+b.irc_room+' at '+b.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) return ret else: irc_participants_nicknames = participant.bridge.get_participants_nicknames_list(protocols=['irc']) return '\nparticipants on '+participant.bridge.irc_room+' at '+participant.bridge.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) elif command == 'bridges': parser = ArgumentParser(prog=command) parser.add_argument('--show-mode', default=False, action='store_true') parser.add_argument('--show-say-level', default=False, action='store_true') parser.add_argument('--show-participants', default=False, action='store_true') try: args = parser.parse_args(args_array) except ArgumentParser.ParseException as e: return '\n'+e.args[1] ret = 'List of bridges:' for i, b in enumerate(self.bridges): ret += '\n'+str(i+1)+' - '+str(b) if args.show_mode: ret += ' - mode='+b.mode if args.show_say_level: ret += ' - say_level='+bridge._say_levels[b.say_level] if args.show_participants: xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp']) ret += '\nparticipants on XMPP ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc']) ret += '\nparticipants on IRC ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) if b.irc_connection == None: ret += ' - this bridge is stopped, use "restart-bridge '+str(i+1)+'" to restart it' return ret elif command in Bot.admin_commands: if bot_admin == False: return 'You have to be a bot admin to use this command.' if command == 'add-bridge': parser = ArgumentParser(prog=command) parser.add_argument('xmpp_room_jid', type=str) parser.add_argument('irc_chan', type=str) parser.add_argument('irc_server', type=str) parser.add_argument('--mode', choices=bridge._modes, default='normal') parser.add_argument('--say-level', choices=bridge._say_levels, default='all') parser.add_argument('--irc-port', type=int, default=6667) try: args = parser.parse_args(args_array) except ArgumentParser.ParseException as e: return '\n'+e.args[1] self.new_bridge(args.xmpp_room_jid, args.irc_chan, args.irc_server, args.mode, args.say_level, irc_port=args.irc_port) return 'Bridge added.' elif command == 'add-xmpp-admin': parser = ArgumentParser(prog=command) parser.add_argument('jid', type=str) try: args = parser.parse_args(args_array) except ArgumentParser.ParseException as e: return '\n'+e.args[1] self.admins_jid.append(args.jid) for b in self.bridges: for p in b.participants: if p.real_jid != None and xmpp.protocol.JID(args.jid).bareMatch(p.real_jid): p.bot_admin = True return 'XMPP admin added.' elif command == 'restart-bot': self.restart() return elif command == 'halt': self.__del__() return elif command in ['remove-bridge', 'restart-bridge', 'stop-bridge']: # we need to know which bridge the command is for if len(args_array) == 0: if isinstance(participant, Participant): b = participant.bridge else: return 'You must specify a bridge. '+self.respond('bridges') else: try: bn = int(args_array[0]) if bn < 1: raise IndexError b = self.bridges[bn-1] except IndexError: return 'Invalid bridge number "'+str(bn)+'". '+self.respond('bridges') except ValueError: bridges = self.findBridges(args_array) if len(bridges) == 0: return 'No bridge found matching "'+' '.join(args_array)+'". '+self.respond('bridges') elif len(bridges) == 1: b = bridges[0] elif len(bridges) > 1: return 'More than one bridge matches "'+' '.join(args_array)+'", please be more specific. '+self.respond('bridges') if command == 'remove-bridge': self.removeBridge(b) return 'Bridge removed.' elif command == 'restart-bridge': b.restart() return 'Bridge restarted.' elif command == 'stop-bridge': b.stop() return 'Bridge stopped.' else: ret = 'Error: "'+command+'" is not a valid command.\ncommands: '+' '.join(Bot.commands) if bot_admin == True: return ret+'\n'+'admin commands: '+' '.join(Bot.admin_commands) else: return ret | ead98574fc85e384856a1d04c90bd2af70a4c033 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/ead98574fc85e384856a1d04c90bd2af70a4c033/bot.py |
return 'Bot stopped.' | return | def stop_bot(bot, command, args_array, bridge): bot.stop() return 'Bot stopped.' | ce133313147381e12ba00a2885ef8c76a052f1a8 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/ce133313147381e12ba00a2885ef8c76a052f1a8/commands.py |
self.really_connected = False | self.really_connected = False | def disconnect(self, message="", volontary=False): """Hang up the connection. | 3803587fd9f33e482af7f2a20088ccdd46d9319f /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/3803587fd9f33e482af7f2a20088ccdd46d9319f/irclib.py |
self.quit(message) | if message and message != 'Connection reset by peer': self.quit(message) | def disconnect(self, message="", volontary=False): """Hang up the connection. | 3803587fd9f33e482af7f2a20088ccdd46d9319f /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/3803587fd9f33e482af7f2a20088ccdd46d9319f/irclib.py |
if isinstance(p.muc, xmpp.muc) and not xmpp.muc.connected: | if isinstance(p.muc, xmpp.muc) and not p.muc.connected: | def remove_participant(self, left_protocol, nickname, leave_message): """Remove the participant using nickname from the bridge. Raises a NoSuchParticipantException if nickname is not used in the bridge.""" was_on_both = None p = self.get_participant(nickname) if p.left: self.lock.acquire() self.participants.remove(p) del p self.lock.release() return if p.protocol == 'xmpp': if p.irc_connection == 'both': was_on_both = True if left_protocol == 'xmpp': p.protocol = 'irc' p.create_duplicate_on_xmpp() elif left_protocol == 'irc': p.create_duplicate_on_irc() else: if left_protocol == 'xmpp': was_on_both = False elif left_protocol == 'irc': # got disconnected somehow if isinstance(p.irc_connection, ServerConnection): if p.irc_connection.socket == 'closed': return p.irc_connection.join(self.irc_room) else: c = self.bot.irc.get_connection(self.irc_server, self.irc_port, p.duplicate_nickname) if not (c and self.irc_room in c.left_channels): p._close_irc_connection(leave_message) p.create_duplicate_on_irc() return elif p.protocol == 'irc': if p.xmpp_c == 'both': was_on_both = True if left_protocol == 'irc': p.protocol = 'xmpp' p.create_duplicate_on_irc() elif left_protocol == 'xmpp': p.create_duplicate_on_xmpp() else: if left_protocol == 'irc': was_on_both = False elif left_protocol == 'xmpp': if isinstance(p.muc, xmpp.muc) and not xmpp.muc.connected: return # got disconnected somehow if isinstance(p.xmpp_c, xmpp.client.Client): self.bot.reopen_xmpp_connection(p.xmpp_c) return else: raise Exception('[Internal Error] bad protocol') if was_on_both == True: self.bot.error(3, '"'+nickname+'" was on both sides of bridge "'+str(self)+'" but left '+left_protocol, debug=True) elif was_on_both == False: self.bot.error(3, 'removing participant "'+nickname+'" from bridge "'+str(self)+'"', debug=True) p.leave(leave_message) if left_protocol == 'xmpp': if self.mode not in ['normal', 'bypass']: self.show_participants_list_on(protocols=['irc']) elif left_protocol == 'irc': if self.mode == 'minimal': self.show_participants_list_on(protocols=['xmpp']) else: self.bot.error(say_levels.debug, 'Bad decision tree, p.protocol='+p.protocol+' left_protocol='+left_protocol+'\np.xmpp_c='+str(p.xmpp_c)+'\np.irc_connection='+str(p.irc_connection), send_to_admins=True) | e43ff656b06abdb9e5bbeaae1d9e2ddd1838239b /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/e43ff656b06abdb9e5bbeaae1d9e2ddd1838239b/bridge.py |
p.irc_connection = error | p.irc_connection = event.eventtype() | def _irc_event_handler(self, connection, event): """[Internal] Manage IRC events""" # Answer ping if event.eventtype() == 'ping': connection.pong(connection.get_server_name()) return # Events we always want to ignore if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: return if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042']: self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) return nickname = None if event.source() != None: if '!' in event.source(): nickname = event.source().split('!')[0] # Events that we want to ignore only in some cases if event.eventtype() in ['umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns']: if connection.really_connected == False: if event.target() == connection.nickname: connection.really_connected = True connection._call_nick_callbacks(None) elif len(connection.nick_callbacks) > 0: self.error(3, 'event target ('+event.target()+') and connection nickname ('+connection.nickname+') don\'t match', debug=True) connection._call_nick_callbacks('nicknametoolong', arguments=[len(event.target())]) self.error(1, 'ignoring '+event.eventtype(), debug=True) return # A string representation of the event event_str = 'connection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) debug_str = 'Received IRC event.\n'+event_str printed_event = False if event.eventtype() in ['pubmsg', 'action', 'privmsg', 'quit', 'part', 'nick', 'kick']: if nickname == None: return handled = False if event.eventtype() in ['quit', 'part'] and nickname == self.nickname: return if event.eventtype() in ['quit', 'part', 'nick', 'kick']: if connection.get_nickname() != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return else: self.error(2, debug_str, debug=True) printed_event = True if event.eventtype() == 'kick' and len(event.arguments()) < 1: self.error(1, 'at least 1 argument is needed for a '+event.eventtype()+' event', debug=True) return if event.eventtype() in ['pubmsg', 'action']: if connection.get_nickname() != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) return if nickname == self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' sent by self', debug=True) return # TODO: lock self.bridges for thread safety for bridge in self.bridges: if connection.server != bridge.irc_server: continue try: from_ = bridge.getParticipant(nickname) except Bridge.NoSuchParticipantException: continue # Private message if event.eventtype() == 'privmsg': if event.target() == None: return try: to_ = bridge.getParticipant(event.target().split('!')[0]) self.error(2, debug_str, debug=True) from_.sayOnXMPPTo(to_.nickname, event.arguments()[0]) return except Bridge.NoSuchParticipantException: if event.target().split('!')[0] == self.nickname: # Message is for the bot self.error(2, debug_str, debug=True) connection.privmsg(from_.nickname, self.respond(event.arguments()[0])) return else: continue # kick handling if event.eventtype() == 'kick': if event.target().lower() == bridge.irc_room: try: kicked = bridge.getParticipant(event.arguments()[0]) if isinstance(kicked.irc_connection, irclib.ServerConnection): kicked.irc_connection.join(bridge.irc_room) else: if len(event.arguments()) > 1: bridge.removeParticipant('irc', kicked.nickname, 'Kicked by '+nickname+' with reason: '+event.arguments()[1]) else: bridge.removeParticipant('irc', kicked.nickname, 'Kicked by '+nickname+' (no reason was given)') return except Bridge.NoSuchParticipantException: self.error(1, 'a participant that was not here has been kicked ? WTF ?', debug=True) return else: continue # Leaving events if event.eventtype() == 'quit' or event.eventtype() == 'part' and event.target().lower() == bridge.irc_room: if len(event.arguments()) > 0: leave_message = event.arguments()[0] elif event.eventtype() == 'quit': leave_message = 'Left server.' elif event.eventtype() == 'part': leave_message = 'Left channel.' else: leave_message = '' bridge.removeParticipant('irc', from_.nickname, leave_message) handled = True continue # Nickname change if event.eventtype() == 'nick': from_.changeNickname(event.target(), 'xmpp') handled = True continue # Chan message if event.eventtype() in ['pubmsg', 'action']: if bridge.irc_room == event.target().lower() and bridge.irc_server == connection.server: self.error(2, debug_str, debug=True) message = event.arguments()[0] if event.eventtype() == 'action': message = '/me '+message from_.sayOnXMPP(message) return else: continue if handled: return # Handle bannedfromchan if event.eventtype() == 'bannedfromchan': if len(event.arguments()) < 1: self.error(1, 'length of arguments should be greater than 0 for a '+event.eventtype()+' event', debug=True) return for bridge in self.bridges: if connection.server != bridge.irc_server or event.arguments()[0].lower() != bridge.irc_room: continue if event.target() == self.nickname: self.error(say_levels.error, 'the nickname "'+event.target()+'" is banned from the IRC chan of bridge "'+str(bridge)+'"') raise Exception('[Error] the nickname "'+event.target()+'" is banned from the IRC chan of bridge "'+str(bridge)+'"') else: try: banned = bridge.getParticipant(event.target()) if banned.irc_connection != 'bannedfromchan': banned.irc_connection = 'bannedfromchan' self.error(2, debug_str, debug=True) bridge.say(say_levels.warning, 'the nickname "'+event.target()+'" is banned from the IRC chan', log=True) else: self.error(1, 'ignoring '+event.eventtype(), debug=True) except Bridge.NoSuchParticipantException: self.error(1, 'no such participant. WTF ?', debug=True) return return if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) else: self.error(say_levels.debug, debug_str, send_to_admins=True) return if event.eventtype() in ['cannotsendtochan', 'notonchannel', 'inviteonlychan']: self.error(2, debug_str, debug=True) bridges = self.getBridges(irc_room=event.arguments()[0], irc_server=connection.server) if len(bridges) > 1: raise Exception, 'more than one bridge for one irc chan, WTF ?' bridge = bridges[0] if connection.get_nickname() == self.nickname: bridge._join_irc_failed(event.eventtype()) else: p = bridge.getParticipant(connection.get_nickname()) p._close_irc_connection('') p.irc_connection = error return # Ignore events not received on bot connection if connection.get_nickname() != self.nickname: self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) return # Joining events if event.eventtype() in ['namreply', 'join']: if event.eventtype() == 'namreply': for bridge in self.getBridges(irc_room=event.arguments()[1].lower(), irc_server=connection.server): for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): if nickname == '' or nickname == self.nickname: continue bridge.addParticipant('irc', nickname) return elif event.eventtype() == 'join': bridges = self.getBridges(irc_room=event.target().lower(), irc_server=connection.server) if len(bridges) == 0: self.error(2, debug_str, debug=True) self.error(3, 'no bridge found for "'+event.target().lower()+' at '+connection.server+'"', debug=True) return for bridge in bridges: bridge.addParticipant('irc', nickname, irc_id=event.source()) return # Mode event if event.eventtype() == 'mode': if len(event.arguments()) < 2: self.error(2, debug_str, debug=True) self.error(1, '2 arguments are needed for a '+event.eventtype()+' event', debug=True) return if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) return self.error(2, debug_str, debug=True) bridges = self.getBridges(irc_room=event.target(), irc_server=connection.server) if len(bridges) > 1: raise Exception, 'more than one bridge for one irc chan, WTF ?' bridge = bridges[0] if re.search('\+[^\-]*o', event.arguments()[0]): # bot is channel operator bridge.irc_op = True self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) elif re.search('\-[^\+]*o', event.arguments()[0]): # bot lost channel operator privileges if bridge.irc_op: self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) bridge.irc_op = False return # Unhandled events if not printed_event: self.error(say_levels.debug, 'The following IRC event was not handled:\n'+event_str+'\n', send_to_admins=True) else: self.error(1, 'event not handled', debug=True) self._send_message_to_admins(say_levels.debug, 'The following IRC event was not handled:\n'+event_str) | 5172b50a28e7e1475dba3d9fb04300bc088ffe7b /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9915/5172b50a28e7e1475dba3d9fb04300bc088ffe7b/bot.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.