changeset 509:1997f7af845c

Add a test for buffer reset by copy().
author athomas
date Wed, 06 Jun 2007 10:07:47 +0000
parents cabd80e75dad
children ca7d707d51b0
files genshi/filters/transform.py
diffstat 1 files changed, 19 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/genshi/filters/transform.py
+++ b/genshi/filters/transform.py
@@ -419,10 +419,25 @@
         >>> buffer = StreamBuffer()
         >>> html = HTML('<html><head><title>Some Title</title></head>'
         ...             '<body>Some <em>body</em> text.</body></html>')
-        >>> print html | Transformer('.//title/text()').copy(buffer) \\
-        ...     .select('.//body').prepend(tag.h1(buffer))
-        <html><head><title>Some Title</title></head><body><h1>Some Title</h1>Some
-        <em>body</em> text.</body></html>
+        >>> print html | Transformer('title/text()').copy(buffer) \\
+        ...     .select('body').prepend(tag.h1(buffer))
+        <html><head><title>Some Title</title></head><body><h1>Some
+        Title</h1>Some <em>body</em> text.</body></html>
+
+        To ensure that a transformation can be reused deterministically, the
+        contents of ``buffer`` is replaced by the ``copy()`` operation:
+
+        >>> print buffer
+        Some Title
+        >>> print html | Transformer('head/title/text()').copy(buffer) \\
+        ...     .select('body/em').copy(buffer).select('body') \\
+        ...     .prepend(tag.h1(buffer))
+        <html><head><title>Some
+        Title</title></head><body><h1><em>body</em></h1>Some <em>body</em>
+        text.</body></html>
+        >>> print buffer
+        <em>body</em>
+
 
         :param buffer: the `StreamBuffer` in which the selection should be
                        stored
Copyright (C) 2012-2017 Edgewall Software