Exemplo n.º 1
0
	def names(self, channels):
		"""
		List the users in a channel.
		"""
		if isIterable(channels):
			self.sendLine('NAMES %s' % ",".join(channels))
		else:
			self.sendLine('NAMES %s' % channels)
Exemplo n.º 2
0
    def names(self, channels):
        """
		List the users in a channel.
		"""
        if isIterable(channels):
            self.sendLine('NAMES %s' % ",".join(channels))
        else:
            self.sendLine('NAMES %s' % channels)
Exemplo n.º 3
0
	def checkAndLoadReqs(self, module, resolvedModules):
		reqs = module.REQUIRES
		if not isIterable(reqs):
			reqs = (reqs,) #assume string?
		for req in reqs:
			if req in self.loadedModules: continue
			else:
				#attempt to load
				if req not in self.allowedmodules:
					return False
				if not self.loadModule(req, resolvedModules):
					return None
		return True
Exemplo n.º 4
0
	def checkAndLoadReqs(self, module, resolvedModules):
		reqs = module.REQUIRES
		if not isIterable(reqs):
			reqs = (reqs,)
		notallowed = set()
		failed = set()
		for req in reqs:
			if req in self.loadedModules: continue
			else:
				#attempt to load
				if req not in self.allowedmodules:
					notallowed.add(req)
				if not self.loadModule(req, resolvedModules):
					failed.add(req)
		if notallowed or failed:
			return (notallowed, failed)
		return True
Exemplo n.º 5
0
	def processMappings(self, module):
		eventmap = self.eventmap
		for mapping in module.mappings:
			for etype in mapping.types:

				etype = etype.lower()
				
				# There's no actual reason to restrict etypes to a preset list, and in some cases it might be annoying
				# (e.g. hooking a numeric event etype)
				if etype not in eventmap:
					eventmap[etype] = {}
					eventmap[etype]["instant"] = []
					eventmap[etype]["regex"] = []
					eventmap[etype]["command"] = {}
				
				# Add etype to servernamemapping
				# This is _addmap inlined
				if etype == "sendmsg":
					self.MSGHOOKS = True
				if not mapping.command and not mapping.regex: 
					eventmap[etype]["instant"].append(mapping)
					eventmap[etype]["instant"].sort(key=attrgetter('priority'))

				if mapping.command:
					mapcom = mapping.command
					#check if tuple or list or basestring (str or unicodes)
					# I guess it's not a big deal to check both
					if isIterable(mapcom):
						for commandname in mapcom:
							eventmap[etype]["command"].setdefault(commandname, []).append(mapping)
							eventmap[etype]["command"][commandname].sort(key=attrgetter('priority'))
					# TODO: unicode command, should work...
					elif isinstance(mapcom, basestring):
						eventmap[etype]["command"].setdefault(mapcom, []).append(mapping)
						eventmap[etype]["command"][mapcom].sort(key=attrgetter('priority'))

				if mapping.regex:
					eventmap[etype]["regex"].append(mapping)
					eventmap[etype]["regex"].sort(key=attrgetter('priority'))
Exemplo n.º 6
0
	def assembleMsgWLen(self, s, strins=None, fcfs=False, joinsep=None):
		enc = self.settings.encoding
		if isinstance(strins, basestring):
			sl = self.calcAvailableMsgLength(s.format(""))
			if sl <= 0: # case where template string is already too big
				return splitEncodedUnicode(s, len(s)+sl, encoding=enc)[0][0]
			return s.format(splitEncodedUnicode(strins, sl, encoding=enc)[0][0])
		
		ls = len(strins)
		if joinsep is not None: 
			# lj is len(joinsep) when comparing to avail in fcfs add 2 to allow some
			# room for start of next element at least
			if isinstance(joinsep, unicode): lj = len(joinsep.encode(enc))
			else: lj = len(joinsep)
		if isIterable(strins):
			if joinsep is not None: avail = self.calcAvailableMsgLength(s.format("")) # must be only one replacement
			else: avail = self.calcAvailableMsgLength(s.format(*[""]*ls)) # format with empty strins to calc max avail
			if avail < 0: # case where template string is already too big
				s = s.format(*[""]*ls)
				return splitEncodedUnicode(s, len(s)+avail, encoding=enc)[0][0]
			if fcfs:
				# first come first served
				if not isinstance(strins, list): 
					raise ValueError("Require list/tuple, dict, or string for strins.")
				for i, rep in enumerate(strins):
					# get trimmed replacement and the length of that trimmed replacement
					rep, lrep = splitEncodedUnicode(rep, avail, encoding=enc)[0]
					# track remaining message space left
					avail -= lrep
					#append joinsep if there's room, else make avail 0
					if (joinsep is not None) and (i != ls-1): 
						if avail < lj+2: 
							avail = 0
						else: 
							rep = rep+joinsep
							avail -= lj
					# replace the replacement with the trimmed version
					strins[i] = rep
				if joinsep is not None: return s.format("".join(strins))
				else: return s.format(*strins)
			else:
				# round 2, even divide
				if joinsep is not None: segmentlength = int(floor(avail / ls)) - (ls-1*lj)
				else: segmentlength = int(floor(avail / ls))
				if isinstance(strins, tuple):
					strins = list(strins)
				for i, sr in enumerate(strins):
					if (joinsep is not None) and (i != ls-1):
						strins[i] = splitEncodedUnicode(sr, segmentlength, encoding=enc)[0][0]+joinsep
					else:
						strins[i] = splitEncodedUnicode(sr, segmentlength, encoding=enc)[0][0]
				if joinsep is not None: return s.format("".join(strins))
				else: return s.format(*strins)
			
		elif isinstance(strins, dict):
			# total space available for message
			avail = self.calcAvailableMsgLength(s.format(**dict(((key, "") for key in strins.keys())))) # format with empty strins to calc max avail
			if avail < 0: # case where template string is already too big
				s = s.format(**dict(((key, "") for key in strins.keys())))
				return splitEncodedUnicode(s, len(s)+avail, encoding=enc)[0][0]
			if fcfs:
				# first come first served (NOTE: This doesn't make much sense for an unordered thing like a dictionary)
				# hopefully we are passed an ordered dictionary or something that extends from dict.
				for key, rep in strins.iteritems():
					rep, lrep = splitEncodedUnicode(rep, avail, encoding=enc)[0]
					strins[key] = rep
					avail -= lrep
				return s.format(**strins)
			else:
				# round 2, even divide
				segmentlength = int(floor((avail / ls)))
				for key, value in strins.iteritems():
					strins[key] = splitEncodedUnicode(value, segmentlength, encoding=enc)[0][0]
				return s.format(**strins)
		else:
			raise ValueError("Require list/tuple, dict, or string for strins.")
Exemplo n.º 7
0
	def assembleMsgWLen(self, s, strins=None, fcfs=False, joinsep=None):
		enc = self.settings.encoding
		if isinstance(strins, basestring):
			sl = self.calcAvailableMsgLength(s.format(""))
			if sl <= 0: # case where template string is already too big
				return splitEncodedUnicode(s, len(s)+sl, encoding=enc)[0][0]
			return s.format(splitEncodedUnicode(strins, sl, encoding=enc)[0][0])
		
		ls = len(strins)
		if joinsep is not None: 
			# lj is len(joinsep) when comparing to avail in fcfs add 2 to allow some
			# room for start of next element at least
			if isinstance(joinsep, unicode): lj = len(joinsep.encode(enc))
			else: lj = len(joinsep)
		if isIterable(strins):
			if joinsep is not None: avail = self.calcAvailableMsgLength(s.format("")) # must be only one replacement
			else: avail = self.calcAvailableMsgLength(s.format(*[""]*ls)) # format with empty strins to calc max avail
			if avail < 0: # case where template string is already too big
				s = s.format(*[""]*ls)
				return splitEncodedUnicode(s, len(s)+avail, encoding=enc)[0][0]
			if fcfs:
				# first come first served
				if not isinstance(strins, list): 
					raise ValueError("Require list/tuple, dict, or string for strins.")
				for i, rep in enumerate(strins):
					# get trimmed replacement and the length of that trimmed replacement
					rep, lrep = splitEncodedUnicode(rep, avail, encoding=enc)[0]
					# track remaining message space left
					avail -= lrep
					#append joinsep if there's room, else make avail 0
					if (joinsep is not None) and (i != ls-1): 
						if avail < lj+2: 
							avail = 0
						else: 
							rep = rep+joinsep
							avail -= lj
					# replace the replacement with the trimmed version
					strins[i] = rep
				if joinsep is not None: return s.format("".join(strins))
				else: return s.format(*strins)
			else:
				# round 2, even divide
				if joinsep is not None: segmentlength = int(floor(avail / ls)) - (ls-1*lj)
				else: segmentlength = int(floor(avail / ls))
				if isinstance(strins, tuple):
					strins = list(strins)
				for i, sr in enumerate(strins):
					if (joinsep is not None) and (i != ls-1):
						strins[i] = splitEncodedUnicode(sr, segmentlength, encoding=enc)[0][0]+joinsep
					else:
						strins[i] = splitEncodedUnicode(sr, segmentlength, encoding=enc)[0][0]
				if joinsep is not None: return s.format("".join(strins))
				else: return s.format(*strins)
			
		elif isinstance(strins, dict):
			# total space available for message
			avail = self.calcAvailableMsgLength(s.format(**dict(((key, "") for key in strins.keys())))) # format with empty strins to calc max avail
			if avail < 0: # case where template string is already too big
				s = s.format(**dict(((key, "") for key in strins.keys())))
				return splitEncodedUnicode(s, len(s)+avail, encoding=enc)[0][0]
			if fcfs:
				# first come first served (NOTE: This doesn't make much sense for an unordered thing like a dictionary)
				# hopefully we are passed an ordered dictionary or something that extends from dict.
				for key, rep in strins.iteritems():
					rep, lrep = splitEncodedUnicode(rep, avail, encoding=enc)[0]
					strins[key] = rep
					avail -= lrep
				return s.format(**strins)
			else:
				# round 2, even divide
				segmentlength = int(floor((avail / ls)))
				for key, value in strins.iteritems():
					strins[key] = splitEncodedUnicode(value, segmentlength, encoding=enc)[0][0]
				return s.format(**strins)
		else:
			raise ValueError("Require list/tuple, dict, or string for strins.")