4.3.2. OData Core Classes

This module extends the definitions in pyslet.odata2.csdl with OData-specific functions and classes. In most cases you won’t need to worry about which layer of the model a definition belongs to. Where a class is derived from one in the parent EDM the same name is used, therefore most of the time you should look to include items from the core module rather than from the base csdl module. Data Model

class pyslet.odata2.core.EntityCollection(entity_set, **kwargs)

Bases: pyslet.odata2.csdl.EntityCollection

EntityCollections that provide OData-specific options

Our definition of EntityCollection is designed for use with Python’s diamond inheritance model. We inherit directly from the basic pyslet.odata2.csdl.EntityCollection object, providing additional methods that support the expression model defined by OData, media link entries and JSON encoding.


Returns the location of this page of the collection

The result is a rfc2396.URI instance.


Returns an OData aware instance

Returns True if this is a collection of Media-Link Entries

new_stream(src, sinfo=None, key=None)

Creates a media resource.

A file-like object from which the stream’s data will be read.
A StreamInfo object containing metadata about the stream. If the size field of sinfo is set then at most sinfo.size bytes are read from src. Otherwise src is read until the end of the file.
The key associated with the stream being written. This value is taken as a suggestion for the key to use, its use is not guaranteed. The key actually used to store the stream can be obtained from the resulting entity.

Returns the media-link entry Entity

update_stream(src, key, sinfo=None)

Updates an existing media resource.

The parameters are the same as new_stream() except that the key must be present and must be an existing key in the collection.

read_stream(key, out=None)

Reads a media resource.

The key associated with the stream being read.
An optional file like object to which the stream’s data will be written. If no output file is provided then no data is written.

The return result is the StreamInfo class describing the stream.


Creates a generator for a media resource.

The key associated with the stream being read.

The return result is a tuple of the StreamInfo class describing the stream and a generator that yields the stream’s data.

The collection is closed by the generator when the iteration is complete (or when the generator is destroyed).


Checks entity against any filter and returns True if it passes.

The filter object must be an instance of py:class:CommonExpression that returns a Boolean value.

boolExpression is a CommonExpression.

calculate_order_key(entity, order_object)

Evaluates order_object as an instance of py:class:CommonExpression.


Generates JSON serialised form of this collection.

Generates JSON serialised collection of links

class pyslet.odata2.core.Entity(entity_set)

Bases: pyslet.odata2.csdl.Entity

We override Entity in order to provide OData serialisation.

set_from_json_object(obj, entity_resolver=None, for_update=False)

Sets the value from a JSON representation.

A python dictionary parsed from a JSON representation
An optional callable that takes a URI object and returns the entity object it points to. This is used for resolving links when creating or updating entities from a JSON source.
An optional boolean (defaults to False) that indicates if an existing entity is being deserialised for update or just for read access. When True, new bindings are added to the entity for links provided in the obj. If the entity doesn’t exist then this argument is ignored.
generate_entity_type_in_json(for_update=False, version=2)

Returns a JSON-encoded string representing this entity

A boolean, defaults to False, indicating that the output JSON should include any unsaved bindings
Defaults to version 2 output

Returns a JSON-serialised link to this entity

class pyslet.odata2.core.StreamInfo(type=MediaType('application', 'octet-stream', {}), created=None, modified=None, size=None)

Bases: object

Represents information about a media resource stream.

type = None

the media type, a MediaType instance

created = None

the optional creation time, a fully specified TimePoint instance that includes a zone

modified = None

the optional modification time, a fully specified TimePoint instance that includes a zone

size = None

the size of the stream (in bytes), None if not known

md5 = None

the 16 byte binary MD5 checksum of the stream, None if not known