Auxiliary functions — "p_group_cohomology" 3.3.2 documentation

# Auxiliary functions

AUTHORS:

- Simon King <simon.king@uni-jena.de>

class `pGroupCohomology.auxiliaries.` `CohoFormatter`(fmt='%(message)s', datefmt=None, walltime=None, cputime=None)

  Formatter that groups log messages.

  EXAMPLE:

      sage: from pGroupCohomology.auxiliaries import coho_logger
      sage: from pGroupCohomology import CohomologyRing
      sage: CohomologyRing.reset()
      sage: L = [ZZ, ZZ, ZZ['x'], ZZ['x'], ZZ['x'], ZZ, ZZ]
      sage: for i,P in enumerate(L):
      ....:     coho_logger.warning('warning %d', P, i)
      ....:
      Integer Ring:
                warning 0
                warning 1
      Univariate Polynomial Ring in x over Integer Ring:
                warning 2
                warning 3
                warning 4
      Integer Ring:
                warning 5
                warning 6

  `format`(record)

    INPUT:

    record, an instance of `logging.LogRecord`.

    This formatter accesses `obj=record.args[0]` (the args must thus be non-empty) and tests whether it coincides with with the `obj` obtained from the previously obtained log record. If the differ, then the string representation is prepended to the log message, which also will be indented.

    In that way, the log messages are grouped in blocks, so that the human eye can more easily grasp what log message is associated with what object.

    ASSUMPTION:

    `record.args[0]` allows a weak reference.

    EXAMPLES:

        sage: from pGroupCohomology.auxiliaries import coho_logger
        sage: from pGroupCohomology import CohomologyRing
        sage: CohomologyRing.reset()
        sage: L = [ZZ, ZZ, ZZ['x'], ZZ['x'], ZZ['x'], ZZ, ZZ]
        sage: for i,P in enumerate(L):
        ....:     coho_logger.warning('warning %d', P, i)  # indirect doctest
        ....:
        Integer Ring:
                  warning 0
                  warning 1
        Univariate Polynomial Ring in x over Integer Ring:
                  warning 2
                  warning 3
                  warning 4
        Integer Ring:
                  warning 5
                  warning 6

  `reset`()

    Reset the formatter.

    By resetting, the next log message is guaranteed to be prepended by the string representation of the first argument of the log record.

    EXAMPLES:

        sage: from pGroupCohomology.auxiliaries import coho_logger
        sage: from pGroupCohomology import CohomologyRing
        sage: CohomologyRing.reset()
        sage: coho_logger.warning('message 1', ZZ)
        Integer Ring:
            message 1

    When we now log a message that is associated to the integer ring as well, then we just see the message, not the integer ring:

        sage: coho_logger.warning('message 2', ZZ)
            message 2

    But sometimes (in particular when other output has happened after logging the previous event), we want to see what object the log message belongs to:

        sage: CohomologyRing.reset()    # indirect doctest
        sage: coho_logger.warning('message 3', ZZ)
        Integer Ring:
            message 3

`pGroupCohomology.auxiliaries.` `safe_save`(obj, path)

  Save data after unlinking the target, if it is a symlink.

  EXAMPLES:

      sage: from pGroupCohomology.auxiliaries import safe_save
      sage: d = tmp_dir()
      sage: save(1, os.path.join(d, 'orig'))
      sage: os.symlink(os.path.join(d, 'orig.sobj'), os.path.join(d, 'copy.sobj'))

  By saving data to the symlink, we change the original data:

      sage: save(2, os.path.join(d, 'copy.sobj'))
      sage: load(os.path.join(d, 'orig.sobj'))
      2
      sage: load(os.path.join(d, 'copy.sobj'))
      2

  The function `safe_save()` protects the original data:

      sage: d = tmp_dir()
      sage: save(1, os.path.join(d, 'orig'))
      sage: os.symlink(os.path.join(d, 'orig.sobj'), os.path.join(d, 'copy.sobj'))
      sage: safe_save(2, os.path.join(d, 'copy.sobj'))
      sage: load(os.path.join(d, 'orig.sobj'))
      1
      sage: load(os.path.join(d, 'copy.sobj'))
      2

class `pGroupCohomology.auxiliaries.` `unpickle_old_mtx`

  Helper for old pickles of MTX matrices.

  It unpickles what was pickled with the old-style `p_group_cohomology` spkg. This holds, for example, for the data found in the database that is shipped with this optional package.

class `pGroupCohomology.auxiliaries.` `unpickle_old_resl`

  Helper for old pickles of `RESL`.

  It unpickles what was pickled with the old-style `p_group_cohomology` spkg.