File:  [CENS] / python / pyGiNaC / lib4 / printer.py
Revision 1.3: download - view: text, annotated - select for diffs - revision graph
Sat Aug 18 19:10:17 2001 UTC (16 years, 3 months ago) by pearu
Branches: MAIN
CVS tags: HEAD
Impl. add,mul,power

#!/usr/bin/env python
"""
ginac.printer

to_string_arch(ex) - convert ex archive dictionary to string
"""
"""
  This file is part of the PyGiNaC package.
  http://cens.ioc.ee/projects/pyginac/

  $Revision: 1.3 $
  $Id: printer.py,v 1.3 2001-08-18 19:10:17 pearu Exp $
 
  Copyright 2001 Pearu Peterson all rights reserved,
  Pearu Peterson <pearu@cens.ioc.ee>
  Permission to use, modify, and distribute this software is given under the
  terms of the LGPL.  See http://www.fsf.org
 
  NO WARRANTY IS EXPRESSED OR IMPLIED.  USE AT YOUR OWN RISK.
"""

import types

def _to_string_arch(d):
    if type(d) is not types.DictType:
        return repr(d)
    r = d['class'] + '('
    fl = 0
    for k,v in d.items():
        if k == 'class':
            continue
        if fl:
            r += ', '
        else:
            fl = 1
        r += k + ' = '
        t = type(v)
        if t is types.ListType:
            if len(v) > 1:
                r += '['
            fl1 = 0
            for a in v:
                if fl1:
                    r += ', '
                else:
                    fl1 = 1
                r += _to_string_arch(a)
            if len(v) > 1:
                r += ']'
        else:
            r += _to_string_arch(v)
    r += ')'
    return r

def to_string_arch(expr):
    """Return string representation of expr archive dictionary."""
    return _to_string_arch(expr.extract_archived(-1))




FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>