Commits

Jason R. Coombs  committed d98686f

Implemented SeparatedValues

  • Participants
  • Parent commits b5214ef

Comments (0)

Files changed (1)

File jaraco/net/notification.py

 import socket
 import sys
 import traceback
+import itertools
 import io
 
 from jaraco.util.dictlib import DictFilter
 	def write(self, msg):
 		self.notify(msg)
 
+class SeparatedValues(unicode):
+	"""
+	A string separated by a separator. Overrides __iter__ for getting
+	the values.
+	
+	>>> list(SeparatedValues('a,b,c'))
+	[u'a', u'b', u'c']
+	
+	Whitespace is stripped and empty values are discarded.
+	
+	>>> list(SeparatedValues(' a,   b   , c,  '))
+	[u'a', u'b', u'c']
+	
+	"""
+	separator = ','
+	
+	def __iter__(self):
+		parts = self.split(self.separator)
+		return itertools.ifilter(None, (part.strip() for part in parts))
+
 class SMTPMailbox(NotificationTarget):
 	from_addr = None
 
 	@property
 	def dest_addrs(self):
 		return itertools.chain.from_iterable(
-			comma_separated_values(getattr(self, key, ''))
+			SeparatedValues(getattr(self, key, ''))
 			for key in ('to_addrs', 'cc_addrs', 'bcc_addrs')
 		)