code: def register_range(pgrange, pyrange, conn_or_curs, globally=False):
      """Create and register an adapter and the typecasters to convert between
      a PostgreSQL |range|_ type and a PostgreSQL `Range` subclass.
  
      :param pgrange: the name of the PostgreSQL |range| type. Can be
          schema-qualified
      :param pyrange: a `Range` strict subclass, or just a name to give to a new
          class
      :param conn_or_curs: a connection or cursor used to find the oid of the
          range and its subtype; the typecaster is registered in a scope limited
          to this object, unless *globally* is set to `!True`
      :param globally: if `!False` (default) register the typecaster only on
          *conn_or_curs*, otherwise register it globally
      :return: `RangeCaster` instance responsible for the conversion
  
      If a string is passed to *pyrange*, a new `Range` subclass is created
      with such name and will be available as the `~RangeCaster.range` attribute
      of the returned `RangeCaster` object.
  
      The function queries the database on *conn_or_curs* to inspect the
      *pgrange* type and raises `~psycopg2.ProgrammingError` if the type is not
      found.  If querying the database is not advisable, use directly the
      `RangeCaster` class and register the adapter and typecasters using the
      provided functions.
  
      """
      caster = RangeCaster._from_db(pgrange, pyrange, conn_or_curs)
      caster._register(not globally and conn_or_curs or None)
      return caster
  
imports: import re
  from psycopg2._psycopg import ProgrammingError, InterfaceError
  from psycopg2.extensions import ISQLQuote, adapt, register_adapter
  from psycopg2.extensions import new_type, new_array_type, register_type
label_desc: Use image node_id 1 for calling a global function with example usage: register_range(pgrange, pyrange, conn_or_curs, globally) and returns: caster