pylib/uxml/uxpath/ast.py
def to_number(obj):
    '''
    Cast an arbitrary object or sequence to a number type
    '''
    if isinstance(obj, LiteralWrapper):
        val = obj.obj
    elif isinstance(obj, Iterable) and not isinstance(obj, str):
        val = next(obj, None)
    else:
        val = obj
    if val is None:
        #FIXME: Should be NaN, not 0
        yield 0
    elif isinstance(val, str):
        yield float(val)
    elif isinstance(val, node):
        yield float(strval(val))
    elif isinstance(val, int) or isinstance(val, float):
        yield val
    else:
        raise RuntimeError('Unknown type for number conversion: {}'.format(val))
def to_number(obj):
    '''
    Cast an arbitrary object or sequence to a number type
    '''
    if isinstance(obj, LiteralWrapper):
        val = obj.obj
    elif isinstance(obj, Iterable) and not isinstance(obj, str):
        val = next(obj, None)
    else:
        val = obj
    if val is None:
        #FIXME: Should be NaN, not 0
        yield 0
    elif isinstance(val, str):
        yield float(val)
    elif isinstance(val, node):
        yield float(strval(val))
    elif isinstance(val, int) or isinstance(val, float):
        yield val
    else:
        raise RuntimeError('Unknown type for number conversion: {}'.format(val))
def to_number ( obj ) : if isinstance ( obj , LiteralWrapper ) : val = obj . obj elif isinstance ( obj , Iterable ) and not isinstance ( obj , str ) : val = next ( obj , None ) else : val = obj if val is None : #FIXME: Should be NaN, not 0 yield 0 elif isinstance ( val , str ) : yield float ( val ) elif isinstance ( val , node ) : yield float ( strval ( val ) ) elif isinstance ( val , int ) or isinstance ( val , float ) : yield val else : raise RuntimeError ( 'Unknown type for number conversion: {}' . format ( val ) )
Cast an arbitrary object or sequence to a number type
Cast an arbitrary object or sequence to a number type