code: def default_listener(col_attr, default):
      """Establish a default-setting listener.
  
      Given a class attribute and a :class:`.DefaultGenerator` instance.
      The default generator should be a :class:`.ColumnDefault` object with a
      plain Python value or callable default; otherwise, the appropriate behavior
      for SQL functions and defaults should be determined here by the
      user integrating this feature.
  
      """
  
      @event.listens_for(
          col_attr, "init_scalar", retval=True, propagate=True
      )
      def init_scalar(target, value, dict_):
          if default.is_callable:
              # the callable of ColumnDefault always accepts a context
              # argument; we can pass it as None here.
              value = default.arg(None)
          elif default.is_scalar:
              value = default.arg
          else:
              # default is a Sequence, a SQL expression, server
              # side default generator, or other non-Python-evaluable
              # object.  The feature here can't easily support this.   This
              # can be made to return None, rather than raising,
              # or can procure a connection from an Engine
              # or Session and actually run the SQL, if desired.
              raise NotImplementedError(
                  "Can't invoke pre-default for a SQL-level column default"
              )
  
          # set the value in the given dict_; this won't emit any further
          # attribute set events or create attribute "history", but the value
          # will be used in the INSERT statement
          dict_[col_attr.key] = value
  
          # return the value as well
          return value
  
file_path: sqlalchemy/examples/custom_attributes/active_column_defaults.py
imports: import datetime
  from sqlalchemy import Column
  from sqlalchemy import create_engine
  from sqlalchemy import DateTime
  from sqlalchemy import event
  from sqlalchemy import Integer
  from sqlalchemy.ext.declarative import declarative_base
  from sqlalchemy.orm import Session
label_desc: Use image node_id 2 for calling a global function with example usage: default_listener(col_attr, default) and returns: value