src/cm/utils/__init__.py
author gibus
Wed, 27 Mar 2013 17:51:18 +0100
changeset 502 8ec189cc214d
parent 0 40c8f766c9b8
permissions -rw-r--r--
do not skip span for newline textnodes otherwise compute_new_comment_positions() will return bad results for pandoc texts.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     1
def get_among(dico,key,allowed,default):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     2
    res = dico.get(key, None)
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     3
    if not res or res not in allowed:
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     4
        return default
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     5
    else:
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     6
        return res
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     7
        
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     8
        
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     9
def get_int(dico, key, default):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    10
    try:
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    11
        return int(dico.get(key, default))
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    12
    except ValueError:
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    13
        return default