[Cubicweb] Understanding _cw

Aurélien Campéas aurelien.campeas at logilab.fr
Wed May 14 18:42:33 CEST 2014

On 14/05/2014 18:08, Aurélien Campéas wrote:
> Hello,
> The mysterious _cw object has always bothered my, because
> it can be different things in the same places in different
> contexts.

For the sake of completeness, here's the list of methods for these

>>> requestsessionbase  # base of *all* others
['base_url', 'build_url', 'build_url_params', 'create_entity',
'describe', 'eid_rset', 'empty_rset', 'ensure_ro_rql', 'entity_cache',
'entity_from_eid', 'etype_rset', 'find', 'format_date',
'format_float', 'format_time', 'get_option_value', 'parse_datetime',
'printable_value', 'property_value', 'rebuild_url',
'set_entity_cache', 'set_language', 'url_parse_qsl', 'url_quote',
'url_unquote', 'user_data', 'view']

>>> cubicwebrequestbase # from web/request.py
['add_css', 'add_header', 'add_js', 'add_onload', 'ajax_replace_url',
'append_to_redirect_message', 'authmode', 'base_url_path',
'base_url_prepend_host', 'cached_entities', 'call_service',
'cancel_edition', 'data_url', 'del_page_data',
'describe', 'drop_entity_cache', 'edited_eids', 'entity_cache',
'entity_metas', 'execute', 'extract_entity_params',
'fckeditor_config', 'from_controller', 'get_authorization',
'get_cookie', 'get_headers', 'get_page_data',
'header_accept_language', 'header_authorization',
'header_if_modified_since', 'html_content_type', 'http_method',
'ie_browser', 'is_client_cache_valid', 'last_visited_page',
'list_form_param', 'match_search_state', 'message', 'next_tabindex',
'no_script_form_param', 'parse_accept_header', 'redirect_message_id',
'relative_path', 'remove_cookie',
'remove_header', 'remove_pending_operations', 'reset_headers',
'reset_message', 'selected', 'set_cnx', 'set_content_type',
'set_cookie', 'set_default_language', 'set_doctype',
'set_entity_cache', 'set_header', 'set_message', 'set_message_id',
'set_page_data', 'set_redirect_message', 'set_search_state',
'set_user_language', 'set_varmaker', 'setup_params', 'source_defs',
'update_breadcrumbs', 'update_search_state',
'url', 'use_fckeditor', 'user_rql_callback', 'useragent', 'varmaker']

>>> clientconnection # from repoapi.py
['allow_all_hooks_but', 'cached_entities', 'call_service', 'commit',
'deny_all_hooks_but', 'describe', 'drop_entity_cache', 'entity_cache',
'entity_metas', 'execute', 'get_option_value', 'get_schema',
'rollback', 'security_enabled', 'set_entity_cache', 'source_defs',
'system_sql', 'transaction_actions', 'transaction_info',
'undo_transaction', 'undoable_transactions']

>>> connection # from server/session.py
['add_operation', 'add_relation', 'add_relations',
'added_in_transaction', 'allow_all_hooks_but', 'cached_entities',
'call_service', 'clear', 'cnxset', 'commit', 'data',
'delete_relation', 'deleted_in_transaction', 'deny_all_hooks_but',
'disable_hook_categories', 'drop_entity_cache',
'enable_hook_categories', 'ensure_cnx_set', 'entity_cache',
'entity_metas', 'ertype_supports_undo', 'execute',
'is_hook_activated', 'is_hook_category_activated',
'read_security', 'rollback', 'rql_rewriter', 'rtype_eids_rdef',
'security_enabled', 'set_entity_cache', 'source_defs', 'system_sql',
'transaction_inc_action_counter', 'transaction_uuid',
'update_rel_cache_add', 'update_rel_cache_del']

I believe we should separate db connection from (http) request and
e.g. learn views to deal with a .req (along with the _cw).

Then, let's tackle ClientConnection vs Connection. The separation of
responsibilities here is quite unclear to me.

I suspect this may be a remain of the "web fence" utopy (where, in
principle, a cubicweb "web client" would talk through pyro to a
cubicweb "repo only" instance). Maybe this is actually needed for the
pyro/zmqpickle protocols today still (needs to be looked up).

I see no fundamental reason we cannot flatten ClientConnection onto
Connection. If we need a RemoteConnection, let's build it and clearly
state its limits.

Then _cw would get rid of all the request stuff (try using dir(_cw) to
see why it would help) and have a single, consistent API, and be the
same thing to all people all the time.


More information about the Cubicweb mailing list