Commit b2be2522 authored by Andreas Jung's avatar Andreas Jung

cleanup

parent 4f9fc7ba
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
######################################################################
# Sequence batching support
import util
__allow_access_to_unprotected_subobjects__={'batch': 1}
__roles__=None
class batch(util.Base):
"""Create a sequence batch"""
def __init__(self, sequence, size, start=0, end=0,
orphan=3, overlap=0):
start=start+1
start,end,sz=opt(start,end,size,orphan,sequence)
self._last=end-1
self._first=start-1
self._sequence=sequence
self._size=size
self._start=start
self._end=end
self._orphan=orphan
self._overlap=overlap
def previous_sequence(self): return self._first
def previous_sequence_end_number(self):
start,end,spam=opt(0, self._start-1+self._overlap,
self._size, self._orphan, self._sequence)
return end
def previous_sequence_start_number(self):
start,end,spam=opt(0, self._start-1+self._overlap,
self._size, self._orphan, self._sequence)
return start
def previous_sequence_end_item(self):
start,end,spam=opt(0, self._start-1+self._overlap,
self._size, self._orphan, self._sequence)
return self._sequence[end-1]
def previous_sequence_start_item(self):
start,end,spam=opt(0, self._start-1+self._overlap,
self._size, self._orphan, self._sequence)
return self._sequence[start-1]
def next_sequence_end_number(self):
start,end,spam=opt(self._end+1-self._overlap, 0,
self._size, self._orphan, self._sequence)
return end
def next_sequence_start_number(self):
start,end,spam=opt(self._end+1-self._overlap, 0,
self._size, self._orphan, self._sequence)
return start
def next_sequence_end_item(self):
start,end,spam=opt(self._end+1-self._overlap, 0,
self._size, self._orphan, self._sequence)
return self._sequence[end-1]
def next_sequence_start_item(self):
start,end,spam=opt(self._end+1-self._overlap, 0,
self._size, self._orphan, self._sequence)
return self._sequence[start-1]
def next_sequence(self):
try: self._sequence[self._end]
except IndexError: return 0
else: return 1
def __getitem__(self, index):
if index > self._last: raise IndexError, index
return self._sequence[index+self._first]
def opt(start,end,size,orphan,sequence):
if size < 1:
if start > 0 and end > 0 and end >= start:
size=end+1-start
else: size=7
if start > 0:
try: sequence[start-1]
except: start=len(sequence)
if end > 0:
if end < start: end=start
else:
end=start+size-1
try: sequence[end+orphan-1]
except: end=len(sequence)
elif end > 0:
try: sequence[end-1]
except: end=len(sequence)
start=end+1-size
if start - 1 < orphan: start=1
else:
start=1
end=start+size-1
try: sequence[end+orphan-1]
except: end=len(sequence)
return start,end,size
<html>
<body tal:define="ztu modules/ZTUtils;b python:ztu.Batch(range(10), 5)">
<p tal:repeat="n b">
Batch 1: item=<span tal:replace="n">n</span>
</p>
<p tal:repeat="n b/next">
Batch 2: item=<span tal:replace="n">n</span>
</p>
</body>
</html>
<html>
<body>
<head>
<p i18n:domain="foo" i18n:translate="bar">baz</p>
<a href="foo" alt="alttext" i18n:attributes="alt">link</a>
<p i18n:domain="dom" i18n:translate="">
<span tal:replace="string:Lomax" i18n:name="name" /> was born in
<span tal:replace="string:Antarctica" i18n:name="country" />.
</p>
</head>
</body>
</html>
<html>
<body>
<head>
<p i18n:domain="foo" i18n:translate="bar">baz</p>
<a href="foo" alt="alttext" i18n:attributes="alt">link</a>
<p i18n:domain="dom" i18n:translate="">
<span tal:replace="string:Lomax" i18n:name="name" /> was born in
<span tal:replace="string:Antarctica" i18n:name="country" />.
</p>
<p i18n:translate="hmm">
I'm <span tal:replace="python:25" i18n:name="age">Age</span>
</p>
</head>
</body>
</html>
<html>
<head></head>
<body>
<div tal:content="not:python:0"></div>
<div tal:content="not:python:1"></div>
<div tal:content="not: python:1"></div>
<div tal:content="not:python:range(1,20)"></div>
</body>
</html>
<html>
<body>
<head>
<title tal:content="nothing">Hello World!</title>
</head>
</body>
</html>
<html>
<body>
<div tal:define="x string:X;nil string:">
<p tal:content="x">1</p>
<p tal:content="x | nil">2</p>
<p tal:content="python:nil or x">3</p>
<p tal:content="y/z | x">4</p>
<p tal:content="y/z | string:X">4</p>
<p tal:content="y/z | python:'|AXE|'[2]">4</p>
<p tal:content="y/z | x | nil">5</p>
<p tal:attributes="name nil">Z</p>
<p tal:attributes="name y/z | nil">Z</p>
<p tal:attributes="name y/z | string:">Z</p>
<p tal:attributes="name y/z | python:'||'[:0]">Z</p>
<p tal:attributes="name y/z | nothing">Z</p>
<p tal:on-error="python:str(error.value[0])" tal:content="a/b | c/d">Z</p>
</div>
</body>
</html>
<html>
<body>
<head>
<title tal:content="path:nothing">Hello World!</title>
</head>
</body>
</html>
<html>
<body>
<head>
<p tal:content="python:u'e acute=\xe9'">e acute here</p>
</head>
</body>
</html>
<?xml version="1.0" ?>
<html>
<body tal:content="string:Hello!">
</body>
</html>
<html xmlns:tal="http://xml.zope.org/namespaces/tal">
<head><title>Test of documentation templates</title></head>
<body>
<span tal:replace="nothing"> blah </span>
<dl tal:condition="context/args">
<dt>The arguments to this test program were:</dt>
<dd>
<ul>
<li tal:repeat="arg context/args">
Argument number <span tal:replace="arg/num">99</span>
is <span tal:replace="arg/arg">default</span>
</li>
</ul>
</dd>
</dl>
<p tal:condition="not:context/args">No arguments were given.</p>
And thats da trooth.
</body>
</html>
<head><title>Test of documentation templates</title></head>
<body>
<div tal:condition="here/args">
The arguments were:
<span tal:condition="options/batch/previous_sequence">
(<span
tal:replace="options/batch/previous_sequence_start_item"
>previous start item</span>-<span
tal:replace="options/batch/previous_sequence_end_item"
>previous end item</span>)
</span>
<dl>
<span tal:repeat="arg options/batch">
<dt><span tal:replace="arg">??</span>.</dt>
<dd>Argument <span tal:define="num arg/num"
tal:replace="string: $num"
>99</span> was <span tal:replace="arg"
>??</span></dd>
</span>
</dl>
<span tal:condition="options/batch/next_sequence">
(<span
tal:replace="options/batch/next_sequence_start_item"
>next start item</span>-<span
tal:replace="options/batch/next_sequence_end_item"
>next end item</span>)
</span>
</div>
<p tal:condition="not:here/args">
No arguments were given.
</p>
And I am 100% sure!
</body>
<html tal:define="global x python:1">
<head></head>
<body>
<div tal:define="x python:2">
<span tal:content="x">Should be 2 here!</span>
</div>
<div>
<span tal:content="x">Should be 1 here!</span>
</div>
<div tal:define="global x python:3">
<span tal:content="x">Should be 3 here!</span>
</div>
</body>
</html>
<html>
<head>
<title>Loop doc</title>
</head>
<body>
<p>Choose your type:</p>
<ul>
<li tal:repeat="type python:'digital', 'analog', 'organic'">
<a href="dummy" tal:attributes="href string:/mach/$type">
<span tal:replace="repeat/type/number">1</span>.
<span tal:replace="type">selection</span></a>
</li>
</ul>
</body>
</html>
<html>
<body tal:define="objects python:[
{'name': 'fred', 'legs': 2},
{'name': 'wilma', 'legs': 2},
{'name': 'dino', 'legs': 4},
]">
<tal:block repeat="ob objects">
<h4 tal:condition="repeat/ob/first/legs">Legs:
<span tal:replace="ob/legs">1</span></h4>
<p tal:content="ob/name">Name</p>
<hr tal:condition="repeat/ob/last/legs" />
</tal:block>
</body>
</html>
<html>
<head>
<title tal:content="string:Hello World!">This is the title</title>
</head>
<body>
<!-- These next two on-error expressions are very fragile; there's
not a lot we can do without fairly interesting exception
objects and not be subject to variations in the str() of the
exception object. -->
<tal:block on-error="string:Error:${error/lineno}" replace="x" />
<tal:block on-error="string:Error:${error/lineno}">
<p tal:content="x">p</p>
</tal:block>
<div tal:replace="structure string:&lt;hr /&gt;">rule</div>
</body>
</html>
<html metal:use-macro="container/laf/macros/page">
<head>
<title>Zope Stuff</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="/common.css">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#0000CC" align="center">
<td>
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#FFFFFF">
<td><img src="/images/lside.gif" width="52" height="94"><img src="/images/swlogo.gif" width="150" height="89"><img src="/images/rside.gif" width="52" height="94"></td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<table width="300" border="0" cellspacing="0" cellpadding="0" align="center">
<tr align="center">
<td width="25%" class="boldbodylist">apparel</td>
<td width="25%" class="boldbodylist">mugs</td>
<td width="25%" class="boldbodylist">toys</td>
<td width="25%" class="boldbodylist">misc</td>
</tr>
</table>
<br>
<br>
<div metal:fill-slot="body">
<table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td bgcolor="#0000CC">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr bgcolor="#FFFFFF" align="center">
<td><img src="/images/welcome.gif" width="293" height="28"></td>
</tr>
<tr bgcolor="#FFFFFF" align="center" valign="top"
tal:repeat="product options/getProducts">
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td colspan="2" class="bodylist" height="200" valign="top"><b>Description:
</b><span tal:replace="product/description">This is the tee for those who LOVE Zope. Show your heart
on your tee.</span></td>
<td align="right" width="1%" rowspan="2">
<p><img src="/images/smlatee.jpg" width="200" height="200"
tal:attributes="src string:/images/${product/image}"></p>
</td>
</tr>
<tr>
<td class="bodylist"><img src="images/clear.gif" width="150" height="10"></td>
<td class="bodylist"><b>Price</b>:<span tal:replace="product/price">12.99</span></td>
</tr>
</table>
</td>
</tr>
<tr bgcolor="#FFFFFF" align="center" valign="top">
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td align="center"><img src="images/buttons/submit.gif" width="87" height="30"></td>
<td align="center"><img src="images/buttons/cancel.gif" width="87" height="30"></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<p>&nbsp;</p><table width="100%" border="0" cellspacing="1" cellpadding="3" align="center">
<tr >
<td align="center" bgcolor="#FFFFFF" class="bodylist"> Copyright 2000 <a href="http://www.4-am.com">4AM
Productions, Inc.</a>. All rights reserved. <br>
Questions or problems should be directed to <a href="mailto:webmaster@teamzonline.com">
the webmaster</a>, 254-412-0846. </td>
</tr>
<tr>
<td align="center"><img src="/images/zopelogos/buildzope.gif" width="54" height="54"></td>
</tr>
</table>
<p>&nbsp;</p>
</body>
</html>
<html metal:use-macro="container/laf/macros/page">
<div metal:fill-slot="body">
Body
</div>
</html>
<html metal:define-macro="page">
<head>
<title>Zope Stuff</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="/common.css">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#0000CC" align="center">
<td>
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#FFFFFF">
<td><img src="/images/lside.gif" width="52" height="94"><img src="/images/swlogo.gif" width="150" height="89"><img src="/images/rside.gif" width="52" height="94"></td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<table width="300" border="0" cellspacing="0" cellpadding="0" align="center">
<tr align="center">
<td width="25%" class="boldbodylist">apparel</td>
<td width="25%" class="boldbodylist">mugs</td>
<td width="25%" class="boldbodylist">toys</td>
<td width="25%" class="boldbodylist">misc</td>
</tr>
</table>
<br>
<br>
<div metal:define-slot="body">
<table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td bgcolor="#0000CC">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr bgcolor="#FFFFFF" align="center">
<td><img src="/images/welcome.gif" width="293" height="28"></td>
</tr>
<tr bgcolor="#FFFFFF" align="center" valign="top">
<td> <br>
<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td>This is the tee for those who LOVE Zope. Show your heart on
your tee.</td>
<td align="right" width="1%">
<p><img src="/images/smlatee.jpg" width="200" height="200"></p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<br><br>
<table width="100%" border="0" cellspacing="1" cellpadding="3" align="center">
<tr>
<td align="center" bgcolor="#FFFFFF" class="bodylist">
Copyright &copy; 2000
<a href="http://www.4-am.com">4AM Productions, Inc.</a>.
All rights reserved. <br>
Questions or problems should be directed to
<a href="mailto:webmaster@teamzonline.com">the webmaster</a>,
254-412-0846.</td>
</tr>
<tr>
<td align="center"><img src="/images/zopelogos/buildzope.gif" width="54" height="54"></td>
</tr>
</table>
</body>
</html>
<html>
<body>
<p>
Batch 1: item=0
</p>
<p>
Batch 1: item=1
</p>
<p>
Batch 1: item=2
</p>
<p>
Batch 1: item=3
</p>
<p>
Batch 1: item=4
</p>
<p>
Batch 2: item=5
</p>
<p>
Batch 2: item=6
</p>
<p>
Batch 2: item=7
</p>
<p>
Batch 2: item=8
</p>
<p>
Batch 2: item=9
</p>
</body>
</html>
<html>
<body>
<head>
<p>baz</p>
<a href="foo" alt="alttext">link</a>
<p>
Lomax was born in
Antarctica.
</p>
</head>
</body>
</html>
<html>
<body>
<head>
<p>[foo](bar/{})</p>
<a href="foo" alt="[default](alttext/{})">link</a>
<p>[dom](${name} was born in ${country}./{'country':'Antarctica','name':'Lomax'})</p>
<p>[default](hmm/{'age':'25'})</p>
</head>
</body>
</html>
<html>
<head></head>
<body>
<div>1</div>
<div>0</div>
<div>0</div>
<div>0</div>
</body>
</html>
<html>
<body>
<head>
<title></title>
</head>
</body>
</html>
<html>
<body>
<div>
<p>X</p>
<p>X</p>
<p>X</p>
<p>X</p>
<p>X</p>
<p>X</p>
<p>X</p>
<p name="">Z</p>
<p name="">Z</p>
<p name="">Z</p>
<p name="">Z</p>
<p>Z</p>
<p>c</p>
</div>
</body>
</html>
<html>
<body>
<head>
<title></title>
</head>
</body>
</html>
<html>
<body>
<head>
<p>e acute=é</p>
</head>
</body>
</html>
<?xml version="1.0" ?>
<html>
<body>Hello!</body>
</html>
<html>
<head><title>Test of documentation templates</title></head>
<body>
<dl>
<dt>The arguments to this test program were:</dt>
<dd>
<ul>
<li>
Argument number 1
is one
</li><li>
Argument number 2
is two
</li><li>
Argument number 3
is three
</li><li>
Argument number 4
is cha
</li><li>
Argument number 5
is cha
</li><li>
Argument number 6
is cha
</li>
</ul>
</dd>
</dl>
And thats da trooth.
</body>
</html>
<html>
<head><title>Test of documentation templates</title></head>
<body>
<p>No arguments were given.</p>
And thats da trooth.
</body>
</html>
<head><title>Test of documentation templates</title></head>
<body>
<div>
The arguments were:
<dl>
<span>
<dt>one.</dt>
<dd>Argument 1 was one</dd>
</span><span>
<dt>two.</dt>
<dd>Argument 2 was two</dd>
</span><span>
<dt>three.</dt>
<dd>Argument 3 was three</dd>
</span><span>
<dt>four.</dt>
<dd>Argument 4 was four</dd>
</span><span>
<dt>five.</dt>
<dd>Argument 5 was five</dd>
</span>
</dl>
<span>
(six-ten)
</span>
</div>
And I am 100% sure!
</body>
<html>
<head></head>
<body>
<div>
<span>2</span>
</div>
<div>
<span>1</span>
</div>
<div>
<span>3</span>
</div>
</body>
</html>
<html>
<head>
<title>Loop doc</title>
</head>
<body>
<p>Choose your type:</p>
<ul>
<li>
<a href="/mach/digital">
1.
digital</a>
</li>
<li>
<a href="/mach/analog">
2.
analog</a>
</li>
<li>
<a href="/mach/organic">
3.
organic</a>
</li>
</ul>
</body>
</html>
<html>
<body>
<h4>Legs:
2</h4>
<p>fred</p>
<p>wilma</p>
<hr >
<h4>Legs:
4</h4>
<p>dino</p>
<hr >
</body>
</html>
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<!-- These next two on-error expressions are very fragile; there's
not a lot we can do without fairly interesting exception
objects and not be subject to variations in the str() of the
exception object. -->
Error:10
Error:11
<hr />
</body>
</html>
<html>
<head>
<title>Zope Stuff</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="/common.css">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#0000CC" align="center">
<td>
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#FFFFFF">
<td><img src="/images/lside.gif" width="52" height="94"><img src="/images/swlogo.gif" width="150" height="89"><img src="/images/rside.gif" width="52" height="94"></td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<table width="300" border="0" cellspacing="0" cellpadding="0" align="center">
<tr align="center">
<td width="25%" class="boldbodylist">apparel</td>
<td width="25%" class="boldbodylist">mugs</td>
<td width="25%" class="boldbodylist">toys</td>
<td width="25%" class="boldbodylist">misc</td>
</tr>
</table>
<br>
<br>
<div>
<table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td bgcolor="#0000CC">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr bgcolor="#FFFFFF" align="center">
<td><img src="/images/welcome.gif" width="293" height="28"></td>
</tr>
<tr bgcolor="#FFFFFF" align="center" valign="top">
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td colspan="2" class="bodylist" height="200" valign="top"><b>Description:
</b>This is the tee for those who LOVE Zope. Show your heart on your tee.</td>
<td align="right" width="1%" rowspan="2">
<p><img src="/images/smlatee.jpg"
width="200" height="200"></p>
</td>
</tr>
<tr>
<td class="bodylist"><img src="images/clear.gif" width="150" height="10"></td>
<td class="bodylist"><b>Price</b>:12.99</td>
</tr>
</table>
</td>
</tr>
<tr bgcolor="#FFFFFF" align="center" valign="top">
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td colspan="2" class="bodylist" height="200" valign="top"><b>Description:
</b>This is the tee for Jim Fulton. He's the Zope Pope!</td>
<td align="right" width="1%" rowspan="2">
<p><img src="/images/smpztee.jpg"
width="200" height="200"></p>
</td>
</tr>
<tr>
<td class="bodylist"><img src="images/clear.gif" width="150" height="10"></td>
<td class="bodylist"><b>Price</b>:11.99</td>
</tr>
</table>
</td>
</tr>
<tr bgcolor="#FFFFFF" align="center" valign="top">
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td align="center"><img src="images/buttons/submit.gif" width="87" height="30"></td>
<td align="center"><img src="images/buttons/cancel.gif" width="87" height="30"></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<br><br>
<table width="100%" border="0" cellspacing="1" cellpadding="3" align="center">
<tr>
<td align="center" bgcolor="#FFFFFF" class="bodylist">
Copyright &copy; 2000
<a href="http://www.4-am.com">4AM Productions, Inc.</a>.
All rights reserved. <br>
Questions or problems should be directed to
<a href="mailto:webmaster@teamzonline.com">the webmaster</a>,
254-412-0846.</td>
</tr>
<tr>
<td align="center"><img src="/images/zopelogos/buildzope.gif" width="54" height="54"></td>
</tr>
</table>
</body>
</html>
<html>
<head>
<title>Zope Stuff</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="/common.css">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#0000CC" align="center">
<td>
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#FFFFFF">
<td><img src="/images/lside.gif" width="52" height="94"><img src="/images/swlogo.gif" width="150" height="89"><img src="/images/rside.gif" width="52" height="94"></td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<table width="300" border="0" cellspacing="0" cellpadding="0" align="center">
<tr align="center">
<td width="25%" class="boldbodylist">apparel</td>
<td width="25%" class="boldbodylist">mugs</td>
<td width="25%" class="boldbodylist">toys</td>
<td width="25%" class="boldbodylist">misc</td>
</tr>
</table>
<br>
<br>
<div>
Body
</div>
<br><br>
<table width="100%" border="0" cellspacing="1" cellpadding="3" align="center">
<tr>
<td align="center" bgcolor="#FFFFFF" class="bodylist">
Copyright &copy; 2000
<a href="http://www.4-am.com">4AM Productions, Inc.</a>.
All rights reserved. <br>
Questions or problems should be directed to
<a href="mailto:webmaster@teamzonline.com">the webmaster</a>,
254-412-0846.</td>
</tr>
<tr>
<td align="center"><img src="/images/zopelogos/buildzope.gif" width="54" height="54"></td>
</tr>
</table>
</body>
</html>
<html>
<head>
<title>Zope Stuff</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="/common.css">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#0000CC" align="center">
<td>
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#FFFFFF">
<td><img src="/images/lside.gif" width="52" height="94"><img src="/images/swlogo.gif" width="150" height="89"><img src="/images/rside.gif" width="52" height="94"></td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<table width="300" border="0" cellspacing="0" cellpadding="0" align="center">
<tr align="center">
<td width="25%" class="boldbodylist">apparel</td>
<td width="25%" class="boldbodylist">mugs</td>
<td width="25%" class="boldbodylist">toys</td>
<td width="25%" class="boldbodylist">misc</td>
</tr>
</table>
<br>
<br>
<div>
<table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td bgcolor="#0000CC">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr bgcolor="#FFFFFF" align="center">
<td><img src="/images/welcome.gif" width="293" height="28"></td>
</tr>
<tr bgcolor="#FFFFFF" align="center" valign="top">
<td> <br>
<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td>This is the tee for those who LOVE Zope. Show your heart on
your tee.</td>
<td align="right" width="1%">
<p><img src="/images/smlatee.jpg" width="200" height="200"></p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<br><br>
<table width="100%" border="0" cellspacing="1" cellpadding="3" align="center">
<tr>
<td align="center" bgcolor="#FFFFFF" class="bodylist">
Copyright &copy; 2000
<a href="http://www.4-am.com">4AM Productions, Inc.</a>.
All rights reserved. <br>
Questions or problems should be directed to
<a href="mailto:webmaster@teamzonline.com">the webmaster</a>,
254-412-0846.</td>
</tr>
<tr>
<td align="center"><img src="/images/zopelogos/buildzope.gif" width="54" height="54"></td>
</tr>
</table>
</body>
</html>
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
import os, sys, unittest
from Products.PageTemplates.tests import util
from Products.PageTemplates.PageTemplate import PageTemplate
from Acquisition import Implicit
from AccessControl import SecurityManager
from AccessControl.SecurityManagement import noSecurityManager
class AqPageTemplate(Implicit, PageTemplate):
pass
class UnitTestSecurityPolicy:
"""
Stub out the existing security policy for unit testing purposes.
"""
#
# Standard SecurityPolicy interface
#
def validate( self
, accessed=None
, container=None
, name=None
, value=None
, context=None
, roles=None
, *args
, **kw):
return 1
def checkPermission( self, permission, object, context) :
return 1
class DTMLTests(unittest.TestCase):
def setUp(self):
self.t=(AqPageTemplate())
self.policy = UnitTestSecurityPolicy()
self.oldPolicy = SecurityManager.setSecurityPolicy( self.policy )
noSecurityManager() # Use the new policy.
def tearDown(self):
SecurityManager.setSecurityPolicy( self.oldPolicy )
noSecurityManager() # Reset to old policy.
def check1(self):
"""DTML test 1: if, in, and var:
%(comment)[ blah %(comment)]
<html><head><title>Test of documentation templates</title></head>
<body>
%(if args)[
<dl><dt>The arguments to this test program were:<p>
<dd>
<ul>
%(in args)[
<li>Argument number %(num)d was %(arg)s
%(in args)]
</ul></dl><p>
%(if args)]
%(else args)[
No arguments were given.<p>
%(else args)]
And thats da trooth.
</body></html>
"""
tal = util.read_input('DTML1.html')
self.t.write(tal)
aa=util.argv(('one', 'two', 'three', 'cha', 'cha', 'cha'))
o=self.t.__of__(aa)()
expect = util.read_output('DTML1a.html')
util.check_xml(expect, o)
aa=util.argv(())
o=self.t.__of__(aa)()
expect = util.read_output('DTML1b.html')
util.check_xml(expect, o)
def check3(self):
"""DTML test 3: batches and formatting:
<html><head><title>Test of documentation templates</title></head>
<body>
<!--#if args-->
The arguments were:
<!--#in args size=size end=end-->
<!--#if previous-sequence-->
(<!--#var previous-sequence-start-arg-->-
<!--#var previous-sequence-end-arg-->)
<!--#/if previous-sequence-->
<!--#if sequence-start-->
<dl>
<!--#/if sequence-start-->
<dt><!--#var sequence-arg-->.</dt>
<dd>Argument <!--#var num fmt=d--> was <!--#var arg--></dd>
<!--#if next-sequence-->
(<!--#var next-sequence-start-arg-->-
<!--#var next-sequence-end-arg-->)
<!--#/if next-sequence-->
<!--#/in args-->
</dl>
<!--#else args-->
No arguments were given.<p>
<!--#/if args-->
And I\'m 100% sure!
</body></html>
"""
tal = util.read_input('DTML3.html')
self.t.write(tal)
aa=util.argv(('one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight', 'nine', 'ten',
'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen',
'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty',
))
from Products.PageTemplates.tests import batch
o=self.t.__of__(aa)(batch=batch.batch(aa.args, 5))
expect = util.read_output('DTML3.html')
util.check_xml(expect, o)
def test_suite():
return unittest.makeSuite(DTMLTests, 'check')
if __name__=='__main__':
main()
import os, sys, unittest
from Products.PageTemplates import Expressions
from Products.PageTemplates.DeferExpr import LazyWrapper
from Products.PageTemplates.DeferExpr import DeferWrapper
class Dummy:
__allow_access_to_unprotected_subobjects__ = 1
def __call__(self):
return 'dummy'
class ExpressionTests(unittest.TestCase):
def setUp(self):
self.e = e = Expressions.getEngine()
self.ec = e.getContext(
one = 1,
d = {'one': 1, 'b': 'b', '': 'blank', '_': 'under'},
blank = '',
dummy = Dummy()
)
def tearDown(self):
del self.e, self.ec
def testCompile(self):
'''Test expression compilation'''
e = self.e
for p in ('x', 'x/y', 'x/y/z'):
e.compile(p)
e.compile('path:a|b|c/d/e')
e.compile('string:Fred')
e.compile('string:A$B')
e.compile('string:a ${x/y} b ${y/z} c')
e.compile('python: 2 + 2')
e.compile('python: 2 \n+\n 2\n')
def testSimpleEval(self):
'''Test simple expression evaluation'''
ec = self.ec
assert ec.evaluate('one') == 1
assert ec.evaluate('d/one') == 1
assert ec.evaluate('d/b') == 'b'
def testRenderedEval(self):
ec = self.ec
assert ec.evaluate('dummy') == 'dummy'
def testEval1(self):
'''Test advanced expression evaluation 1'''
ec = self.ec
assert ec.evaluate('x | nothing') is None
assert ec.evaluate('d/') == 'blank'
assert ec.evaluate('d/_') == 'under'
assert ec.evaluate('d/ | nothing') == 'blank'
assert ec.evaluate('d/?blank') == 'blank'
def testHybrid(self):
'''Test hybrid path expressions'''
ec = self.ec
assert ec.evaluate('x | python:1+1') == 2
assert ec.evaluate('x | python:int') == int
assert ec.evaluate('x | string:x') == 'x'
assert ec.evaluate('x | string:$one') == '1'
assert ec.evaluate('x | not:exists:x')
def testWrappers(self):
"""Test if defer and lazy are returning their wrappers
"""
ec = self.ec
defer = ec.evaluate('defer: b')
lazy = ec.evaluate('lazy: b')
self.failUnless(isinstance(defer, DeferWrapper))
self.failUnless(isinstance(lazy, LazyWrapper))
def test_suite():
return unittest.makeSuite(ExpressionTests)
if __name__=='__main__':
main()
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
import os, sys, unittest
from Products.PageTemplates.tests import util
from Products.PageTemplates.PageTemplate import PageTemplate
from Products.PageTemplates.GlobalTranslationService import \
setGlobalTranslationService
from AccessControl import SecurityManager
from AccessControl.SecurityManagement import noSecurityManager
from Acquisition import Implicit
class AqPageTemplate(Implicit, PageTemplate):
pass
class Folder(util.Base):
pass
class TestTranslationService:
def translate(self, domain, msgid, mapping=None, *args, **kw):
maps = []
if mapping is not None:
# Get a deterministic, sorted representation of dicts.
for k, v in mapping.items():
maps.append('%s:%s' % (`k`, `v`))
maps.sort()
return "[%s](%s/{%s})" % (domain, msgid, ','.join(maps))
class UnitTestSecurityPolicy:
"""
Stub out the existing security policy for unit testing purposes.
"""
#
# Standard SecurityPolicy interface
#
def validate( self
, accessed=None
, container=None
, name=None
, value=None
, context=None
, roles=None
, *args
, **kw):
return 1
def checkPermission( self, permission, object, context) :
return 1
class HTMLTests(unittest.TestCase):
def setUp(self):
self.folder = f = Folder()
f.laf = AqPageTemplate()
f.t = AqPageTemplate()
self.policy = UnitTestSecurityPolicy()
self.oldPolicy = SecurityManager.setSecurityPolicy( self.policy )
noSecurityManager() # Use the new policy.
def tearDown(self):
SecurityManager.setSecurityPolicy( self.oldPolicy )
noSecurityManager() # Reset to old policy.
def assert_expected(self, t, fname, *args, **kwargs):
t.write(util.read_input(fname))
assert not t._v_errors, 'Template errors: %s' % t._v_errors
expect = util.read_output(fname)
out = t(*args, **kwargs)
util.check_html(expect, out)
def assert_expected_unicode(self, t, fname, *args, **kwargs):
t.write(util.read_input(fname))
assert not t._v_errors, 'Template errors: %s' % t._v_errors
expect = util.read_output(fname)
expect = unicode(expect, 'utf8')
out = t(*args, **kwargs)
util.check_html(expect, out)
def getProducts(self):
return [
{'description': 'This is the tee for those who LOVE Zope. '
'Show your heart on your tee.',
'price': 12.99, 'image': 'smlatee.jpg'
},
{'description': 'This is the tee for Jim Fulton. '
'He\'s the Zope Pope!',
'price': 11.99, 'image': 'smpztee.jpg'
},
]
def check1(self):
self.assert_expected(self.folder.laf, 'TeeShopLAF.html')
def check2(self):
self.folder.laf.write(util.read_input('TeeShopLAF.html'))
self.assert_expected(self.folder.t, 'TeeShop2.html',
getProducts=self.getProducts)
def check3(self):
self.folder.laf.write(util.read_input('TeeShopLAF.html'))
self.assert_expected(self.folder.t, 'TeeShop1.html',
getProducts=self.getProducts)
def checkSimpleLoop(self):
self.assert_expected(self.folder.t, 'Loop1.html')
def checkFancyLoop(self):
self.assert_expected(self.folder.t, 'Loop2.html')
def checkGlobalsShadowLocals(self):
self.assert_expected(self.folder.t, 'GlobalsShadowLocals.html')
def checkStringExpressions(self):
self.assert_expected(self.folder.t, 'StringExpression.html')
def checkReplaceWithNothing(self):
self.assert_expected(self.folder.t, 'CheckNothing.html')
def checkWithXMLHeader(self):
self.assert_expected(self.folder.t, 'CheckWithXMLHeader.html')
def checkNotExpression(self):
self.assert_expected(self.folder.t, 'CheckNotExpression.html')
def checkPathNothing(self):
self.assert_expected(self.folder.t, 'CheckPathNothing.html')
def checkPathAlt(self):
self.assert_expected(self.folder.t, 'CheckPathAlt.html')
def checkBatchIteration(self):
self.assert_expected(self.folder.t, 'CheckBatchIteration.html')
def checkUnicodeInserts(self):
self.assert_expected_unicode(self.folder.t, 'CheckUnicodeInserts.html')
def checkI18nTranslate(self):
self.assert_expected(self.folder.t, 'CheckI18nTranslate.html')
def checkI18nTranslateHooked(self):
old_ts = setGlobalTranslationService(TestTranslationService())
self.assert_expected(self.folder.t, 'CheckI18nTranslateHooked.html')
setGlobalTranslationService(old_ts)
def test_suite():
return unittest.makeSuite(HTMLTests, 'check')
if __name__=='__main__':
main()
import os, sys, unittest
from Products.PageTemplates import TALES
from Products.PageTemplates.tests import harness1
import string
class DummyUnicodeExpr:
'''Dummy expression type handler returning unicode'''
def __init__(self, name, expr, engine):
self._name = name
self._expr = expr
def __call__(self, econtext):
return unicode(self._expr, 'latin1')
def __repr__(self):
return '<SimpleExpr %s %s>' % (self._name, `self._expr`)
class TALESTests(unittest.TestCase):
def testIterator0(self):
'''Test sample Iterator class'''
context = harness1()
it = TALES.Iterator('name', (), context)
assert not it.next(), "Empty iterator"
context._complete_()
def testIterator1(self):
'''Test sample Iterator class'''
context = harness1()
it = TALES.Iterator('name', (1,), context)
context._assert_('setLocal', 'name', 1)
assert it.next() and not it.next(), "Single-element iterator"
context._complete_()
def testIterator2(self):
'''Test sample Iterator class'''
context = harness1()
it = TALES.Iterator('text', 'text', context)
for c in 'text':
context._assert_('setLocal', 'text', c)
for c in 'text':
assert it.next(), "Multi-element iterator"
assert not it.next(), "Multi-element iterator"
context._complete_()
def testRegisterType(self):
'''Test expression type registration'''
e = TALES.Engine()
e.registerType('simple', TALES.SimpleExpr)
assert e.getTypes()['simple'] == TALES.SimpleExpr
def testRegisterTypeUnique(self):
'''Test expression type registration uniqueness'''
e = TALES.Engine()
e.registerType('simple', TALES.SimpleExpr)
try:
e.registerType('simple', TALES.SimpleExpr)
except TALES.RegistrationError:
pass
else:
assert 0, "Duplicate registration accepted."
def testRegisterTypeNameConstraints(self):
'''Test constraints on expression type names'''
e = TALES.Engine()
for name in '1A', 'A!', 'AB ':
try:
e.registerType(name, TALES.SimpleExpr)
except TALES.RegistrationError:
pass
else:
assert 0, 'Invalid type name "%s" accepted.' % name
def testCompile(self):
'''Test expression compilation'''
e = TALES.Engine()
e.registerType('simple', TALES.SimpleExpr)
ce = e.compile('simple:x')
assert ce(None) == ('simple', 'x'), (
'Improperly compiled expression %s.' % `ce`)
def testGetContext(self):
'''Test Context creation'''
TALES.Engine().getContext()
TALES.Engine().getContext(v=1)
TALES.Engine().getContext(x=1, y=2)
def getContext(self, **kws):
e = TALES.Engine()
e.registerType('simple', TALES.SimpleExpr)
e.registerType('unicode', DummyUnicodeExpr)
return e.getContext(**kws)
def testContext0(self):
'''Test use of Context'''
se = self.getContext().evaluate('simple:x')
assert se == ('simple', 'x'), (
'Improperly evaluated expression %s.' % `se`)
def testContextUnicode(self):
'''Test evaluateText on unicode-returning expressions'''
se = self.getContext().evaluateText('unicode:\xe9')
self.assertEqual(se, u'\xe9')
def testVariables(self):
'''Test variables'''
ctxt = self.getContext()
c = ctxt.vars
ctxt.beginScope()
ctxt.setLocal('v1', 1)
ctxt.setLocal('v2', 2)
assert c['v1'] == 1, 'Variable "v1"'
ctxt.beginScope()
ctxt.setLocal('v1', 3)
ctxt.setGlobal('g', 1)
assert c['v1'] == 3, 'Inner scope'
assert c['v2'] == 2, 'Outer scope'
assert c['g'] == 1, 'Global'
ctxt.endScope()
assert c['v1'] == 1, "Uncovered local"
assert c['g'] == 1, "Global from inner scope"
ctxt.endScope()
def test_suite():
return unittest.makeSuite(TALESTests)
if __name__=='__main__':
unittest.main(defaultTest='test_suite')
""" Unit tests for Products.PageTemplates.ZRPythonExpr
$Id
"""
import unittest
class MiscTests(unittest.TestCase):
def test_call_with_ns_prefer_context_to_here(self):
from Products.PageTemplates.ZRPythonExpr import call_with_ns
context = ['context']
here = ['here']
request = {'request': 1}
names = {'context' : context, 'here': here, 'request' : request}
result = call_with_ns(lambda td: td.this, names)
self.failUnless(result is context, result)
def test_call_with_ns_no_context_or_here(self):
from Products.PageTemplates.ZRPythonExpr import call_with_ns
request = {'request': 1}
names = {'request' : request}
result = call_with_ns(lambda td: td.this, names)
self.failUnless(result is None, result)
def test_call_with_ns_no_request(self):
from Products.PageTemplates.ZRPythonExpr import call_with_ns
context = ['context']
here = ['here']
names = {'context' : context, 'here': here}
def _find_request(td):
ns = td._pop() # peel off 'ns'
instance_dict = td._pop() # peel off InstanceDict
request = td._pop()
td._push(request)
td._push(instance_dict)
td._push(ns)
return request
result = call_with_ns(_find_request, names)
self.assertEqual(result, {})
def test_suite():
return unittest.makeSuite(MiscTests)
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
######################################################################
# Utility facilities to aid setting things up.
import os, sys, string, re
from ExtensionClass import Base
class Bruce(Base):
__allow_access_to_unprotected_subobjects__=1
def __str__(self): return 'bruce'
def __int__(self): return 42
def __float__(self): return 42.0
def keys(self): return ['bruce']*7
def values(self): return [self]*7
def items(self): return [('bruce',self)]*7
def __len__(self): return 7
def __getitem__(self,index):
if (type(index) is type(1) and
(index < 0 or index > 6)): raise IndexError, index
return self
isDocTemp=0
def __getattr__(self,name):
if name[:1]=='_': raise AttributeError, name
return self
bruce=Bruce()
class arg(Base):
__allow_access_to_unprotected_subobjects__=1
def __init__(self,nn,aa): self.num, self.arg = nn, aa
def __str__(self): return str(self.arg)
class argv(Base):
__allow_access_to_unprotected_subobjects__=1
def __init__(self, argv=sys.argv[1:]):
args=self.args=[]
for aa in argv:
args.append(arg(len(args)+1,aa))
def items(self):
return map(lambda a: ('spam%d' % a.num, a), self.args)
def values(self): return self.args
def getPhysicalRoot(self):
return self
def nicerange(lo, hi):
if hi <= lo+1:
return str(lo+1)
else:
return "%d,%d" % (lo+1, hi)
def check_html(s1, s2):
s1 = normalize_html(s1)
s2 = normalize_html(s2)
if s1!=s2:
print
from OFS.ndiff import SequenceMatcher, dump, IS_LINE_JUNK
a = string.split(s1, '\n')
b = string.split(s2, '\n')
def add_nl(s):
return s + '\n'
a = map(add_nl, a)
b = map(add_nl, b)
cruncher=SequenceMatcher(isjunk=IS_LINE_JUNK, a=a, b=b)
for tag, alo, ahi, blo, bhi in cruncher.get_opcodes():
if tag == 'equal':
continue
print nicerange(alo, ahi) + tag[0] + nicerange(blo, bhi)
dump('<', a, alo, ahi)
if a and b:
print '---'
dump('>', b, blo, bhi)
assert s1==s2, "HTML Output Changed"
def check_xml(s1, s2):
s1 = normalize_xml(s1)
s2 = normalize_xml(s2)
assert s1==s2, "XML Output Changed"
def normalize_html(s):
s = re.sub(r"[ \t]+", " ", s)
s = re.sub(r"/>", ">", s)
return s
def normalize_xml(s):
s = re.sub(r"\s+", " ", s)
s = re.sub(r"(?s)\s+<", "<", s)
s = re.sub(r"(?s)>\s+", ">", s)
return s
import Products.PageTemplates.tests
dir = os.path.dirname( Products.PageTemplates.tests.__file__)
input_dir = os.path.join(dir, 'input')
output_dir = os.path.join(dir, 'output')
def read_input(filename):
filename = os.path.join(input_dir, filename)
return open(filename, 'r').read()
def read_output(filename):
filename = os.path.join(output_dir, filename)
return open(filename, 'r').read()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment