adhocracy_core.schema package

Basic data structures and validation.

class SchemaNode(*arg, **kw)[source]

Bases: colander.SchemaNode

Subclass of :class: SchemaNode with extended keyword support.

The constructor accepts these additional keyword arguments:

readonly:
Disable deserialization. Default: False
readonly = False
deserialize(cstruct=<colander.null>)[source]

Deserialize the cstruct into an appstruct.

serialize(appstruct=<colander.null>)[source]

Serialize the appstruct to a cstruct.

If the appstruct is None and None is the default value, serialize to None instead of null.

class SequenceSchema(*args, **kw)[source]

Bases: colander.SequenceSchema, adhocracy_core.schema.SchemaNode

Subclass of :class: SchemaNode with Sequence type.

The default value is a deferred returning [] to prevent modify it.

default = <colander.deferred object>[source]
widget = <colander.deferred object>[source]
class SequenceOptionalJsonInSchema(*args, **kw)[source]

Bases: adhocracy_core.schema.SequenceSchema

Sequence type that allows a JSON string deserialization input.

deserialize(cstruct)[source]
widget = <colander.deferred object>[source]
class MappingSchema(*arg, **kw)[source]

Bases: colander.Schema, adhocracy_core.schema.SchemaNode

Subclass of :class: SchemaNode with dictionary type.

class TupleSchema(*arg, **kw)[source]

Bases: colander.TupleSchema, adhocracy_core.schema.SchemaNode

Subclass of :class: SchemaNode with tuple type.

raise_attribute_error_if_not_location_aware(context) → None[source]

Ensure that the argument is location-aware.

Raises:AttributeError – if it isn’t
deferred_validate_name_is_unique(node: adhocracy_core.schema.SchemaNode, kw: dict)[source]

Validate if value is name that does not exists in the parent object.

Raises:Invalid – if name already exists in the parent or parent is None.
class Identifier(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

Like Name, but doesn’t check uniqueness..

Example value: blu.ABC_12-3

schema_type

alias of String

default = ''
missing = <colander._drop object>
relative_regex = '[a-zA-Z0-9\\_\\-\\.]+'
validator = <colander.All object>
class Name(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

The unique name of a resource inside the parent pool.

Allowed characters are: “alpha” “numeric” “_” “-” ”.” The maximal length is 100 characters, the minimal length 1.

Example value: blu.ABC_12-3

This node needs a parent_pool binding to validate.

schema_type

alias of String

default = ''
missing = <colander._drop object>
validator = <colander.deferred object>
class Email(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

String with email address.

Example value: test@test.de

schema_type

alias of String

default = ''
missing = <colander._drop object>
static preparer(email)
validator = <colander.Email object>
class URL(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

String with a URL.

Example value: http://colander.readthedocs.org/en/latest/

schema_type

alias of String

default = ''
missing = <colander._drop object>
regex = re.compile('^(http|ftp)s?://(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\\.)+(?:[A-Z]{2,6}\\.?|[A-Z0-9-]{2,}(?<!-)\\.?)|localhost|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|\\[?[A-F0-9]*:[A-F0-9:]+\\]?)(?::\\d+)?(?, re.IGNORECASE)
validator = <colander.Regex object>
class TimeZoneName(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

String with time zone.

Example value: UTC

schema_type

alias of String

default = 'UTC'
missing = <colander._drop object>
validator = <colander.OneOf object>
class Role(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

Permission role name.

Example value: ‘reader’

schema_type

alias of String

default = 'creator'
missing = <colander._drop object>
validator = <colander.OneOf object>
class Roles(*args, **kw)[source]

Bases: adhocracy_core.schema.SequenceSchema

List of Permssion role names.

Example value: [‘initiator’]

missing = <colander._drop object>
validator = <colander.Length object>
preparer(value: collections.abc.Sequence) → list[source]

Preparer for the roles.

class InterfaceType[source]

Bases: colander.SchemaType

A ZOPE interface in dotted name notation.

Example value: adhocracy_core.sheets.name.IName

serialize(node, value)[source]

Serialize interface to dotted name.

deserialize(node, value)[source]

Deserialize path to object.

class Interface(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

schema_type

alias of InterfaceType

class Interfaces(*args, **kw)[source]

Bases: adhocracy_core.schema.SequenceSchema

class AbsolutePath(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

Absolute path made with Identifier Strings.

Example value: /bluaABC/_123/3

schema_type

alias of String

relative_regex = '/[a-zA-Z0-9\\_\\-\\.\\/]+'
validator = <colander.Regex object>
string_has_no_newlines_validator(value: str) → bool[source]

Check for new line characters.

class SingleLine(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

UTF-8 encoded String without line breaks.

Disallowed characters are linebreaks like: n, r. Example value: This is a something.

schema_type

alias of String

default = ''
missing = <colander._drop object>
validator = <colander.Function object>
class Boolean(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

SchemaNode for boolean values.

Example value: false

schema_type() → colander.SchemaType[source]

Return the schema type.

default = False
missing = False
class Booleans(*args, **kw)[source]

Bases: adhocracy_core.schema.SequenceSchema

class ContentType(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

ContentType schema.

schema_type

alias of InterfaceType

default = <colander.deferred object>
get_sheet_cstructs(context: <InterfaceClass adhocracy_core.interfaces.IResource>, registry, request) → dict[source]

Serialize and return the `viewable`resource sheet data.

class CurrencyAmount(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

SchemaNode for currency amounts.

Values are stored precisely with 2 fractional digits. The used currency (e.g. EUR, USD) is not stored as part of the value, it is assumed to be known or to be stored in a different field.

Example value: 1.99

schema_type() → colander.SchemaType[source]

Return schema type.

default = Decimal('0')
missing = <colander._drop object>
class ISOCountryCode(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

An ISO 3166-1 alpha-2 country code (two uppercase ASCII letters).

Example value: US

schema_type

alias of String

default = ''
missing = <colander._drop object>
validator = <colander.Regex object>
deserialize(cstruct=<colander.null>)[source]

Deserialize the cstruct into an appstruct.

class ResourceObjectType(serialization_form='url')[source]

Bases: colander.SchemaType

Schema type that de/serialized a location-aware object.

Example values: ‘http://a.org/bluaABC/_123/3‘ ‘/blua/ABC/’

If the value is an url with fqdn the the request binding is used to deserialize the resource.

If the value is an absolute path the context binding is used to deserialize the resource.

The default serialization is the resource url.

Initialize self.

serialization_form = None
Parameters:serialization_form
  • If ‘url` the request binding is used to serialize to the resource url.
  • If path the context binding is used to serialize to the Resource Location path.
  • If content the request and ‘context’ binding is used to serialize the complete resource content and metadata.

Default url.

serialize(node, value)[source]

Serialize object to url or path.

Parameters:
  • node – the Colander node.
  • value – the resource to serialize
Returns:

the url or path of that resource

deserialize(node, value)[source]

Deserialize url or path to object.

Parameters:
  • node – the Colander node.
  • value – the url or path Resource Location to deserialize
Returns:

the resource registered under that path

Raises:

Invalid – if the object does not exist.

class Resource(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

A resource SchemaNode.

Example value: ‘http://a.org/bluaABC/_123/3

default = None
missing = <colander._drop object>
schema_type

alias of ResourceObjectType

class ResourcePathSchema(*arg, **kw)[source]

Bases: adhocracy_core.schema.MappingSchema

Resource Path schema.

class ResourcePathAndContentSchema(*arg, **kw)[source]

Bases: adhocracy_core.schema.ResourcePathSchema

Resource Path with content schema.

validate_reftype(node: adhocracy_core.schema.SchemaNode, value: <InterfaceClass adhocracy_core.interfaces.IResource>)[source]

Raise if value doesn`t provide the ISheet set by node.reftype.

class Reference(*arg, **kw)[source]

Bases: adhocracy_core.schema.Resource

Schema Node to reference a resource that implements a specific sheet.

The constructor accepts these additional keyword arguments:

  • reftype: :class:` adhocracy_core.interfaces.SheetReference`.

    The target_isheet attribute of the reftype specifies the sheet that accepted resources must implement. Storing another kind of resource will trigger a validation error.

  • backref: marks this Reference as a back reference.

    adhocracy_core.sheet.ResourceSheet can use this information to autogenerate the appstruct/cstruct. Default: False.

reftype = <SheetReferenceClass adhocracy_core.interfaces.SheetReference>
backref = False
validator = <colander.All object>
multiple = False
widget = <colander.deferred object>
class Resources(*args, **kw)[source]

Bases: adhocracy_core.schema.SequenceSchema

List of :class:`Resource:`s.

missing = []
class References(*args, **kw)[source]

Bases: adhocracy_core.schema.Resources

Schema Node to reference resources that implements a specific sheet.

The constructor accepts these additional keyword arguments:

  • reftype: adhocracy_core.interfaces.SheetReference.

    The target_isheet attribute of the reftype specifies the sheet that accepted resources must implement. Storing another kind of resource will trigger a validation error.

  • backref: marks this Reference as a back reference.

    adhocracy_core.sheet.ResourceSheet can use this information to autogenerate the appstruct/cstruct. Default: False.

reftype = <SheetReferenceClass adhocracy_core.interfaces.SheetReference>
backref = False
validator = <colander.All object>
multiple = True
widget = <colander.deferred object>
class UniqueReferences(*args, **kw)[source]

Bases: adhocracy_core.schema.References

Schema Node to reference resources that implements a specific sheet.

The order is preserved, duplicates are removed.

Example value: [“http:a.org/bluaABC“]

preparer(value: collections.abc.Sequence) → list[source]

Preparer for the schema.

class Text(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

UTF-8 encoded String with line breaks.

Example value: This is a something
with new lines.
schema_type

alias of String

default = ''
missing = <colander._drop object>
widget = <deform_markdown.MarkdownTextAreaWidget object>
class Password(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

UTF-8 encoded text.

Minimal length=6, maximal length=100 characters. Example value: secret password?

schema_type

alias of String

default = <colander.deferred object>
missing = <colander._drop object>
validator = <colander.Length object>
widget = <deform.widget.PasswordWidget object>
class DateTime(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

DateTime object.

This type serializes python datetime.datetime objects to a ISO8601 string format. The format includes the date, the time, and the timezone of the datetime.

Example values: 2014-07-21, 2014-07-21T09:10:37, 2014-07-21T09:10:37+00:00

The default/missing value is the current datetime.

Constructor arguments:

Parameters:tzinfo – This timezone is used if the cstruct is missing the tzinfo. Defaults to UTC
schema_type

alias of DateTime

default = <colander.deferred object>
missing = <colander.deferred object>
widget = <colander.deferred object>[source]
class DateTimes(*args, **kw)[source]

Bases: adhocracy_core.schema.SequenceSchema

class PostPool(*arg, **kw)[source]

Bases: adhocracy_core.schema.Reference

Reference to the common place to post resources used by the this sheet.

Constructor arguments:

Parameters:iresource_or_service_name – The resource interface/service name of this post_pool. If it is a interface the lineage of the context is searched for the first matching interface. If it is a string the lineage and the lineage children are search for a service with this name. Defaults to adhocracy_core.interfaces.IPool.
readonly = True
default = <colander.deferred object>
missing = <colander._drop object>
schema_type

alias of ResourceObjectType

iresource_or_service_name = <InterfaceClass adhocracy_core.interfaces.IPool>
create_post_pool_validator(child_node: adhocracy_core.schema.Reference, kw: dict) → <built-in function callable>[source]

Create validator to check kw[‘context’] is inside post_pool.

Parameters:
  • child_node (Reference) – Reference to a sheet with post_pool field.
  • kw (dict) – dictionary with keys context and registry.
class Integer(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

SchemaNode for Integer values.

Example value: 1

schema_type

alias of Integer

default = 0
missing = <colander._drop object>
class Integers(*args, **kw)[source]

Bases: adhocracy_core.schema.SequenceSchema

SchemaNode for a list of Integer values.

Example value: [1,2]

class Float(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

SchemaNode for Float values.

Example value: 1.234

schema_type

alias of Float

default = 0.0
missing = <colander._drop object>
class Floats(*args, **kw)[source]

Bases: adhocracy_core.schema.SequenceSchema

SchemaNode for a list of Float values.

Example value: [1.003, 2.0]

class FileStoreType[source]

Bases: colander.SchemaType

Accepts raw file data or filedict.

raw file data: used to make ‘multipart/form-data’ upload in
adhocracy_core.rest.views.AssetsServiceRESTView work.
filedict: dictionary with html5 file data, as used for
adhocracy_core.sdi.
SIZE_LIMIT = 16777216
serialize(node: adhocracy_core.schema.SchemaNode, value: substanced.file.File) → deform.widget.filedict[source]

Serialize File value to filedict.

deserialize(node: adhocracy_core.schema.SchemaNode, value: object) → substanced.file.File[source]

Deserialize cgi.file or class:deform.widget.filedict .

class FileStore(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

SchemaNode wrapping FileStoreType.

schema_type

alias of FileStoreType

default = None
missing = <colander._drop object>
widget = <colander.deferred object>[source]
deserialize(cstruct=<colander.null>)[source]
class SingleLines(*args, **kw)[source]

Bases: adhocracy_core.schema.SequenceSchema

List of SingleLines.

class ACEPrincipalType[source]

Bases: colander.SchemaType

Adhocracy role or pyramid system principal.

valid_principals = ['participant', 'moderator', 'creator', 'initiator', 'admin', 'god', 'everyone', 'authenticated']

Valid principal strings.

serialize(node, value) → str[source]

Serialize principal and remove prefix (“system.” or “role:”).

Raises:ValueError – if value has no ‘.’ or ‘:’ char
deserialize(node, value) → str[source]

Deserialize principal and add prefix (“system.” or “role:”).

class ACEPrincipal(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

Adhocracy role or pyramid system principal.

schema_type

alias of ACEPrincipalType

widget = <colander.deferred object>[source]
class ACEPrincipals(*args, **kw)[source]

Bases: adhocracy_core.schema.SequenceSchema

List of Adhocracy role or pyramid system principal.

class ACMCell(*arg, **kw)[source]

Bases: adhocracy_core.schema.SchemaNode

ACM Cell.

schema_type

alias of String

missing = None
preparer(node, value)[source]
class ACMRow(*args, **kw)[source]

Bases: adhocracy_core.schema.SequenceSchema

ACM Row.

validator = <colander.deferred object>[source]
class ACMPrincipals(*args, **kw)[source]

Bases: adhocracy_core.schema.SequenceSchema

ACM Principals.

default = []
missing = []
class ACMPermissions(*args, **kw)[source]

Bases: adhocracy_core.schema.SequenceSchema

ACM Permissions.

default = []
missing = []
class ACM(*arg, **kw)[source]

Bases: adhocracy_core.schema.MappingSchema

Access Control Matrix.

default = {'principals': [], 'permissions': []}
missing = {'principals': [], 'permissions': []}
create_deferred_permission_validator(permission: str) → <built-in function callable>[source]

Create a deferred permission check validator.

get_choices_by_interface(interface: <InterfaceClass zope.interface.interfaces.IInterface>, context: <InterfaceClass adhocracy_core.interfaces.IResource>, request: <InterfaceClass pyramid.interfaces.IRequest>) → [][source]

Get choices for resource paths by interface.