changeset 880:62a67c72ca60

Merged newest htmlmarkup.py changes from upstream (trac).
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Sat, 01 Jul 2006 15:39:59 +0200
parents 49d164e275f3
children 21095ba16b58 c3694976f155 f16cf67d3440
files MoinMoin/support/htmlmarkup.py
diffstat 1 files changed, 35 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/support/htmlmarkup.py	Fri Jun 30 23:16:45 2006 +0200
+++ b/MoinMoin/support/htmlmarkup.py	Sat Jul 01 15:39:59 2006 +0200
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# copied from trac.util.markup, version 2006-04-10
+# copied from trac.util.markup, revision 3446, merged on 2006-06-30
 #
 # Copyright (C) 2003-2006 Edgewall Software
 # All rights reserved.
@@ -103,7 +103,7 @@
         as is. Escaping quotes is generally only required for strings that are
         to be used in attribute values.
         """
-        if isinstance(text, cls):
+        if isinstance(text, (cls, Element)):
             return text
         text = unicode(text)
         if not text:
@@ -192,7 +192,7 @@
         'td', 'textarea', 'tfoot', 'th', 'thead', 'tr', 'tt', 'u', 'ul',
         'var'])
     safe_attrs = frozenset(['abbr', 'accept', 'accept-charset',
-        'accesskey', 'action', 'align', 'alt', 'axis', 'border',
+        'accesskey', 'action', 'align', 'alt', 'axis', 'border', 'bgcolor',
         'cellpadding', 'cellspacing', 'char', 'charoff', 'charset',
         'checked', 'cite', 'class', 'clear', 'cols', 'colspan', 'color',
         'compact', 'coords', 'datetime', 'dir', 'disabled', 'enctype',
@@ -305,14 +305,9 @@
             except TypeError:
                 self.children.append(node)
 
-    def __getitem__(self, nodes):
-        """Add child nodes to the element."""
-        if not isinstance(nodes, (basestring, Fragment)):
-            try:
-                nodes = iter(nodes)
-            except TypeError:
-                nodes = [str(nodes)]
-        self.append(nodes)
+    def __call__(self, *args):
+        for arg in args:
+            self.append(arg)
         return self
 
     def serialize(self):
@@ -327,77 +322,78 @@
         return Markup(''.join(self.serialize()))
 
     def __add__(self, other):
-        return Fragment()[self, other]
+        return Fragment()(self, other)
 
 
 class Element(Fragment):
     """Simple XHTML output generator based on the builder pattern.
-
+    
     Construct XHTML elements by passing the tag name to the constructor:
-
+    
     >>> print Element('strong')
     <strong></strong>
-
+    
     Attributes can be specified using keyword arguments. The values of the
     arguments will be converted to strings and any special XML characters
     escaped:
-
+    
     >>> print Element('textarea', rows=10, cols=60)
     <textarea rows="10" cols="60"></textarea>
     >>> print Element('span', title='1 < 2')
     <span title="1 &lt; 2"></span>
     >>> print Element('span', title='"baz"')
     <span title="&#34;baz&#34;"></span>
-
+    
     The " character is escaped using a numerical entity.
     The order in which attributes are rendered is undefined.
-
+    
     If an attribute value evaluates to `None`, that attribute is not included
     in the output:
-
+    
     >>> print Element('a', name=None)
     <a></a>
-
+    
     Attribute names that conflict with Python keywords can be specified by
     appending an underscore:
-
+    
     >>> print Element('div', class_='warning')
     <div class="warning"></div>
-
+    
     While the tag names and attributes are not restricted to the XHTML language,
     some HTML characteristics such as boolean (minimized) attributes and empty
     elements get special treatment.
-
+    
     For compatibility with HTML user agents, some XHTML elements need to be
     closed using a separate closing tag even if they are empty. For this, the
     close tag is only ommitted for a small set of elements which are known be
     be safe for use as empty elements:
-
+    
     >>> print Element('br')
     <br />
-
+    
     Trying to add nested elements to such an element will cause an
     `AssertionError`:
     
-    >>> Element('br')['Oops']
+    >>> Element('br')('Oops')
     Traceback (most recent call last):
         ...
     AssertionError: 'br' elements must not have content
-
+    
     Furthermore, boolean attributes such as "selected" or "checked" are omitted
     if the value evaluates to `False`. Otherwise, the name of the attribute is
     used for the value:
-
+    
     >>> print Element('option', value=0, selected=False)
     <option value="0"></option>
     >>> print Element('option', selected='yeah')
     <option selected="selected"></option>
-
-    Nested elements can be added to an element using item access notation.
-    The call notation can also be used for this and for adding attributes
-    using keyword arguments, as one would do in the constructor.
-
-    >>> print Element('ul')[Element('li'), Element('li')]
+    
+    
+    Nested elements can be added to an element by calling the instance using
+    positional arguments. The same technique can also be used for adding
+    attributes using keyword arguments, as one would do in the constructor:
+    
+    >>> print Element('ul')(Element('li'), Element('li'))
     <ul><li></li><li></li></ul>
     >>> print Element('a')('Label')
     <a>Label</a>
@@ -407,16 +403,16 @@
     Text nodes can be nested in an element by adding strings instead of
     elements. Any special characters in the strings are escaped automatically:
 
-    >>> print Element('em')['Hello world']
+    >>> print Element('em')('Hello world')
     <em>Hello world</em>
-    >>> print Element('em')[42]
+    >>> print Element('em')(42)
     <em>42</em>
-    >>> print Element('em')['1 < 2']
+    >>> print Element('em')('1 < 2')
     <em>1 &lt; 2</em>
 
     This technique also allows mixed content:
 
-    >>> print Element('p')['Hello ', Element('b')['world']]
+    >>> print Element('p')('Hello ', Element('b')('world'))
     <p>Hello <b>world</b></p>
 
     Elements can also be combined with other elements or strings using the
@@ -436,10 +432,8 @@
         self(**attr)
 
     def __call__(self, *args, **attr):
-        for arg in args:
-            self.append(arg)
         self.attr.update(attr)
-        return self
+        return Fragment.__call__(self, *args)
 
     def append(self, node):
         """Append an element or string as child node."""