/usr/share/pyshared/Noyau/N_utils.py is in eficas 2.0.3-1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | #@ MODIF N_utils Noyau DATE 11/05/2010 AUTEUR COURTOIS M.COURTOIS
# -*- coding: iso-8859-1 -*-
# RESPONSABLE COURTOIS M.COURTOIS
# CONFIGURATION MANAGEMENT OF EDF VERSION
# ======================================================================
# COPYRIGHT (C) 1991 - 2002 EDF R&D WWW.CODE-ASTER.ORG
# THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
# IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
# THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
# (AT YOUR OPTION) ANY LATER VERSION.
#
# THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
# WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
# GENERAL PUBLIC LICENSE FOR MORE DETAILS.
#
# YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
# ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
# 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
#
#
# ======================================================================
"""
Ce module contient des fonctions utilitaires
"""
# Modules Python
import sys
# Modules EFICAS
from N_Exception import AsException
from N_types import is_int, is_float, is_complex, is_str, is_enum, is_assd
SEP='_'
try:
# Si la version de Python possède la fonction _getframe
# on l'utilise.
cur_frame=sys._getframe
except:
# Sinon on l'émule
def cur_frame(offset=0):
""" Retourne la frame d execution effective eventuellement en remontant
de offset niveaux dans la pile d execution
Si il y a moins de offset niveaux retourne None
"""
try:1/0
except:
frame=sys.exc_info()[2].tb_frame.f_back
while offset > 0:
if frame == None:return None
frame=frame.f_back
offset=offset-1
return frame
def callee_where(niveau=4):
"""
recupere la position de l appel
"""
frame=cur_frame(niveau)
if frame == None: return 0,"inconnu",0,{}
try:
return frame.f_lineno,frame.f_code.co_filename,frame.f_code.co_firstlineno,frame.f_locals
except:
return 0,"inconnu",0,{}
def AsType(a):
"""
Retourne le type d'un concept (a) à partir
des caractéristiques de l'objet Python
"""
if is_enum(a): return AsType(a[0])
if is_assd(a): return type(a)
if is_float(a): return "R"
if is_int(a): return "I"
if is_str(a): return "TXM"
if a == None: return None
print 'a=', a, type(a)
raise AsException("type inconnu")
def prbanner(s):
print "*"*(len(s)+10)
print "*"*5 + s + "*"*5
print "*"*(len(s)+10)
def repr_float(valeur):
"""
Cette fonction représente le réel valeur comme une chaine de caractères
sous forme mantisse exposant si nécessaire cad si le nombre contient plus de
5 caractères
NB : valeur est un réel au format Python ou une chaine de caractères représentant un réel
"""
if type(valeur) == str : valeur = eval(valeur)
if valeur == 0. : return '0.0'
if abs(valeur) > 1. :
if abs(valeur) < 10000. : return repr(valeur)
else :
if abs(valeur) > 0.01 : return repr(valeur)
t=repr(valeur)
if t.find('e') != -1 or t.find('E') != -1 :
# le réel est déjà sous forme mantisse exposant !
# --> on remplace e par E
t=t.replace('e','E')
# --> on doit encore vérifier que la mantisse contient bien un '.'
if t.find('.')!= -1:
return t
else:
# -->il faut rajouter le point avant le E
t=t.replace('E','.E')
return t
s=''
neg = 0
if t[0]=='-':
s=s+t[0]
t=t[1:]
cpt = 0
if t[0].atof() == 0.:
# réel plus petit que 1
neg = 1
t=t[2:]
cpt=1
while t[0].atof() == 0. :
cpt = cpt+1
t=t[1:]
s=s+t[0]+'.'
for c in t[1:]:
s=s+c
else:
# réel plus grand que 1
s=s+t[0]+'.'
if t[1:].atof() == 0.:
l=t[1:].split('.')
cpt = len(l[0])
else:
r=0
pt=0
for c in t[1:]:
r=r+1
if c != '.' :
if pt != 1 : cpt = cpt + 1
s=s+c
else:
pt = 1
if r+1 == len(t) or t[r+1:].atof() == 0.:break
s=s+'E'+neg*'-'+repr(cpt)
return s
|