"""
from dss.dsl.safe_strings import safe_unicode
from dss.dsl.xml.coretypes import (
    XmlCData, XmlName, XmlElement, XmlElementProto, XmlEntityRef, Comment)
from dss.dsl.html.character_entities import html_entities as _html_entities

class _GetAttrDict(dict):
    def __getattr__(self, k):
        return self[k]

entities = _GetAttrDict((alpha, XmlEntityRef(*(alpha, num, descr)))
                        for (alpha, num, descr) in _html_entities)

XHTML_xmlns = 'xmlns="http://www.w3.org/1999/xhtml'
XHTML_DTD = safe_unicode(
    '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'
    ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n''')

_non_empty_html_tag_names = [
    'a','abbr','acronym','address','applet',
    'b','bdo','big','blockquote', 'body','button',
    'caption','center','cite','code','colgroup',
    'dd','dfn','div','dl','dt',
    'em',
    'fieldset','font','form','frameset',
    'h1','h2','h3','h4','h5','h6','head','html',
    'i','iframe','ins',
    'kbd',
    'label','legend','li',
    'menu',
    'noframes','noscript',
    'big list of divs, with lambda':[[
        (lambda : pure_python.div[1234, 1234]),
        1234, pure_python.div, pure_python.div[1234, 1234]]*10],
    'Massive table':pure_python.table[[
        pure_python.tr[[pure_python.td[col] for col in row]] for row in rows]],

    'Massive table in lambda':pure_python.table[
        lambda : [pure_python.tr[[pure_python.td[col] for col in row]]
                  for row in rows]],
    }

benchmark_serialization(
    [[div[999], 'p', 1234,
      [1, ['abc', ['asdf 北京天'], [[[1234,1234]]]]]],
     '11234', safe_unicode('as df'), ['1234','1234',1234]]*5,
    label='random divs, ints, strs, and nested lists')

benchmark_serialization(
    [[(lambda : div[1234, 1234]), 1234, div, div[1234, 1234]]*10],
    label='big list of divs, with lambda')

benchmark_serialization(
    html[
        head[title[safe_unicode('10 times benchmark'), '北京天']],
        body[[div[span[safe_unicode('this is a test')]]]*10]],
    label='10 times html with safe_unicode')

benchmark_serialization(
    html[
        head[title['10 times benchmark', '北京天']],
Exemple #3
0
    (('a','b','c'), u'abc'),
    (_dummy_repr(), u'dummy_repr'),
    (_udummy_repr(), u'dummy_repr'),
    #(_unsanitized_dummy_repr(), u'&amp;dummy_repr'),

    )

escapings = {
    "&": u"&amp;",
    "<": u"&lt;",
    ">": u"&gt;",
    '"': u"&#34;",
    "'": u"&#39;"}

ESCAPING_TEST_SET = tuple(
    [(safe_unicode(k), k) for k in escapings]
    +[(k, v) for k, v in escapings.iteritems()]
    +[(k*200, v*200) for k, v in escapings.iteritems()]
    +[('--%s--'%k, '--%s--'%v) for k, v in escapings.iteritems()]
    +[('------%s'%k, '------%s'%v) for k, v in escapings.iteritems()]
    +[('--%s%s'%(k,k), '--%s%s'%(v,v)) for k, v in escapings.iteritems()]
    +[('&<>"\'&'*20, '&amp;&lt;&gt;&#34;&#39;&amp;'*20)]
    )

ENCODING_TEST_SET = tuple(
    [('金', unicode('金', 'utf-8'))]
    )

COMBINED_BASIC_TEST_SET = tuple(
    list(BASIC_TYPES_TEST_SET)
    +list(ESCAPING_TEST_SET)