[Python-modules-commits] [dominate] 09/15: Import dominate_2.3.1.orig.tar.gz

Ross Gammon ross-guest at moszumanska.debian.org
Thu Mar 16 18:33:05 UTC 2017


This is an automated email from the git hooks/post-receive script.

ross-guest pushed a commit to branch master
in repository dominate.

commit 3efb78e8d2125981dd5a0998d91ea1513e13ddfc
Author: Ross Gammon <rosco2 at ubuntu.com>
Date:   Thu Mar 16 16:57:25 2017 +0100

    Import dominate_2.3.1.orig.tar.gz
---
 .travis.yml             |  27 +++
 MANIFEST.in             |   4 +
 README.md               | 601 ++++++++++++++++++++++++++++++++----------------
 dominate/__init__.py    |   3 +-
 dominate/_version.py    |   2 +
 dominate/dom_tag.py     | 102 ++++----
 dominate/tags.py        |  26 +--
 dominate/util.py        |  48 ++--
 setup.py                |  34 ++-
 tests/old/__init__.py   |  25 --
 tests/old/attributes.py |  42 ----
 tests/old/rendering.py  |  61 -----
 tests/test_document.py  | 152 ++++++------
 tests/test_dom1core.py  |  32 +--
 tests/test_html.py      | 446 +++++++++++++++++++++++------------
 tests/test_utils.py     |  32 +++
 16 files changed, 987 insertions(+), 650 deletions(-)

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..b99802f
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,27 @@
+language: python
+
+python:
+  - "2.7"
+  - "3.3"
+  - "3.4"
+  - "3.5"
+  - "pypy"
+  - "pypy3"
+
+# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
+install:
+    - pip install pytest>=2.7.3 --upgrade
+
+# command to run tests, e.g. python setup.py test
+script:
+    - python setup.py sdist --format=zip
+    - pip install dist/dominate*.zip
+    - py.test
+
+after_success:
+    - pip install coveralls coverage
+    - PYTHONPATH=. coverage run --source=dominate -m pytest
+    - coverage report
+    - coveralls
+
+sudo: false
diff --git a/MANIFEST.in b/MANIFEST.in
index bb3ec5f..e9a430a 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1 +1,5 @@
 include README.md
+include LICENSE.txt
+recursive-include tests *
+global-exclude __pycache__
+global-exclude *.pyc
diff --git a/README.md b/README.md
index e86d7b1..3de3fbc 100644
--- a/README.md
+++ b/README.md
@@ -2,13 +2,73 @@ Dominate
 ========
 
 `Dominate` is a Python library for creating and manipulating HTML documents using an elegant DOM API.
-It allows you to write HTML pages in pure Python very concisely, which eliminate the need to learn another template language, and to take advantage of the more powerful features of Python.
+It allows you to write HTML pages in pure Python very concisely, which eliminates the need to learn another template language, and lets you take advantage of the more powerful features of Python.
+
+Python:
+
+```python
+import dominate
+from dominate.tags import *
+
+doc = dominate.document(title='Dominate your HTML')
+
+with doc.head:
+    link(rel='stylesheet', href='style.css')
+    script(type='text/javascript', src='script.js')
+
+with doc:
+    with div(id='header').add(ol()):
+        for i in ['home', 'about', 'contact']:
+            li(a(i.title(), href='/%s.html' % i))
+
+    with div():
+        attr(cls='body')
+        p('Lorem ipsum..')
+
+print(doc)
+```
+
+Output:
+
+```html
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>Dominate your HTML</title>
+    <link href="style.css" rel="stylesheet">
+    <script src="script.js" type="text/javascript"></script>
+  </head>
+  <body>
+    <div id="header">
+      <ol>
+        <li>
+          <a href="/home.html">Home</a>
+        </li>
+        <li>
+          <a href="/about.html">About</a>
+        </li>
+        <li>
+          <a href="/contact.html">Contact</a>
+        </li>
+      </ol>
+    </div>
+    <div class="body">
+      <p>Lorem ipsum..</p>
+    </div>
+  </body>
+</html>
+```
 
 
-Compatability
+Compatibility
 -------------
 
-`Dominate` is compatable with both Python 2.7 and Python 3.3. There are known issues with Python 3.2 and below.
+`Dominate` is compatible with both Python 2.7 and Python 3.3. There are known issues with Python 3.2 and below.
+
+[![Build Status](https://travis-ci.org/Knio/dominate.png?branch=master)](https://travis-ci.org/Knio/dominate)
+[![Coverage Status](https://coveralls.io/repos/Knio/dominate/badge.png?branch=master)](https://coveralls.io/r/Knio/dominate?branch=master)
+
+
 
 Installation
 ------------
@@ -18,6 +78,8 @@ The recommended way to install `dominate` is with
 
     sudo pip install dominate
 
+[![PyPI version](https://badge.fury.io/py/dominate.png)](http://badge.fury.io/py/dominate)
+
 
 Developed By
 ------------
@@ -33,7 +95,11 @@ Git repository located at
 Examples
 ========
 
-All examples assume you have imported the appropriate tags or entire tag set (i.e. `from dominate.tags import *`).
+All examples assume you have imported the appropriate tags or entire tag set:
+
+```python
+from dominate.tags import *
+```
 
 
 Hello, World!
@@ -43,40 +109,60 @@ The most basic feature of `dominate` exposes a class for each HTML element, wher
 accepts child elements, text, or keyword attributes. `dominate` nodes return their HTML representation
 from the `__str__`, `__unicode__`, and `render()` methods.
 
-    >>> print html(body(h1('Hello, World!')))
-    <html>
-      <body>
+```python
+print(html(body(h1('Hello, World!'))))
+```
+```html
+<html>
+    <body>
         <h1>Hello, World!</h1>
-      </body>
-    </html>
-
+    </body>
+</html>
+```
 
 Attributes
 ----------
 
 `Dominate` can also use keyword arguments to append attributes onto your tags. Most of the attributes are a direct copy from the HTML spec with a few variations.
 
-Use `cls` for class names and `fr` for `for` in label elements. `cls` and `fr` are used because `class` and `for` in python are [reserved keyword](http://docs.python.org/2/reference/lexical_analysis.html#keywords "Reserved Keywords").
+For attributes `class` and `for` which conflict with Python's [reserved keywords](http://docs.python.org/2/reference/lexical_analysis.html#keywords "Reserved Keywords"), you can use the following aliases:
+
+| class | for |
+|-------|-----|
+|_class | _for |
+|cls | fr |
+|className|htmlFor|
+|class_name|html_for|
 
-    >>> test = label(cls='classname anothername', fr='someinput')
-    >>> print test
-    <label class="classname anothername" for="someinput">
-    </label>
+
+```python
+test = label(cls='classname anothername', fr='someinput')
+print(test)
+```
+```html
+<label class="classname anothername" for="someinput"></label>
+```
 
 Use `data_*` for [custom HTML5 data attributes](http://www.w3.org/html/wg/drafts/html/master/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes "HTML5 Data Attributes").
 
-    >>> test = div(data_employee='101011')
-    >>> print test
-    <div data-employee="101011">
-    </div>
+```python
+test = div(data_employee='101011')
+print(test)
+```
+```html
+<div data-employee="101011"></div>
+```
 
 You can also modify the attributes of tags through a dictionary-like interface:
 
-    >>> header = div()
-    >>> header['id'] = 'header'
-    >>> print header
-    <div id="header"></div>
-
+```python
+header = div()
+header['id'] = 'header'
+print(header)
+```
+```html
+<div id="header"></div>
+```
 
 Complex Structures
 ------------------
@@ -85,85 +171,177 @@ Through the use of the `+=` operator and the `.add()` method you can easily crea
 
 Create a simple list:
 
-    >>> list = ul()
-    >>> for item in range(4):
-    ...   list += li('Item #', item)
-    ...
-    >>> print list
-    <ul>
-      <li>Item #0</li>
-      <li>Item #1</li>
-      <li>Item #2</li>
-      <li>Item #3</li>
-    </ul>
-
-If you are using a database or other backend to fetch data, `dominate` supports iterables to help streamline your code:
-
-    >>> print ul(li(a(name, href=link), __inline=True) for name, link in menu_items)
-    <ul>
-      <li><a href="/home/">Home</a></li>
-      <li><a href="/about/">About</a></li>
-      <li><a href="/downloads/">Downloads</a></li>
-      <li><a href="/links/">Links</a></li>
-    </ul>
+```python
+list = ul()
+for item in range(4):
+    list += li('Item #', item)
+print(list)
+```
+```html
+<ul>
+    <li>Item #0</li>
+    <li>Item #1</li>
+    <li>Item #2</li>
+    <li>Item #3</li>
+</ul>
+```
+
+`dominate` supports iterables to help streamline your code:
+
+```python
+print(ul(li(a(name, href=link), __pretty=False) for name, link in menu_items))
+```
+```html
+<ul>
+    <li><a href="/home/">Home</a></li>
+    <li><a href="/about/">About</a></li>
+    <li><a href="/downloads/">Downloads</a></li>
+    <li><a href="/links/">Links</a></li>
+</ul>
+```
 
 A simple document tree:
 
-    >>> _html = html()
-    >>> _body = _html.add(body())
-    >>> header  = _body.add(div(id='header'))
-    >>> content = _body.add(div(id='content'))
-    >>> footer  = _body.add(div(id='footer'))
-    >>> print _html
-    <html>
-      <body>
+```python
+_html = html()
+_body = _html.add(body())
+header  = _body.add(div(id='header'))
+content = _body.add(div(id='content'))
+footer  = _body.add(div(id='footer'))
+print(_html)
+```
+```html
+<html>
+    <body>
         <div id="header"></div>
         <div id="content"></div>
         <div id="footer"></div>
-      </body>
-    </html>
+    </body>
+</html>
+```
 
 For clean code, the `.add()` method returns children in tuples. The above example can be cleaned up and expanded like this:
 
-    >>> _html = html()
-    >>> _head, _body = _html.add(head(title('Simple Document Tree')), body())
-    >>> names = ['header', 'content', 'footer']
-    >>> header, content, footer = _body.add(div(id=name) for name in names)
-    >>> print _html
-    <html>
-      <head>
-        <title>Simple Document Tree</title>
-      </head>
-      <body>
+```python
+_html = html()
+_head, _body = _html.add(head(title('Simple Document Tree')), body())
+names = ['header', 'content', 'footer']
+header, content, footer = _body.add(div(id=name) for name in names)
+print(_html)
+```
+```html
+<html>
+    <head>
+       <title>Simple Document Tree</title>
+    </head>
+    <body>
         <div id="header"></div>
         <div id="content"></div>
         <div id="footer"></div>
-      </body>
-    </html>
+    </body>
+</html>
+```
 
 You can modify the attributes of tags through a dictionary-like interface:
 
-    >>> header = div()
-    >>> header['id'] = 'header'
-    >>> print header
-    <div id="header"></div>
+```python
+header = div()
+header['id'] = 'header'
+print(header)
+```
+```html
+<div id="header"></div>
+```
 
 Or the children of a tag though an array-line interface:
 
-    >>> header = div('Test')
-    >>> header[0] = 'Hello World'
-    >>> print header
-    <div>Hello World</div>
-
+```python
+header = div('Test')
+header[0] = 'Hello World'
+print(header)
+```
+```html
+<div>Hello World</div>
+```
 
 Comments can be created using objects too!
 
-    >>> print comment('BEGIN HEADER')
-    <!--BEGIN HEADER-->
-    >>> print comment(p('Upgrade to newer IE!'), condition='lt IE9')
-    <!--[if lt IE9]>
-    <p>Upgrade to newer IE!</p>
-    <![endif]-->
+```python
+print(comment('BEGIN HEADER'))
+```
+```html
+<!--BEGIN HEADER-->
+```
+
+```python
+print(comment(p('Upgrade to newer IE!'), condition='lt IE9'))
+```
+```html
+<!--[if lt IE9]>
+  <p>Upgrade to newer IE!</p>
+<![endif]-->
+```
+
+Rendering
+---------
+
+By default, `render()` tries to make all output human readable, with one HTML
+element per line and two spaces of indentation.
+
+This behavior can be controlled by the `__pretty` (default: `True` except for
+certain element types like `pre`) attribute when creating an element, and by
+the `pretty` (default: `True`), `indent` (default: `  `) and `xhtml` (default: `False`)
+ arguments to `render()`. Rendering options propagate to all descendant nodes.
+
+```python
+a = div(span('Hello World'))
+print(a.render())
+```
+```html
+<div>
+  <span>Hello World</span>
+</div>
+```
+```python
+print(a.render(pretty=False))
+```
+```html
+<div><span>Hello World</span></div>
+```
+```python
+print(a.render(indent='\t'))
+```
+```html
+<div>
+	<span>Hello World</span>
+</div>
+```
+```python
+a = div(span('Hello World'), __pretty=False)
+print(a.render())
+```
+```html
+<div><span>Hello World</span></div>
+```
+```python
+d = div()
+with d:
+    hr()
+    p("Test")
+    br()
+print(d.render())
+print(d.render(xhtml=True))
+```
+```html
+<div>
+  <hr>
+  <p>Test</p><br>
+</div>
+<div>
+  <hr />
+  <p>Test</p><br />
+</div>
+```
 
 
 Context Managers
@@ -171,66 +349,74 @@ Context Managers
 
 You can also add child elements using Python's `with` statement:
 
-    >>> h = ul()
-    >>> with h:
-    ...   li('One')
-    ...   li('Two')
-    ...   li('Three')
-    ...
-    >>>
-    >>> print h
-    <ul>
-      <li>One</li>
-      <li>Two</li>
-      <li>Three</li>
-    </ul>
+```python
+h = ul()
+with h:
+    li('One')
+    li('Two')
+    li('Three')
+
+print(h)
+```
+```html
+<ul>
+    <li>One</li>
+    <li>Two</li>
+    <li>Three</li>
+</ul>
+```
 
 
 You can use this along with the other mechanisms of adding children elements, including nesting `with` statements, and it works as expected:
 
-    >>> h = html()
-    >>> with h.add(body()).add(div(id='content')):
-    ...   h1('Hello World!')
-    ...   p('Lorem ipsum ...')
-    ...   with table().add(tbody()):
-    ...     l = tr()
-    ...     l += td('One')
-    ...     l.add(td('Two'))
-    ...     with l:
-    ...       td('Three')
-    ...
-    >>>
-    >>> print h
-    <html>
-      <body>
+```python
+h = html()
+with h.add(body()).add(div(id='content')):
+    h1('Hello World!')
+    p('Lorem ipsum ...')
+    with table().add(tbody()):
+        l = tr()
+        l += td('One')
+        l.add(td('Two'))
+        with l:
+            td('Three')
+
+print(h)
+```
+```html
+<html>
+    <body>
         <div id="content">
-          <h1>Hello World!</h1>
-          <p>Lorem ipsum ...</p>
-          <table>
-            <tbody>
-              <tr>
-                <td>One</td>
-                <td>Two</td>
-                <td>Three</td>
-              </tr>
-            </tbody>
-          </table>
+            <h1>Hello World!</h1>
+            <p>Lorem ipsum ...</p>
+            <table>
+                <tbody>
+                    <tr>
+                        <td>One</td>
+                        <td>Two</td>
+                        <td>Three</td>
+                    </tr>
+                </tbody>
+            </table>
         </div>
-      </body>
-    </html>
-
+    </body>
+</html>
+```
 
 When the context is closed, any nodes that were not already added to something get added to the current context.
 
 Attributes can be added to the current context with the `attr` function:
 
-    >>> d = div()
-    >>> with d:
-    ...   attr(id='header')
-    ...
-    >>>
-    >>> print d
-    <div id="header"></div>
+```python
+d = div()
+with d:
+    attr(id='header')
+
+ print(d)
+ ```
+ ```html
+<div id="header"></div>
+```
 
 
 Decorators
@@ -238,104 +424,123 @@ Decorators
 
 `Dominate` is great for creating reusable widgets for parts of your page. Consider this example:
 
-    >>> def greeting(name):
-    ...     with div() as d:
-    ...         p('Hello, %s' % name)
-    ...     return d
-    ...
-    ...
-    >>> print greeting('Bob')
-    <div>
-      <p>Hello, Bob</p>
-    </div>
-    >>>
+```python
+def greeting(name):
+    with div() as d:
+        p('Hello, %s' % name)
+    return d
+
+print(greeting('Bob'))
+```
+```html
+<div>
+    <p>Hello, Bob</p>
+</div>
+```
 
 You can see the following pattern being repeated here:
 
-    def widget(parameters):
-      with tag() as t:
-          ...
-      return t
+```python
+def widget(parameters):
+    with tag() as t:
+        ...
+    return t
+```
 
 This boilerplate can be avoided by using tags (objects and instances) as decorators
 
-    >>> @div
-    ... def greeting(name):
-    ...     p('Hello %s' % name)
-    ...
-    ...
-    >>> print greeting('Bob')
-    <div>
-      <p>Hello Bob</p>
-    </div>
-    >>>
+```python
+ at div
+def greeting(name):
+    p('Hello %s' % name)
+print(greeting('Bob'))
+```
+```html
+<div>
+    <p>Hello Bob</p>
+</div>
+```
 
 The decorated function will return a new instance of the tag used to decorate it, and execute in a `with` context which will collect all the nodes created inside it.
 
 You can also use instances of tags as decorators, if you need to add attributes or other data to the root node of the widget.
 Each call to the decorated function will return a copy of the node used to decorate it.
 
-    >>> @div(h2('Welcome'), cls='greeting')
-    ... def greeting(name):
-    ...     p('Hello %s' % name)
-    ...
-    ...
-    >>> print greeting('Bob')
-    <div class="greeting">
-      <h2>Welcome</h2>
-      <p>Hello Bob</p>
-    </div>
-    >>>
+```python
+ at div(h2('Welcome'), cls='greeting')
+def greeting(name):
+    p('Hello %s' % name)
 
+print(greeting('Bob'))
+```
+```html
 
+<div class="greeting">
+    <h2>Welcome</h2>
+    <p>Hello Bob</p>
+</div>
+```
 
 Creating Documents
 ------------------
 
-Since creating the common structure of an HTML document everytime would be excessively tedious dominate provides a class to create an manage them for you, `document`.
+Since creating the common structure of an HTML document everytime would be excessively tedious dominate provides a class to create and manage them for you: `document`.
 
 When you create a new document, the basic HTML tag structure is created for you.
 
-    >>> d = document()
-    >>> print d
-    <!DOCTYPE html>
-    <html>
-      <head>
-        <title>Dominate</title>
-      </head>
-      <body></body>
-    </html>
+```python
+d = document()
+print(d)
+```
+```html
+<!DOCTYPE html>
+<html>
+    <head>
+       <title>Dominate</title>
+    </head>
+    <body></body>
+</html>
+```
 
 The `document` class accepts `title`, `doctype`, and `request` keyword arguments.
 The default values for these arguments are `Dominate`, `<!DOCTYPE html>`, and `None` respectively.
 
 The `document` class also provides helpers to allow you to access the `html`, `head`, and `body` nodes directly.
 
-    >>> d = document()
-    >>> d.html
-    <dominate.tags.html: 0 attributes, 2 children>
-    >>> d.head
-    <dominate.tags.head: 0 attributes, 0 children>
-    >>> d.body
-    <dominate.tags.body: 0 attributes, 0 children>
+```python
+d = document()
+```
+
+```python
+>>> d.html
+<dominate.tags.html: 0 attributes, 2 children>
+>>> d.head
+<dominate.tags.head: 0 attributes, 0 children>
+>>> d.body
+<dominate.tags.body: 0 attributes, 0 children>
+```
+
 
 You should notice that here the `head` tag contains zero children.
-This is because the default `title` tag is only added when the document is rendered and the `head` element already does not explicitly contain one.
+This is because the default `title` tag is only added when the document is rendered and the `head` element does not explicitly contain one.
 
 The `document` class also provides helpers to allow you to directly add nodes to the `body` tag.
 
-    >>> d = document()
-    >>> d += h1('Hello, World!')
-    >>> d += p('This is a paragraph.')
-    >>> print d
-    <!DOCTYPE html>
-    <html>
-      <head>
-        <title>Dominate</title>
-      </head>
-      <body>
+```python
+d = document()
+d += h1('Hello, World!')
+d += p('This is a paragraph.')
+print(d)
+```
+```html
+<!DOCTYPE html>
+<html>
+    <head>
+       <title>Dominate</title>
+    </head>
+    <body>
         <h1>Hello, World!</h1>
         <p>This is a paragraph.</p>
-      </body>
-    </html>
-
+    </body>
+</html>
+```
diff --git a/dominate/__init__.py b/dominate/__init__.py
index d32fd3e..50668cb 100644
--- a/dominate/__init__.py
+++ b/dominate/__init__.py
@@ -1,3 +1,4 @@
-version = __version__ = '2.1.5'
+from ._version import __version__
+version = __version__
 
 from .document import document
diff --git a/dominate/_version.py b/dominate/_version.py
new file mode 100644
index 0000000..74a4100
--- /dev/null
+++ b/dominate/_version.py
@@ -0,0 +1,2 @@
+__version__ = '2.3.1'
+
diff --git a/dominate/dom_tag.py b/dominate/dom_tag.py
index f3be8b7..8ef1014 100644
--- a/dominate/dom_tag.py
+++ b/dominate/dom_tag.py
@@ -16,6 +16,8 @@ Public License along with Dominate.  If not, see
 <http://www.gnu.org/licenses/>.
 '''
 
+# pylint: disable=bad-indentation, bad-whitespace, missing-docstring
+
 import copy
 import numbers
 from collections import defaultdict, namedtuple, Callable
@@ -28,23 +30,25 @@ except NameError: # py3
   basestring = str
   unicode = str
 
+
+try:
+  import greenlet
+except ImportError:
+  greenlet = None
+
 def _get_thread_context():
   context = [threading.current_thread()]
-  try:
-    import greenlet
+  if greenlet:
     context.append(greenlet.getcurrent())
-  except:
-    pass
   return hash(tuple(context))
 
 
 class dom_tag(object):
-  TAB = '  '  # TODO make this a parameter to render(), and a tag.
-
   is_single = False  # Tag does not require matching end tag (ex. <hr/>)
   is_pretty = True   # Text inside the tag should be left as-is (ex. <pre>)
                      # otherwise, text will be escaped() and whitespace may be
                      # modified
+  is_inline = False
 
   frame = namedtuple('frame', ['tag', 'items', 'used'])
 
@@ -81,7 +85,8 @@ class dom_tag(object):
     self.document   = None
 
     # Does not insert newlines on all children if True (recursive attribute)
-    self.do_inline = kwargs.pop('__inline', False)
+    self.is_inline = kwargs.pop('__inline', self.is_inline)
+    self.is_pretty = kwargs.pop('__pretty', self.is_pretty)
 
     #Add child elements
     if args:
@@ -124,7 +129,6 @@ class dom_tag(object):
     # remove decorator from its context so it doesn't
     # get added in where it was defined
     if self._ctx:
-      assert False, self._ctx
       self._ctx.used.add(self)
 
     @wraps(func)
@@ -148,6 +152,13 @@ class dom_tag(object):
           'child tags and attributes, respectively.')
   __setitem__ = set_attribute
 
+  def delete_attribute(self, key):
+    if isinstance(key, int):
+      del self.children[key:key+1]
+    else:
+      del self.attributes[key]
+  __delitem__ = delete_attribute
+
   def setdocument(self, doc):
     '''
     Creates a reference to the parent document to allow for partial-tree
@@ -170,8 +181,7 @@ class dom_tag(object):
         obj = str(obj)
 
       if isinstance(obj, basestring):
-        if self.is_pretty:
-          obj = escape(obj)
+        obj = escape(obj)
         self.children.append(obj)
 
       elif isinstance(obj, dom_tag):
@@ -291,16 +301,17 @@ class dom_tag(object):
     self.add(obj)
     return self
 
-  def render(self, indent=1, inline=False):
-    data = self._render([], indent, inline)
+  # String and unicode representations are the same as render()
+  def __unicode__(self):
+    return self.render()
+  __str__ = __unicode__
+
+  def render(self, indent='  ', pretty=True, xhtml=False):
+    data = self._render([], 0, indent, pretty, xhtml)
     return u''.join(data)
 
-  def _render(self, rendered, indent=1, inline=False):
-    '''
-    Returns a well-formatted string representation of the tag and renderings
-    of all its child tags.
-    '''
-    inline = self.do_inline or inline
+  def _render(self, sb, indent_level, indent_str, pretty, xhtml):
+    pretty = pretty and self.is_pretty
 
     t = type(self)
     name = getattr(t, 'tagname', t.__name__)
@@ -310,45 +321,42 @@ class dom_tag(object):
     if name[-1] == '_':
       name = name[:-1]
 
-    rendered.extend(['<', name])
+    # open tag
+    sb.append('<')
+    sb.append(name)
 
     for attribute, value in sorted(self.attributes.items()):
-      rendered.append(' %s="%s"' % (attribute, escape(unicode(value), True)))
+      sb.append(' %s="%s"' % (attribute, escape(unicode(value), True)))
 
-    rendered.append('>')
+    sb.append(' />' if self.is_single and xhtml else '>')
 
     if not self.is_single:
-      self._render_children(rendered, indent, inline)
-
-      # if there are no children, or only 1 child that is not an html element,
-      # do not add tabs and newlines
-      no_children = self.is_pretty and self.children and \
-          (not (len(self.children) == 1 and not isinstance(self[0], dom_tag)))
+      inline = self._render_children(sb, indent_level + 1, indent_str, pretty, xhtml)
 
-      if no_children and not inline:
-        rendered.append('\n')
-        rendered.append(dom_tag.TAB * (indent - 1))
+      if pretty and not inline:
+        sb.append('\n')
+        sb.append(indent_str * indent_level)
 
-      rendered.append('</')
-      rendered.append(name)
-      rendered.append('>')
+      # close tag
+      sb.append('</')
+      sb.append(name)
+      sb.append('>')
 
-    return rendered
+    return sb
 
-  # String and unicode representations are the same as render()
-  def __unicode__(self):
-    return self.render()
-  __str__ = __unicode__
-
-  def _render_children(self, rendered, indent=1, inline=False):
+  def _render_children(self, sb, indent_level, indent_str, pretty, xhtml):
+    inline = True
     for child in self.children:
       if isinstance(child, dom_tag):
-        if not inline and self.is_pretty:
-          rendered.append('\n')
-          rendered.append(dom_tag.TAB * indent)
-        child._render(rendered, indent + 1, inline)
+        if pretty and not child.is_inline:
+          inline = False
+          sb.append('\n')
+          sb.append(indent_str * indent_level)
+        child._render(sb, indent_level, indent_str, pretty, xhtml)
       else:
-        rendered.append(unicode(child))
+        sb.append(unicode(child))
+
+    return inline
... 1079 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/dominate.git



More information about the Python-modules-commits mailing list