API

nti.property.property

class nti.property.property.LazyOnClass(func)

Bases: object

Like zope.cachedescriptors.property.Lazy, but when it caches, it caches on the class itself, not the instance, thus sharing the value. Thus, the value should be immutable and independent of any other state.

nti.property.property.alias(prop_name, doc=None)

Returns a property that is a read/write alias for another attribute of the object.

See dict_alias().

nti.property.property.annotation_alias(annotation_name, annotation_property=None, default=None, delete=False, delete_quiet=True, doc=None)

Returns a property that is a read/write alias for a value stored as a zope.annotation.interface.IAnnotations.

The object itself may be adaptable to an IAnnotations, or a property of the object may be what is adaptable to the annotation. The later is intended for use in adapters when the context object is what should be adapted.

Parameters:
  • delete (bool) – If True (not the default), then the property can be used to delete the annotation.
  • delete_quiet (bool) – If True and delete is also True, then the property will ignore key errors when deleting the annotation value.
  • annotation_property (str) – If set to a string, it is this property of the object that will be adapted to IAnnotations. Most often this will be context when used inside an adapter.
nti.property.property.dict_alias(key_name, doc=None)

Returns a property that is a read/write alias for a value in the instance’s dictionary.

See alias() for a more general version; this is a speed or access optimization.

nti.property.property.dict_read_alias(key_name, doc=None)

Returns a property that is a read-only alias for a value in the instances dictionary.

See read_alias() for a more general version; this is a speed or access optimization.

nti.property.property.read_alias(prop_name, doc=None)

Returns a property that is a read-only alias for another attribute of the object.

See dict_read_alias().

nti.property.schema

Schema fields.

class nti.property.schema.DataURI(min_length=0, max_length=None, **kw)

Bases: zope.schema._field.URI

A URI field that ensures and requires its value to be a data URI. The field value is a DataURL.

DATA = 'data:'
fromUnicode(value)

See IFromUnicode.

classmethod is_valid_data_uri(value)

nti.property.dataurl

Objects for working with the RFC2397 data URL scheme:

data:[<MIME-type>][;charset=<encoding>][;base64],<data>

The encoding is indicated by ;base64. If it’s present the data is encoded as base64. Without it the data (as a sequence of octets) is represented using ASCII encoding for octets inside the range of safe URL characters and using the standard %xx hex encoding of URLs for octets outside that range. If <MIME-type> is omitted, it defaults to text/plain;charset=US-ASCII. (As a shorthand, the type can be omitted but the charset parameter supplied.)

class nti.property.dataurl.DataURL

Bases: str

Represents a data URL with convenient access to its raw bytes and mime type.

data
mimeType
nti.property.dataurl.decode(data_url)

Decodes a data URL into raw bytes and metadata.

Parameters:data_url – The data url string. If a mime-type definition is missing in the metadata, text/plain;charset=US-ASCII will be used as default mime-type.
Returns:A 2-tuple: (bytes, mime_type_string) The mime_type string will not be parsed. See zope.contenttype.parse.parse() for that.
nti.property.dataurl.encode(raw_bytes, mime_type='text/plain', charset=<object object>, encoder='base64')

Encodes raw bytes into a data URL scheme string.

Parameters:
  • raw_bytes – Raw bytes
  • mime_type – The mime type, e.g. b"text/css" or b"image/png". Default b"text/plain".
  • charset

    Set to b"utf-8" if you want the data URL to contain a b"charset=utf-8" component. Default b'US-ASCII'. This does not mean however, that your raw_bytes will be encoded by this function. You must ensure that if you specify, b"utf-8" (or anything else) as the encoding, you have encoded your raw data appropriately.

    Note

    This function employs a heuristic to know when to default this parameter (for example, it is not used for image mime types). To be absolutely sure, set it explicitly (None always meaning not to use it).

  • encoder – The string “base64” (the default) or None. If None, the data is directly output as quoted ASCII bytes.
Returns:

Data URL byte string

nti.property.urlproperty

class nti.property.urlproperty.UrlProperty(data_name=None, url_attr_name=None, file_attr_name=None, use_dict=False)

Bases: object

A data descriptor like property() for storing a URL value efficiently.

This is an interesting situation because of data: URLs, which can be quite large. (See nti.property.dataurl) To store them efficiently, we transform them into a Blob-based zope.file.interfaces.IFile. This means that we need up to two dictionary entries/attributes on the instance (one to store a URL string, one to store a IFile), although they can be the same; we will take care of type checking as needed.

Commonly, to be useful, the file will need to be reachable by traversal on the instance holding the property. This object will ensure that the file is located (in the zope.location sense) as a child of the instance, and that it has a name; it is the responsibility of the instance to arrange for it to be traversable (through implementing __getitem__ or ITraversable or an adapter).

Parameters:use_dict (bool) – If set to True, then the instance dictionary will be used explicitly for access to the url and file data. This is necessary if this property is being assigned to the same value as one of the attr names.
data_name = 'data'
file_attr_name = '_file'
get_file(instance)

Return the zope.file.interfaces.IFile for the instance if there is one, otherwise None.

ignore_url_with_missing_host = False
make_getitem()

As a convenience and to help with traversability, the results of this method can be assigned to __getitem__ (if there is no other instance of this property, or no other getitem).

Caution

The traversal key must be equal to the data_name, but the returned dictionary key is the file_attr_name.

max_file_size = None
reject_url_with_missing_host = False
url_attr_name = '_url'