Ńņ Ź©MHc@sdZddkZdd„Zdd„Zdd„Zd„d„Zd„Zd efd „ƒYZ e d joddk Z e i ƒndS( s<Helpers that are neither text, numeric, container, or date. i’’’’NcCs"xti||ƒD]}tSWtS(s±Is ``pred(elm)`` true for all elements? With the default predicate, this is the same as Python 2.5's ``all()`` function; i.e., it returns true if all elements are true. >>> all(["A", "B"]) True >>> all(["A", ""]) False >>> all(["", ""]) False >>> all(["A", "B", "C"], lambda x: x <= "C") True >>> all(["A", "B", "C"], lambda x: x < "C") False From recipe in itertools docs. (t itertoolst ifilterfalsetFalsetTrue(tseqtpredtelm((s3/usr/lib/python2.6/site-packages/webhelpers/misc.pytallscCs"xti||ƒD]}tSWtS(sÆIs ``pred(elm)`` is true for any element? With the default predicate, this is the same as Python 2.5's ``any()`` function; i.e., it returns true if any element is true. >>> any(["A", "B"]) True >>> any(["A", ""]) True >>> any(["", ""]) False >>> any(["A", "B", "C"], lambda x: x <= "C") True >>> any(["A", "B", "C"], lambda x: x < "C") True From recipe in itertools docs. (RtifilterRR(RRR((s3/usr/lib/python2.6/site-packages/webhelpers/misc.pytanyscCs"xti||ƒD]}tSWtS(sqIs ``pred(elm)`` false for all elements? With the default predicate, this returns true if all elements are false. >>> no(["A", "B"]) False >>> no(["A", ""]) False >>> no(["", ""]) True >>> no(["A", "B", "C"], lambda x: x <= "C") False >>> no(["X", "Y", "Z"], lambda x: x <="C") True From recipe in itertools docs. (RRRR(RRR((s3/usr/lib/python2.6/site-packages/webhelpers/misc.pytno4scCs|S(((tx((s3/usr/lib/python2.6/site-packages/webhelpers/misc.pytJscCs6d}x)|D]!}||ƒo|d7}q q W|S(sMHow many elements is ``pred(elm)`` true for? With the default predicate, this counts the number of true elements. >>> count_true([1, 2, 0, "A", ""]) 3 >>> count_true([1, "A", 2], lambda x: isinstance(x, int)) 2 This is equivalent to the ``itertools.quantify`` recipe, which I couldn't get to work. ii((RRtretR ((s3/usr/lib/python2.6/site-packages/webhelpers/misc.pyt count_trueJs  cCs)y||ƒSWntj odSXdS(sęReturn the value converted to the type, or None if error. ``type_`` may be a Python type or any function taking one argument. >>> print convert_or_none("5", int) 5 >>> print convert_or_none("A", int) None N(t ExceptiontNone(tvaluettype_((s3/usr/lib/python2.6/site-packages/webhelpers/misc.pytconvert_or_none]s tDeclarativeExceptioncBs eZdZdZdd„ZRS(sUA simpler way to define an exception with a fixed message. Example: >>> class MyException(DeclarativeException): ... message="can't frob the bar when foo is enabled" ... >>> try: ... raise MyException() ... except Exception, e: ... print e ... can't frob the bar when foo is enabled tcCsti||p|iƒdS(N(Rt__init__tmessage(tselfR((s3/usr/lib/python2.6/site-packages/webhelpers/misc.pyR{sN(t__name__t __module__t__doc__RRR(((s3/usr/lib/python2.6/site-packages/webhelpers/misc.pyRks t__main__( RRRRR R RRRRRtdoctestttestmod(((s3/usr/lib/python2.6/site-packages/webhelpers/misc.pyts