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.
4.3.2.1. 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.-
get_next_page_location
()¶ Returns the location of this page of the collection
The result is a
rfc2396.URI
instance.
-
new_entity
()¶ Returns an OData aware instance
-
is_medialink_collection
()¶ Returns True if this is a collection of Media-Link Entries
-
new_stream
(src, sinfo=None, key=None)¶ Creates a media resource.
- src
- A file-like object from which the stream’s data will be read.
- sinfo
- 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. - key
- 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.
- key
- The key associated with the stream being read.
- out
- 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.
-
read_stream_close
(key)¶ Creates a generator for a media resource.
- key
- 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).
-
check_filter
(entity)¶ 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, orderObject)¶ Evaluates orderObject as an instance of py:class:CommonExpression.
-
generate_entity_set_in_json
(version=2)¶ Generates JSON serialised form of this collection.
-
generate_link_coll_json
(version=2)¶ 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.
- obj
- A python dictionary parsed from a JSON representation
- entity_resolver
- 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.
- for_update
- 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
- for_update
- A boolean, defaults to False, indicating that the output JSON should include any unsaved bindings
- version
- Defaults to version 2 output
-
link_json
()¶ 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.
-
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
-