equal
deleted
inserted
replaced
240 self.pending_operations = [] |
240 self.pending_operations = [] |
241 #: (None, 'precommit', 'postcommit', 'uncommitable') |
241 #: (None, 'precommit', 'postcommit', 'uncommitable') |
242 self.commit_state = None |
242 self.commit_state = None |
243 self.pruned_hooks_cache = {} |
243 self.pruned_hooks_cache = {} |
244 |
244 |
|
245 |
|
246 def tx_attr(attr_name): |
|
247 """return a property to forward attribute access to transaction. |
|
248 |
|
249 This is to be used by session""" |
|
250 @property |
|
251 def attr_from_tx(session): |
|
252 return getattr(session._tx, attr_name) |
|
253 return attr_from_tx |
245 |
254 |
246 class Session(RequestSessionBase): |
255 class Session(RequestSessionBase): |
247 """Repository user session |
256 """Repository user session |
248 |
257 |
249 This tie all together: |
258 This tie all together: |
647 if read is not None: |
656 if read is not None: |
648 self.set_read_security(read) |
657 self.set_read_security(read) |
649 if write is not None: |
658 if write is not None: |
650 self.set_write_security(write) |
659 self.set_write_security(write) |
651 |
660 |
652 @property |
661 read_security = tx_attr('read_security') |
653 def read_security(self): |
|
654 """return a boolean telling if read security is activated or not""" |
|
655 return self._tx.read_security |
|
656 |
662 |
657 def set_read_security(self, activated): |
663 def set_read_security(self, activated): |
658 """[de]activate read security, returning the previous value set for |
664 """[de]activate read security, returning the previous value set for |
659 later restoration. |
665 later restoration. |
660 |
666 |
682 # also reset dbapi_query to true when we go back to DEFAULT_SECURITY |
688 # also reset dbapi_query to true when we go back to DEFAULT_SECURITY |
683 tx.dbapi_query = (oldmode is DEFAULT_SECURITY |
689 tx.dbapi_query = (oldmode is DEFAULT_SECURITY |
684 or activated is DEFAULT_SECURITY) |
690 or activated is DEFAULT_SECURITY) |
685 return oldmode |
691 return oldmode |
686 |
692 |
687 @property |
693 write_security = tx_attr('write_security') |
688 def write_security(self): |
|
689 """return a boolean telling if write security is activated or not""" |
|
690 return self._tx.write_security |
|
691 |
694 |
692 def set_write_security(self, activated): |
695 def set_write_security(self, activated): |
693 """[de]activate write security, returning the previous value set for |
696 """[de]activate write security, returning the previous value set for |
694 later restoration. |
697 later restoration. |
695 |
698 |
716 def allow_all_hooks_but(self, *categories): |
719 def allow_all_hooks_but(self, *categories): |
717 return hooks_control(self, HOOKS_ALLOW_ALL, *categories) |
720 return hooks_control(self, HOOKS_ALLOW_ALL, *categories) |
718 def deny_all_hooks_but(self, *categories): |
721 def deny_all_hooks_but(self, *categories): |
719 return hooks_control(self, HOOKS_DENY_ALL, *categories) |
722 return hooks_control(self, HOOKS_DENY_ALL, *categories) |
720 |
723 |
721 @property |
724 hooks_mode = tx_attr('hooks_mode') |
722 def hooks_mode(self): |
|
723 return self._tx.hooks_mode |
|
724 |
725 |
725 def set_hooks_mode(self, mode): |
726 def set_hooks_mode(self, mode): |
726 assert mode is HOOKS_ALLOW_ALL or mode is HOOKS_DENY_ALL |
727 assert mode is HOOKS_ALLOW_ALL or mode is HOOKS_DENY_ALL |
727 oldmode = self._tx.hooks_mode |
728 oldmode = self._tx.hooks_mode |
728 self._tx.hooks_mode = mode |
729 self._tx.hooks_mode = mode |
750 else: |
751 else: |
751 return self.enable_hook_categories(*categories) |
752 return self.enable_hook_categories(*categories) |
752 finally: |
753 finally: |
753 self.set_hooks_mode(oldmode) |
754 self.set_hooks_mode(oldmode) |
754 |
755 |
755 @property |
756 disabled_hook_categories = tx_attr('disabled_hook_cats') |
756 def disabled_hook_categories(self): |
757 enabled_hook_categories = tx_attr('enabled_hook_cats') |
757 return self._tx.disabled_hook_cats |
|
758 |
|
759 @property |
|
760 def enabled_hook_categories(self): |
|
761 return self._tx.enabled_hook_cats |
|
762 |
758 |
763 def disable_hook_categories(self, *categories): |
759 def disable_hook_categories(self, *categories): |
764 """disable the given hook categories: |
760 """disable the given hook categories: |
765 |
761 |
766 - on HOOKS_DENY_ALL mode, ensure those categories are not enabled |
762 - on HOOKS_DENY_ALL mode, ensure those categories are not enabled |
1183 def closed(self): |
1179 def closed(self): |
1184 return not hasattr(self, '_txs') |
1180 return not hasattr(self, '_txs') |
1185 |
1181 |
1186 # transaction data/operations management ################################## |
1182 # transaction data/operations management ################################## |
1187 |
1183 |
1188 @property |
1184 transaction_data = tx_attr('data') |
1189 def transaction_data(self): |
1185 pending_operations = tx_attr('pending_operations') |
1190 return self._tx.transaction_data |
1186 pruned_hooks_cache = tx_attr('pruned_hooks_cache') |
1191 |
|
1192 @property |
|
1193 def pending_operations(self): |
|
1194 return self._tx.pending_operations |
|
1195 |
|
1196 @property |
|
1197 def pruned_hooks_cache(self): |
|
1198 return self._tx.pruned_hooks_cache |
|
1199 |
1187 |
1200 def add_operation(self, operation, index=None): |
1188 def add_operation(self, operation, index=None): |
1201 """add an operation""" |
1189 """add an operation""" |
1202 if index is None: |
1190 if index is None: |
1203 self.pending_operations.append(operation) |
1191 self.pending_operations.append(operation) |
1224 self._tx.data['tx_action_count'] = num |
1212 self._tx.data['tx_action_count'] = num |
1225 return num |
1213 return num |
1226 |
1214 |
1227 # querier helpers ######################################################### |
1215 # querier helpers ######################################################### |
1228 |
1216 |
1229 @property |
1217 rql_rewriter = tx_attr('_rewriter') |
1230 def rql_rewriter(self): |
|
1231 # in thread local storage since the rewriter isn't thread safe |
|
1232 return self._tx._rewriter |
|
1233 |
1218 |
1234 # deprecated ############################################################### |
1219 # deprecated ############################################################### |
1235 |
1220 |
1236 @deprecated('[3.13] use getattr(session.rtype_eids_rdef(rtype, eidfrom, eidto), prop)') |
1221 @deprecated('[3.13] use getattr(session.rtype_eids_rdef(rtype, eidfrom, eidto), prop)') |
1237 def schema_rproperty(self, rtype, eidfrom, eidto, rprop): |
1222 def schema_rproperty(self, rtype, eidfrom, eidto, rprop): |