LeenO computo metrico con LibreOffice
3.22.0
Il software libero per la gestione di computi metrici e contabilità lavori.
_SRC
leeno
src
Ultimus.oxt
python
pythonpath
PersistUtils.py
Vai alla documentazione di questo file.
1
'''
2
some not-too-complicated persistence methods
3
'''
4
from
datetime
import
date
5
import
LeenoUtils
6
7
_TYPEMAP = {
8
str:
lambda
x :
'(str)'
+ x,
9
int:
lambda
x :
'(int)'
+ str(x),
10
float:
lambda
x :
'(float)'
+ str(x),
11
date:
lambda
x :
'(date)'
+
LeenoUtils.date2String
(x, 1),
12
bool:
lambda
x :
'(bool)'
+ str(x)
13
}
14
15
_TYPENAMEMAP = {
16
'str'
: str,
17
'int'
: int,
18
'float'
: float,
19
'date'
: LeenoUtils.string2Date,
20
'bool'
:
lambda
x :
True
if
x ==
'True'
else
False
,
21
}
22
23
24
def
string2var
(s):
25
'''
26
convert the string-format data (type)xxxxxx to
27
its value equivalent
28
examples : (int)5 --> 5
29
(date)25/02/2020 --> date(2020, 02, 25)
30
'''
31
if
not
s.startswith(
'('
):
32
return
None
33
closePos = s.find(
')'
)
34
if
closePos < 0:
35
return
None
36
typ = s[1:closePos]
37
if
not
typ
in
_TYPENAMEMAP:
38
return
None
39
return
_TYPENAMEMAP[typ](s[closePos+1:])
40
41
def
var2string
(var):
42
'''
43
convert the variable var to a storable string
44
'''
45
if
not
type(var)
in
_TYPEMAP :
46
return
None
47
return
_TYPEMAP[type(var)](var)
PersistUtils.string2var
def string2var(s)
Definition:
PersistUtils.py:24
PersistUtils.var2string
def var2string(var)
Definition:
PersistUtils.py:41
LeenoUtils.date2String
def date2String(dat, fmt=0)
Definition:
LeenoUtils.py:189
Generato da
1.8.16