[py-svn] r8470 - in py/dist/py: documentation documentation/example xmlobj xmlobj/testing
hpk at codespeak.net
hpk at codespeak.net
Sat Jan 22 17:02:20 CET 2005
Author: hpk
Date: Sat Jan 22 17:02:20 2005
New Revision: 8470
Modified:
py/dist/py/documentation/example/genhtmlcss.py
py/dist/py/documentation/example/genxml.py
py/dist/py/documentation/xml.txt
py/dist/py/xmlobj/html.py
py/dist/py/xmlobj/testing/test_html.py
py/dist/py/xmlobj/testing/test_xml.py
py/dist/py/xmlobj/xml.py
Log:
changed the mechanics of the basic py.xml.Namespace
slightly and adjusted the documentation and examples
accordingly.
Modified: py/dist/py/documentation/example/genhtmlcss.py
==============================================================================
--- py/dist/py/documentation/example/genhtmlcss.py (original)
+++ py/dist/py/documentation/example/genhtmlcss.py Sat Jan 22 17:02:20 2005
@@ -1,9 +1,9 @@
import py
html = py.xml.html
-class my:
+class my(html):
"a custom style"
- class body(html.body):
+ class body(html.body):
style = html.Style(font_size = "120%")
class h2(html.h2):
@@ -12,8 +12,8 @@
class p(html.p):
style = html.Style(font_weight="bold")
-doc = html.html(
- html.head(),
+doc = my.html(
+ my.head(),
my.body(
my.h2("hello world"),
my.p("bold as bold can")
Modified: py/dist/py/documentation/example/genxml.py
==============================================================================
--- py/dist/py/documentation/example/genxml.py (original)
+++ py/dist/py/documentation/example/genxml.py Sat Jan 22 17:02:20 2005
@@ -1,6 +1,8 @@
import py
-ns = py.xml.Namespace()
+class ns(py.xml.Namespace):
+ pass
+
doc = ns.books(
ns.book(
ns.author("May Day"),
Modified: py/dist/py/documentation/xml.txt
==============================================================================
--- py/dist/py/documentation/xml.txt (original)
+++ py/dist/py/documentation/xml.txt Sat Jan 22 17:02:20 2005
@@ -1,6 +1,6 @@
-=====================================================
-py.xml: Lightweight and powerfull xml/html generation
-=====================================================
+====================================================
+py.xml: Lightweight and flexible xml/html generation
+====================================================
.. contents::
.. sectnum::
@@ -34,10 +34,11 @@
generating arbitrary xml structures
-----------------------------------
-With ``py.xml.Namespace()`` you have everything
+With ``py.xml.Namespace`` you have the basis
to generate custom xml-fragments on the fly::
- ns = py.xml.Namespace()
+ class ns(py.xml.Namespace):
+ "my custom xml namespace"
doc = ns.books(
ns.book(
ns.author("May Day"),
@@ -73,17 +74,17 @@
Consider this example::
- from py.xml import html
+ from py.xml import html # html namespace
- paras = "First Para", "Second para"
+ paras = "First Para", "Second para"
- doc = html.html(
+ doc = html.html(
html.head(
- html.meta(name="Content-Type", value="text/html; charset=utf8))
+ html.meta(name="Content-Type", value="text/html; charset=latin1")),
html.body(
[html.p(p) for p in paras]))
- print unicode(doc).encode('latin1')
+ print unicode(doc).encode('latin1')
Again, tags are objects which contain tags and have attributes.
More exactly, Tags inherit from the list type and thus can be
@@ -94,7 +95,6 @@
note that the tag/namespace implementation consumes some 50 lines
with another 50 lines for the unicode serialization code.
-
CSS-styling your html Tags
--------------------------
@@ -112,7 +112,7 @@
By contrast, consider this CSS styling example::
- class my:
+ class my(html):
"my initial custom style"
class body(html.body):
style = html.Style(font_size = "120%")
@@ -123,8 +123,8 @@
class p(html.p):
style = html.Style(font_weight="bold")
- doc = html.html(
- html.head(),
+ doc = my.html(
+ my.head(),
my.body(
my.h2("hello world"),
my.p("bold as bold can")
Modified: py/dist/py/xmlobj/html.py
==============================================================================
--- py/dist/py/xmlobj/html.py (original)
+++ py/dist/py/xmlobj/html.py Sat Jan 22 17:02:20 2005
@@ -5,7 +5,8 @@
from py.xml import Namespace
# exported plain html namespace
-class Html(Namespace):
+class html(Namespace):
+ __stickyname__ = True
__tagspec__ = dict([(x,1) for x in (
"h1,h2,h3,h5,h6,p,b,i,a,div,span,code,"
"html,head,title,style,table,tr,tt,"
@@ -19,4 +20,3 @@
x = x.replace('_', '-')
setattr(self, x, y)
-html = Html(stickyname=True)
Modified: py/dist/py/xmlobj/testing/test_html.py
==============================================================================
--- py/dist/py/xmlobj/testing/test_html.py (original)
+++ py/dist/py/xmlobj/testing/test_html.py Sat Jan 22 17:02:20 2005
@@ -18,14 +18,14 @@
html.Style(background="white"),
html.Style(background="grey"),
)
- class my:
+ class my(html):
class li(html.li):
def style(self):
i = self.parent.index(self)
return alternating[i%2]
style = property(style)
- x = html.ul(
+ x = my.ul(
my.li("hello"),
my.li("world"),
my.li("42"))
Modified: py/dist/py/xmlobj/testing/test_xml.py
==============================================================================
--- py/dist/py/xmlobj/testing/test_xml.py (original)
+++ py/dist/py/xmlobj/testing/test_xml.py Sat Jan 22 17:02:20 2005
@@ -1,7 +1,8 @@
import py
-ns = py.xml.Namespace()
+class ns(py.xml.Namespace):
+ pass
def test_tag_with_text():
x = ns.hello("world")
Modified: py/dist/py/xmlobj/xml.py
==============================================================================
--- py/dist/py/xmlobj/xml.py (original)
+++ py/dist/py/xmlobj/xml.py Sat Jan 22 17:02:20 2005
@@ -33,15 +33,12 @@
# provides Tag classes on the fly optionally checking for
# a tagspecification
-class Namespace(object):
- __tagspec__ = None
- def __init__(self, tagclass=Tag, stickyname=False):
- self.__tagclass__ = tagclass
- self.__stickyname__ = stickyname
-
- def __getattr__(self, name):
+class NamespaceMetaclass(type):
+ def __getattr__(self, name):
if name[:1] == '_':
raise AttributeError(name)
+ if self == Namespace:
+ raise ValueError("Namespace class is abstract")
tagspec = self.__tagspec__
if tagspec is not None and name not in tagspec:
raise AttributeError(name)
@@ -51,3 +48,10 @@
cls = type(name, (self.__tagclass__,), classattr)
setattr(self, name, cls)
return cls
+
+class Namespace(object):
+ __tagspec__ = None
+ __tagclass__ = Tag
+ __metaclass__ = NamespaceMetaclass
+ __stickyname__ = False
+
More information about the pytest-commit
mailing list