Walter Dörwald committed 1feecc6

The transparent pixel used by ll.xist.ns.htmlspecials.pixel
has been renamed to spc.gif to avoid problems with IE.

Removed a debug print in ll.xist.xfind.Finder.__getitem__.

ll.xist.xfind now has a new function item, that can be used to get
a certain item or slice from an iterator.

Prepare for a new release.

Comments (0)

Files changed (7)

 <?xml version='1.0' encoding='iso-8859-1'?>
+<section><title>Changes in 2.6.2 (released 11/24/2004)</title>
+<item>The transparent pixel used by <class>ll.xist.ns.htmlspecials.pixel</class>
+has been renamed to <filename>spc.gif</filename> to avoid problems with IE.</item>
+<item>Removed a debug print in <class>ll.xist.xfind.Finder.__getitem__</class>.</item>
+<item><module>ll.xist.xfind</module> now has a new function <function>item</function>,
+that can be used to get a certain item or slice from an iterator.</item>
 <section><title>Changes in 2.6.1 (released 11/02/2004)</title>
 <item>Fixed a bug in <method>ll.xist.xfind.Finder.__floordiv__</method>.</item>
-XIST v2.6.1
+XIST v2.6.2
 XIST is an extensible HTML/XML generator written in Python.


 	class Attrs(html.img.Attrs):
 		class color(xsc.TextAttr):
-			The pixel color as a three digit hex value.
+			The pixel color as a three digit hex value or <lit>spc</lit> to
+			get a transparent pixel.
-			default = 0
+			default = "spc"
 			def checkvalid(self):
 				if len(self) and not self.isfancy():
 					content = unicode(self)
-					if content != u"0":
+					if content != u"spc":
 						if len(content) == 3:
 							for c in content:
 								if c not in "0369cf":
 			return self
 	def __getitem__(self, index):
-		if isinstance(index, slice):
-			return list(self)[index] # fall back to materializing the list
-		else:
-			if index>=0:
-				for item in self:
-					if not index:
-						return item
-					index -= 1
-				raise IndexError
-			else:
-				index = -index
-				cache = []
-				for item in self:
-					cache.append(item)
-					if len(cache)>index:
-						cache.pop(0)
-				if len(cache)==index:
-					return cache[0]
-				else:
-					raise IndexError
+		return item(self, index)
 	# We can't implement __len__, because if a Finder object is passed to list(), __len__() would be called, exhausting the iterator
 		return "<%s.%s object for %r%s at 0x%x>" % (self.__class__.__module__, self.__class__.__name__, self.iterator, ops, id(self))
-def first(iterator, default=None):
+_defaultitem = object()
+def item(iterator, index, default=_defaultitem):
+	"""
+	<par>Return the <arg>index</arg>th item from the iterator <arg>iterator</arg>.
+	<arg>index</arg> may be an integer (negative integers are relative to the
+	end (i.e. the last item produced by the iterator) or a <class>slice</class>.</par>
+	<par>Calling this function will partially or totally exhaust the iterator.</par>
+	<par>If <arg>default</arg> is gived, this will be the default value when
+	the iterator doesn't contain an item at this position. Otherwise an
+	<class>IndexError</class> will be raised.</par>
+	"""
+	if isinstance(index, slice):
+		return list(iterator)[index] # fall back to materializing the list
+	else:
+		i = index
+		if i>=0:
+			for item in iterator:
+				if not i:
+					return item
+				i -= 1
+		else:
+			i = -index
+			cache = []
+			for item in iterator:
+				cache.append(item)
+				if len(cache)>i:
+					cache.pop(0)
+			if len(cache)==i:
+				return cache[0]
+		if default is _defaultitem:
+			raise IndexError(index)
+		else:
+			return default
+def first(iterator, default=_defaultitem):
 	<par>Return the first object produced by the iterator <arg>iterator</arg> or
 	<arg>default</arg> if the iterator didn't produce any items.</par>
 	<par>Calling this function will consume one item from the iterator.</par>
-	for node in iterator:
-		return node
-	return default
+	return item(iterator, 0, default)
-def last(iterator, default=None):
+def last(iterator, default=_defaultitem):
 	<par>Return the last object from the iterator <arg>iterator</arg> or
 	<arg>default</arg> if the iterator didn't produce any items.</par>
 	<par>Calling this function will exhaust the iterator.</par>
-	node = default
-	for node in iterator:
-		pass
-	return node
+	return item(iterator, -1, default)
 def count(iterator):


Old image
New image
-	version="2.6.1",
+	version="2.6.2",
 	description="An extensible HTML/XML generator",
 	author="Walter Doerwald",