Package qubx :: Module accept
[hide private]
[frames] | no frames]

Module accept

source code

Functions for parsing strings into various data types, ranging from string (a no-op) to a system of differential equations.

An "accept" function takes a string, and returns a value of the desired type. If the conversion is impossible, it raises a descriptive exception.

Accept functions are used to validate input in various components in qubx.GTK and qubx.tables.

Copyright 2007-2014 Research Foundation State University of New York This file is part of QUB Express.

QUB Express 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 3 of the License, or (at your option) any later version.

QUB Express 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, named LICENSE.txt, in the QUB Express program directory. If not, see <http://www.gnu.org/licenses/>.

Classes [hide private]
  FieldAcceptException
  FuncAcceptor
FuncAcceptor instance is callable as fa(x, custom1, custom2, ...).
  ODEAcceptor
Functions [hide private]
 
acceptNothing(x) source code
 
acceptEval(typ=<type 'float'>) source code
 
acceptString(x) source code
 
acceptStringNonempty(x) source code
 
acceptInt(x) source code
 
acceptFloat(x) source code
 
acceptFloatNonzero(x) source code
 
acceptXorUnset(accept)
Interprets '' as UNSET_VALUE, otherwise uses provided accept function.
source code
 
acceptFloatOrUnset(x)
Like acceptFloat, but acceptFloatOrUnset('') returns qubx.util_types.UNSET_VALUE.
source code
 
formatFloatOrUnset(fmt)
Returns f(val): if val != qubx.util_types.UNSET_VALUE: return fmt(val); else: return ''
source code
 
acceptBool(x)
Returns False if x is in ['', 'False', 'false']; True otherwise.
source code
 
acceptCmp(convert, compare, errmsg)
Returns an accept function which enforces `compare(convert(s)) == True.
source code
 
errmsg_cmp(cmpname) source code
 
errmsg_gt(typename, bound) source code
 
errmsg_ge(typename, bound) source code
 
errmsg_lt(typename, bound) source code
 
errmsg_le(typename, bound) source code
 
acceptIntGreaterThan(lb) source code
 
acceptIntGreaterThanOrEqualTo(lb) source code
 
acceptIntLessThan(ub) source code
 
acceptIntLessThanOrEqualTo(ub) source code
 
acceptIntBetween(lb, ub) source code
 
acceptFloatGreaterThan(lb) source code
 
acceptFloatGreaterThanOrEqualTo(lb) source code
 
acceptFloatLessThan(ub) source code
 
acceptFloatLessThanOrEqualTo(ub) source code
 
acceptFloatBetween(lb, ub) source code
 
acceptFloatAbsBetween(lb, ub) source code
 
acceptAcceptList(s, accept, dashrange, description)
e.g.
source code
 
acceptList(acceptor, dashrange, description) source code
 
acceptIntList(acceptor=<__builtin__.function object>, description='integers') source code
 
acceptFloatList(acceptor=<__builtin__.function object>, description='numbers') source code
 
acceptDimList(acceptList, dim, msg) source code
 
formatList(fmt=<type 'str'>) source code
 
proper_minus(s) source code
 
MissingName(msg)
Returns the symbol named in a NameError's message.
source code
 
acceptF(static=['x'], avail=[], custom=False, typ=<type 'float'>, default='1.0', locals=None)
Returns an accept function which converts a Python expression into a FuncAcceptor
source code
 
any_type(x) source code
 
Union(ls)
Given an iterable of subiterables, returns a list of unique elements in the subiterables.
source code
 
acceptODEs(static=['x'], avail=[], custom=False, locals=None)
Returns an accept function which converts a string of ODEs into a ODEAcceptor.
source code
 
acceptODEorF(static=['x'], avail=[], custom=False, locals=None)
Returns an accept function which acts like acceptODEs if ' is present, otherwise like acceptF.
source code
 
acceptFormat(format)
Returns a function which converts something to a string.
source code
Variables [hide private]
  name_int = 'an integer'
  name_float = 'a number'
  __package__ = 'qubx'
  e = 2.71828182846
  pi = 3.14159265359
  rdbk = 'Expired.'
  rdbreak = 'supporting'
  rdname = 'qubfast.txt'
Function Details [hide private]

acceptCmp(convert, compare, errmsg)

source code 

Returns an accept function which enforces `compare(convert(s)) == True.

Parameters:
  • errmsg - string for complaining

acceptAcceptList(s, accept, dashrange, description)

source code 

e.g. '1, 2, 3-5 7' -> [1, 2, 3, 4, 5, 7]

acceptF(static=['x'], avail=[], custom=False, typ=<type 'float'>, default='1.0', locals=None)

source code 

Returns an accept function which converts a Python expression into a FuncAcceptor

Parameters:
  • static - names arguments which are always present
  • avail - names which are added to args if they are in the expression
  • custom - whether to add unrecognized names to args, or re-raise the NameError
  • typ - desired result type
  • default - expression to use in place of ''
  • locals - optional dictionary of stuff avail in expr

acceptODEs(static=['x'], avail=[], custom=False, locals=None)

source code 

Returns an accept function which converts a string of ODEs into a ODEAcceptor.

Parameters:
  • static - names arguments which are always present
  • avail - names which are added to args if they are in the expression
  • custom - whether to add unrecognized names to args, or re-raise the NameError
  • locals - optional dictionary of stuff avail in expr

    The expression can have one or more ODEs separated by ';'. Each ODE has the form

    >>> "foo' = do_something(foo, bar)"

    For example, a sinusoidal:

    >>> "a' = b; b' = -a"

acceptFormat(format)

source code 

Returns a function which converts something to a string. If format is callable, it's returned back unchanged. Otherwise we assume it's a format string e.g. "%.8g", and the returned function is lambda val: format % val.