Commits

Jason R. Coombs  committed 4c21d5b

Added missing first() function

  • Participants
  • Parent commits 9f8ddee
  • Tags 1100.8.3

Comments (0)

Files changed (1)

File pmxbot/logging.py

 		cursor = self.db.find(query, fields=fields)
 		cursor = cursor.sort('_id', storage.pymongo.DESCENDING)
 		res = first(cursor)
-		if not res:
-			return None
-		return [res['_id'].generation_time, res['channel']]
+		return res and [res['_id'].generation_time(), res['channel']]
 
 	def strike(self, channel, nick, count):
 		channel = channel.replace('#', '')
 		message['_id'] = oid
 		message['datetime'] = self._fmt_date(dt)
 		self.db.insert(message)
+
+def first(iterable):
+	"""
+	Return the first element from the iterable or None if no element is
+	found.
+	"""
+	try:
+		return next(iterable)
+	except StopIteration:
+		pass