API

cubes.wsme.types

Types

class cubes.wsme.types.PassThroughType[source]

Special webservice type that transmit a value without doing anything

It is used in wsme signature for the ‘entity’ argument which is passed by the controller itself and should not be transtyped in any way.

cubes.wsme.types.JsonData = <cubes.wsme.types.JsonDataType object>

User type that carry json encoded arbitrary data.

cubes.wsme.types.binary = <cubes.wsme.types.BinaryType object>

webservice type that map the cubicweb.Binary values.

class cubes.wsme.types.wsattr(rtype=None, role='subject', etype=None, datatype=None, writeonly=False, **kw)[source]

Cubicweb-specific version of wsme.types.wsattr

To be used on a Base class. All the attributes are optionnal and can be deduced from the rtype.

rtype

The corresponding relation in the model

role

The role of the parent class in the relation

etype

The entity type on the other side of the relation

datatype

The webservice type

cubes.wsme.types.iswsattr(obj)[source]

returns True if an object is a wsattr

class cubes.wsme.types.Base(entity=None, keyonly=False, fetch=())[source]

Bases: wsme.types.Base

Base class for a complex type that map an entity type

eid

Entity eid

alias of long

final_values()[source]

Returns a dict with all the attribute values.

This dict can be used to feed cubicweb.entity.Entity.cw_set().

classmethod finalize_init()[source]

Finalize the class initialization.

This last step resolve types in the underlying attributes.

from_entity(entity, keyonly=False, fetch=())[source]

Load values from an entity

Parameters:
  • entity – the entity
  • keyonly – if True, only the .eid and .modfication_date will be loaded. The result can be used as “timestamped reference”.
  • fetch – a list of relations to eager load. Unless specified, all the ‘1’ or ‘?’ relation targets will be loaded as ‘keyonly’, and the ‘*’ or ‘+’ relations will not be loaded at all.
classmethod reginit(vreg)[source]

Register the class

Use the informations in the registry, and most notably the schema, to initialize the attributes.

to_entity(entity)[source]

Update the entity attributes (not the non-final relations).

class cubes.wsme.types.Any(entity=None, keyonly=False, fetch=())[source]

Complex type to carry any type of entity.

Automatically used for polymorphic relations targets

cubes.wsme.types.scan(vreg, modname)[source]

Scan a module for any class inheriting Base and register them.

cubes.wsme.controller

‘webservice’ controller implementation

class cubes.wsme.controller.WSController(*args, **kwargs)[source]

Bases: cubicweb.web.controller.Controller

A controller that rely on WSME to provide webservice API for an entity.

publish(rset)[source]

Main entry-point of the controller.

Will dispatch the request to the adequate function depending on the http method and the form/rset content.

It also takes care of converting the inputs (form & body) to call arguments using the WSME api, based on the function signatures.

The following form values are used, which are normaly set by cubes.wsme.views.RestPathEvaluator:

  • _ws_method: the HTTP method
  • _ws_etype: the etype (ignored, only used by the selector)
  • _ws_rtype: the relation type if provided
  • _ws_rtype_target: An option relation target id

If the :arg:`rset` contains an entity, it will be considered as the target of the API call.

classmethod resolve_types(registry)[source]

Late-resolve the types of the function signatures.

This function is called at regitering time (by __registered__()).

class cubes.wsme.controller.WSCRUDController(*args, **kwargs)[source]

Bases: cubes.wsme.controller.WSController

An entity type CRUD controller

The displatch is summarized in this table, where ‘entity’ means that an entity exists in the rset:

form-rset / verb GET POST PUT DELETE
  _get() _post()    
entity _entity_get()   _entity_put() _entity_delete()
entity, _ws_rtype _entity_rtype_get() _entity_rtype_post()    
entity, _ws_rtype, _ws_rtype_target       _entity_rtype_target_delete()
_create(data)[source]

Create an entity from ws data

_entity_delete(entity)[source]

Default implementation of DELETE /etype/eid.

_entity_get(entity, fetch=[])[source]

Default implementation of GET /etype/eid.

_entity_put(entity, fetch=[], data=None)[source]

Default implementation of PUT /etype/eid.

_entity_rtype_get(entity, rtype, orderby=None, limit=None, offset=None, keyonly=False)[source]

Default implementation of GET /etype/eid/rtype.

_entity_rtype_post(entity, rtype, eid)[source]

Default implementation of POST /etype/eid/rtype.

_entity_rtype_target_delete(entity, rtype, eid)[source]

Default implementation of DELETE /etype/eid/rtype/eid.

_get(orderby=None, filter=None, limit=0, offset=0, fetch=[], keyonly=False)[source]

List entities with an optional filter.

Default implementation of GET /etype.

Parameters:
  • filter
  • fetch – A list of relations and subrelations of which the target entities will be returned.
_get_entities(datalist)[source]

Get a list of entities from a list a webservice data

_get_entity(data)[source]

Get an entity and update/create it and its related entities all along.

Parameters:data – A webservice type instance
_handle_data(data)[source]

Handle webservice data.

It returns a tuple (eid, values, relation_values), where eid can be None if the data had none, values contains the final and inlined values, and relation_values the relation values. These variables are dictionnaries that can be fed cw_set().

While handling the entity data, the related entities present in the data will be updated/create (via _get_entity()).

_post(fetch=[], keyonly=False, data=None)[source]

Default implementation of POST /etype.

_update(data)[source]

Update an existing entity from ws data