/usr/lib/python2.7/dist-packages/zope/configuration/tests/nested.py is in python-zope.configuration 4.0.3-3.
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 | ##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################
""" Utilities for the 'nested directive' section in the narrative docs.
"""
from zope.interface import Attribute
from zope.interface import Interface
from zope.interface import implementer
from zope.schema import BytesLine
from zope.schema import Id
from zope.schema import Int
from zope.schema import Text
from zope.schema import TextLine
from zope.configuration.config import GroupingContextDecorator
from zope.configuration.config import IConfigurationContext
from zope.configuration.fields import Bool
from zope.configuration._compat import u
schema_registry = {}
class ISchemaInfo(Interface):
"""Parameter schema for the schema directive
"""
name = TextLine(
title=u("The schema name"),
description=u("This is a descriptive name for the schema."),
)
id = Id(title=u("The unique id for the schema"))
class ISchema(Interface):
"""Interface that distinguishes the schema directive
"""
fields = Attribute("Dictionary of field definitions")
@implementer(IConfigurationContext, ISchema)
class Schema(GroupingContextDecorator):
"""Handle schema directives
"""
def __init__(self, context, name, id):
self.context, self.name, self.id = context, name, id
self.fields = {}
def after(self):
schema = Interface.__class__(
self.name,
(Interface, ),
self.fields
)
schema.__doc__ = self.info.text.strip()
self.action(
discriminator=('schema', self.id),
callable=schema_registry.__setitem__,
args=(self.id, schema),
)
class IFieldInfo(Interface):
name = BytesLine(
title=u("The field name"),
)
title = TextLine(
title=u("Title"),
description=u("A short summary or label"),
default=u(""),
required=False,
)
required = Bool(
title=u("Required"),
description=u("Determines whether a value is required."),
default=True)
readonly = Bool(
title=u("Read Only"),
description=u("Can the value be modified?"),
required=False,
default=False)
class ITextInfo(IFieldInfo):
min_length = Int(
title=u("Minimum length"),
description=u("Value after whitespace processing cannot have less than "
"min_length characters. If min_length is None, there is "
"no minimum."),
required=False,
min=0, # needs to be a positive number
default=0)
max_length = Int(
title=u("Maximum length"),
description=u("Value after whitespace processing cannot have greater "
"or equal than max_length characters. If max_length is "
"None, there is no maximum."),
required=False,
min=0, # needs to be a positive number
default=None)
def field(context, constructor, name, **kw):
# Compute the field
field = constructor(description=context.info.text.strip(), **kw)
# Save it in the schema's field dictionary
schema = context.context
if name in schema.fields:
raise ValueError("Duplicate field", name)
schema.fields[name] = field
def textField(context, **kw):
field(context, Text, **kw)
class IIntInfo(IFieldInfo):
min = Int(
title=u("Start of the range"),
required=False,
default=None
)
max = Int(
title=u("End of the range (excluding the value itself)"),
required=False,
default=None
)
def intField(context, **kw):
field(context, Int, **kw)
|