/usr/share/pyshared/z3c/rml/doclogic.py is in python-z3c.rml 2.0.0-0ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | ##############################################################################
#
# Copyright (c) 2012 Zope Foundation 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.
#
##############################################################################
"""``doc*`` directives.
"""
import reportlab.platypus
from z3c.rml import attr, directive, flowable, interfaces, occurence
class IDocAssign(interfaces.IRMLDirectiveSignature):
"""Assign a value to the namesapce."""
var = attr.String(
title=u'Variable Name',
description=u'The name under which the value is stored.',
required=True)
expr = attr.String(
title=u'Expression',
description=u'The expression that creates the value when evaluated.',
required=True)
class DocAssign(flowable.Flowable):
signature = IDocAssign
klass = reportlab.platypus.flowables.DocAssign
class IDocExec(interfaces.IRMLDirectiveSignature):
"""Execute a statement."""
stmt = attr.String(
title=u'Statement',
description=u'The statement to be executed.',
required=True)
class DocExec(flowable.Flowable):
signature = IDocExec
klass = reportlab.platypus.flowables.DocExec
class IDocPara(interfaces.IRMLDirectiveSignature):
"""Create a paragraph with the value returned from the expression."""
expr = attr.String(
title=u'Expression',
description=u'The expression to be executed.',
required=True)
format = attr.String(
title=u'Format',
description=u'The format used to render the expression value.',
required=False)
style = attr.Style(
title=u'Style',
description=u'The style of the paragraph.',
required=False)
escape = attr.Boolean(
title=u'Escape Text',
description=u'When set (default) the expression value is escaped.',
required=False)
class DocPara(flowable.Flowable):
signature = IDocPara
klass = reportlab.platypus.flowables.DocPara
class IDocAssert(interfaces.IRMLDirectiveSignature):
"""Assert a certain condition."""
cond = attr.String(
title=u'Condition',
description=u'The condition to be asserted.',
required=True)
format = attr.String(
title=u'Format',
description=u'The text displayed if assertion fails.',
required=False)
class DocAssert(flowable.Flowable):
signature = IDocAssert
klass = reportlab.platypus.flowables.DocAssert
class IDocElse(interfaces.IRMLDirectiveSignature):
"""Starts 'else' block."""
class DocElse(flowable.Flowable):
signature = IDocElse
def process(self):
if not isinstance(self.parent, DocIf):
raise ValueError("<docElse> can only be placed inside a <docIf>")
self.parent.flow = self.parent.elseFlow
class IDocIf(flowable.IFlow):
"""Display story flow based on the value of the condition."""
cond = attr.String(
title=u'Condition',
description=u'The condition to be tested.',
required=True)
class DocIf(flowable.Flow):
signature = IDocAssert
klass = reportlab.platypus.flowables.DocIf
def __init__(self, *args, **kw):
super(flowable.Flow, self).__init__(*args, **kw)
self.thenFlow = self.flow = []
self.elseFlow = []
def process(self):
args = dict(self.getAttributeValues())
self.processSubDirectives()
dif = self.klass(
thenBlock = self.thenFlow, elseBlock = self.elseFlow, **args)
self.parent.flow.append(dif)
class IDocWhile(flowable.IFlow):
"""Repeat the included directives as long as the condition is true."""
cond = attr.String(
title=u'Condition',
description=u'The condition to be tested.',
required=True)
class DocWhile(flowable.Flow):
signature = IDocAssert
klass = reportlab.platypus.flowables.DocWhile
def process(self):
args = dict(self.getAttributeValues())
self.processSubDirectives()
dwhile = self.klass(whileBlock = self.flow, **args)
self.parent.flow.append(dwhile)
flowable.Flow.factories['docAssign'] = DocAssign
flowable.Flow.factories['docExec'] = DocExec
flowable.Flow.factories['docPara'] = DocPara
flowable.Flow.factories['docAssert'] = DocAssert
flowable.Flow.factories['docIf'] = DocIf
flowable.Flow.factories['docElse'] = DocElse
flowable.Flow.factories['docWhile'] = DocWhile
flowable.IFlow.setTaggedValue(
'directives',
flowable.IFlow.getTaggedValue('directives') +
(occurence.ZeroOrMore('docAssign', IDocAssign),
occurence.ZeroOrMore('docExec', IDocExec),
occurence.ZeroOrMore('docPara', IDocPara),
occurence.ZeroOrMore('docIf', IDocIf),
occurence.ZeroOrMore('docElse', IDocElse),
occurence.ZeroOrMore('docWhile', IDocWhile),
)
)
|