parameters: (
              self,
              context: Connection,
              handler: Optional['TransactionHandler'] = None,
              settle_before_discharge: bool = False
      )
return_statement: return Transaction(context._txn_ctrl, handler, settle_before_discharge)
docstring: Declare a local transaction.
  
          :param context: Context for the transaction, usually the connection.
          :param handler: Handler for transactional events.
          :param settle_before_discharge: Settle all transaction control messages before
              the transaction is discharged.
docstring_summary: Declare a local transaction.
docstring_tokens: Declare a local transaction .
function: def declare_transaction(
              self,
              context: Connection,
              handler: Optional['TransactionHandler'] = None,
              settle_before_discharge: bool = False
      ) -> Transaction:
          """
          Declare a local transaction.
  
          :param context: Context for the transaction, usually the connection.
          :param handler: Handler for transactional events.
          :param settle_before_discharge: Settle all transaction control messages before
              the transaction is discharged.
          """
          if not _get_attr(context, '_txn_ctrl'):
              class InternalTransactionHandler(OutgoingMessageHandler):
                  def __init__(self):
                      super(InternalTransactionHandler, self).__init__(auto_settle=True)
  
                  def on_settled(self, event):
                      if hasattr(event.delivery, "transaction"):
                          event.transaction = event.delivery.transaction
                          event.delivery.transaction.handle_outcome(event)
  
                  def on_unhandled(self, method, event):
                      if handler:
                          event.dispatch(handler)
  
              context._txn_ctrl = self.create_sender(context, None, name='txn-ctrl', handler=InternalTransactionHandler())
              context._txn_ctrl.target.type = Terminus.COORDINATOR
              context._txn_ctrl.target.capabilities.put_object(symbol(u'amqp:local-transactions'))
          return Transaction(context._txn_ctrl, handler, settle_before_discharge)
function_tokens: def declare_transaction ( self , context : Connection , handler : Optional [ 'TransactionHandler' ] = None , settle_before_discharge : bool = False ) -> Transaction : if not _get_attr ( context , '_txn_ctrl' ) : class InternalTransactionHandler ( OutgoingMessageHandler ) : def __init__ ( self ) : super ( InternalTransactionHandler , self ) . __init__ ( auto_settle = True ) def on_settled ( self , event ) : if hasattr ( event . delivery , "transaction" ) : event . transaction = event . delivery . transaction event . delivery . transaction . handle_outcome ( event ) def on_unhandled ( self , method , event ) : if handler : event . dispatch ( handler ) context . _txn_ctrl = self . create_sender ( context , None , name = 'txn-ctrl' , handler = InternalTransactionHandler ( ) ) context . _txn_ctrl . target . type = Terminus . COORDINATOR context . _txn_ctrl . target . capabilities . put_object ( symbol ( u'amqp:local-transactions' ) ) return Transaction ( context . _txn_ctrl , handler , settle_before_discharge )