26 from contextlib import contextmanager |
26 from contextlib import contextmanager |
27 from logging import getLogger |
27 from logging import getLogger |
28 |
28 |
29 from six import text_type |
29 from six import text_type |
30 |
30 |
31 from logilab.common.deprecation import deprecated |
|
32 from logilab.common.registry import objectify_predicate |
31 from logilab.common.registry import objectify_predicate |
33 |
32 |
34 from cubicweb import QueryError, ProgrammingError, schema, server |
33 from cubicweb import QueryError, ProgrammingError, schema, server |
35 from cubicweb import set_log_methods |
34 from cubicweb import set_log_methods |
36 from cubicweb.req import RequestSessionBase |
35 from cubicweb.req import RequestSessionBase |
69 |
68 |
70 @objectify_predicate |
69 @objectify_predicate |
71 def repairing(cls, req, **kwargs): |
70 def repairing(cls, req, **kwargs): |
72 """return 1 when repository is running in repair mode""" |
71 """return 1 when repository is running in repair mode""" |
73 return req.vreg.config.repairing |
72 return req.vreg.config.repairing |
74 |
|
75 |
|
76 @deprecated('[3.17] use <object>.allow/deny_all_hooks_but instead') |
|
77 def hooks_control(obj, mode, *categories): |
|
78 assert mode in (HOOKS_ALLOW_ALL, HOOKS_DENY_ALL) |
|
79 if mode == HOOKS_ALLOW_ALL: |
|
80 return obj.allow_all_hooks_but(*categories) |
|
81 elif mode == HOOKS_DENY_ALL: |
|
82 return obj.deny_all_hooks_but(*categories) |
|
83 |
73 |
84 |
74 |
85 class _hooks_control(object): |
75 class _hooks_control(object): |
86 """context manager to control activated hooks categories. |
76 """context manager to control activated hooks categories. |
87 |
77 |
121 def __exit__(self, exctype, exc, traceback): |
111 def __exit__(self, exctype, exc, traceback): |
122 self.cnx._hooks_mode = self.old_mode |
112 self.cnx._hooks_mode = self.old_mode |
123 self.cnx._hooks_categories = self.old_categories |
113 self.cnx._hooks_categories = self.old_categories |
124 |
114 |
125 |
115 |
126 @deprecated('[3.17] use <object>.security_enabled instead') |
|
127 def security_enabled(obj, *args, **kwargs): |
|
128 return obj.security_enabled(*args, **kwargs) |
|
129 |
|
130 |
|
131 class _security_enabled(object): |
116 class _security_enabled(object): |
132 """context manager to control security w/ session.execute, |
117 """context manager to control security w/ session.execute, |
133 |
118 |
134 By default security is disabled on queries executed on the repository |
119 By default security is disabled on queries executed on the repository |
135 side. |
120 side. |
388 self.hooks_in_progress = prevmode |
373 self.hooks_in_progress = prevmode |
389 |
374 |
390 # shared data handling ################################################### |
375 # shared data handling ################################################### |
391 |
376 |
392 @property |
377 @property |
393 @deprecated('[3.25] use transaction_data or req.session.data', stacklevel=3) |
|
394 def data(self): |
|
395 return self.transaction_data |
|
396 |
|
397 @property |
|
398 def rql_rewriter(self): |
378 def rql_rewriter(self): |
399 return self._rewriter |
379 return self._rewriter |
400 |
380 |
401 def clear(self): |
381 def clear(self): |
402 """reset internal data""" |
382 """reset internal data""" |
406 #: (None, 'precommit', 'postcommit', 'uncommitable') |
386 #: (None, 'precommit', 'postcommit', 'uncommitable') |
407 self.commit_state = None |
387 self.commit_state = None |
408 self.pruned_hooks_cache = {} |
388 self.pruned_hooks_cache = {} |
409 self.local_perm_cache.clear() |
389 self.local_perm_cache.clear() |
410 self.rewriter = RQLRewriter(self) |
390 self.rewriter = RQLRewriter(self) |
411 |
|
412 @deprecated('[3.19] cnxset are automatically managed now.' |
|
413 ' stop using explicit set and free.') |
|
414 def set_cnxset(self): |
|
415 pass |
|
416 |
|
417 @deprecated('[3.19] cnxset are automatically managed now.' |
|
418 ' stop using explicit set and free.') |
|
419 def free_cnxset(self, ignoremode=False): |
|
420 pass |
|
421 |
|
422 @property |
|
423 @contextmanager |
|
424 @_open_only |
|
425 @deprecated('[3.21] a cnxset is automatically set on __enter__ call now.' |
|
426 ' stop using .ensure_cnx_set') |
|
427 def ensure_cnx_set(self): |
|
428 yield |
|
429 |
391 |
430 # Entity cache management ################################################# |
392 # Entity cache management ################################################# |
431 # |
393 # |
432 # The connection entity cache as held in cnx.transaction_data is removed at the |
394 # The connection entity cache as held in cnx.transaction_data is removed at the |
433 # end of the connection (commit and rollback) |
395 # end of the connection (commit and rollback) |
699 |
661 |
700 @_open_only |
662 @_open_only |
701 def entity_type(self, eid): |
663 def entity_type(self, eid): |
702 """Return entity type for the entity with id `eid`.""" |
664 """Return entity type for the entity with id `eid`.""" |
703 return self.repo.type_from_eid(eid, self) |
665 return self.repo.type_from_eid(eid, self) |
704 |
|
705 @deprecated('[3.24] use entity_type(eid) instead') |
|
706 @_open_only |
|
707 def entity_metas(self, eid): |
|
708 """Return a dictionary {type}) for the entity with id `eid`.""" |
|
709 return {'type': self.repo.type_from_eid(eid, self)} |
|
710 |
666 |
711 # core method ############################################################# |
667 # core method ############################################################# |
712 |
668 |
713 @_open_only |
669 @_open_only |
714 def execute(self, rql, kwargs=None, build_descr=True): |
670 def execute(self, rql, kwargs=None, build_descr=True): |