³ņ
Je|Mc           @   s  d  Z  d d k Z d d k Z d d k Z d d k Z d d  Z d d  Z d d  Z d   d  Z	 d   Z
 d	   Z d d
  Z d e f d     YZ d e f d     YZ d e f d     YZ d d  Z e d d  Z e d j o d d k Z e i   n d S(   s<   Helpers that are neither text, numeric, container, or date.
i’’’’Nc         C   s%   x t  i | |   D]
 } t Sq Wt S(   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   ifilterfalset   Falset   True(   t   seqt   predt   elm(    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/misc.pyt   all	   s     c         C   s%   x t  i | |   D]
 } t Sq Wt S(   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.
    (   R    t   ifilterR   R   (   R   R   R   (    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/misc.pyt   any    s     c         C   s%   x t  i | |   D]
 } t Sq Wt S(   sq  Is ``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.
    (   R    R   R   R   (   R   R   R   (    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/misc.pyt   no7   s     c         C   s   |  S(    (    (   t   x(    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/misc.pyt   <lambda>M   s    c         C   s6   d } x) |  D]! } | |  o | d 7} q q W| S(   sM  How 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.
    i    i   (    (   R   R   t   retR   (    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/misc.pyt
   count_trueM   s     c         C   s,   y | |   SWn t  j
 o d Sn Xd S(   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	   Exceptiont   None(   t   valuet   type_(    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/misc.pyt   convert_or_none`   s    
c         c   sP   xI |  D]A } t  | t t f  o  x" t |  D] } | Vq0 Wq | Vq Wd S(   s°   Recursively iterate lists and tuples.

    Examples:

    >>> list(flatten([1, [2, 3], 4]))
    [1, 2, 3, 4]
    >>> list(flatten([1, (2, 3, [4]), 5]))
    [1, 2, 3, 4, 5]
    N(   t
   isinstancet   listt   tuplet   flatten(   t   iterableR   t   relm(    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/misc.pyR   o   s    
  c         C   s    t  | t  o | i   } n t t i f } |  g } | o | i |  n g  } | D]> } t  | |  o( t | |   o | | j o | | q[ q[ ~ S(   sv  Extract the subclasses of a class from a module, dict, or iterable.

    Return a list of subclasses found. The class itself will not be included.
    This is useful to collect the concrete subclasses of an abstract base
    class.

    ``class_`` is a class.

    ``it`` is a dict or iterable. If a dict is passed, examine its values,
    not its keys. To introspect the current module, pass ``globals()``. To
    introspect another module or namespace, pass
    ``vars(the_module_or_namespace)``.

    ``exclude`` is an optional list of additional classes to ignore. 
    This is mainly used to exclude abstract subclasses.
    (   R   t   dictt
   itervaluest   typet   typest	   ClassTypet   extendt
   issubclass(   t   class_t   itt   excludet   class_typest   ignoret   _[1]R   (    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/misc.pyt   subclasses_only   s    	!t   NotGivenc           B   s   e  Z d  Z RS(   s"  A default value for function args.

    Use this when you need to distinguish between ``None`` and no value.
    
    Example::
    
        >>> def foo(arg=NotGiven):
        ...     print arg is NotGiven
        ...
        >>> foo()
        True
        >>> foo(None)
        False

    (   t   __name__t
   __module__t   __doc__(    (    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/misc.pyR(      s   t   DeclarativeExceptionc           B   s    e  Z d  Z d Z d d  Z RS(   s  A simpler way to define an exception with a fixed message.

    Subclasses have a class attribute ``.message``, which is used if no
    message is passed to the constructor. The default message is the empty
    string.

    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
    t    c         C   s   t  i |  | p |  i  d  S(   N(   R   t   __init__t   message(   t   selfR/   (    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/misc.pyR.   Å   s    N(   R)   R*   R+   R/   R   R.   (    (    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/misc.pyR,   °   s   t   OverwriteErrorc           B   s   e  Z d  Z d d  Z RS(   s4   Refusing to overwrite an existing file or directory.s   not overwriting '%s'c         C   s*   | | f ;} t  i |  |  | |  _ d  S(   N(   R   R.   t   filename(   R0   R2   R/   (    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/misc.pyR.   Ģ   s    (   R)   R*   R+   R.   (    (    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/misc.pyR1   É   s   c         C   sR   |  o t  |   } n t i   d  \ } }  t i | |   } d i |  i   S(   sµ  Format the exception type and value for display, without the traceback.

    This is the function you always wished were in the ``traceback`` module but
    isn't. It's *different* from ``traceback.format_exception``, which includes
    the traceback, returns a list of lines, and has a trailing newline.

    If you don't provide an exception object as an argument, it will call
    ``sys.exc_info()`` to get the current exception.
    i   R-   (   R   t   syst   exc_infot	   tracebackt   format_exception_onlyt   joint   rstrip(   t   exct   exc_typet   lines(    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/misc.pyt   format_exceptionŃ   s
    
i   c         C   s+   | o t  p t } t i |  | |  d S(   s·  Issue a deprecation warning.

    ``message``: the deprecation message.

    ``pending``: if true, use ``PendingDeprecationWarning``. If false (default), 
    use ``DeprecationWarning``. Python displays deprecations and ignores
    pending deprecations by default.

    ``stacklevel``: passed to ``warnings.warn``. The default level 2 makes the
    traceback end at the caller's level. Higher numbers make it end at higher
    levels.
    N(   t   PendingDeprecationWarningt   DeprecationWarningt   warningst   warn(   R/   t   pendingt
   stacklevelt   category(    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/misc.pyt	   deprecateā   s    t   __main__(   R+   R    R5   R   R?   R   R   R	   R
   R   R   R   R'   t   objectR(   R   R,   R1   R<   R   RD   R)   t   doctestt   testmod(    (    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/misc.pys   <module>   s&   		