Commits

Jason R. Coombs  committed c3e5fe5

Allow a compiled expression to be passed to regexp handler

  • Participants
  • Parent commits 2d7ceed

Comments (0)

Files changed (1)

File pmxbot/core.py

 class RegexpHandler(ContainsHandler):
 	class_priority = 4
 
+	def __init__(self, *args, **kwargs):
+		super(RegexpHandler, self).__init__(*args, **kwargs)
+		if isinstance(self.pattern, basestring):
+			self.pattern = re.compile(self.pattern, re.IGNORECASE)
+
 	def match(self, message, channel):
 		return self.pattern.search(message)
 
 	return RegexpHandler(
 		name=name.lower(),
 		doc=doc,
-		pattern=re.compile(regexp, re.IGNORECASE),
+		pattern=regexp,
 		**kwargs
 	).decorate