
xFWgc           @   s   d  Z  d d l m Z m Z e Z d Z e d  Z d   Z	 d   Z
 e d  Z e d d	  Z d
   Z d   Z d   Z d S(   s   Various utility functions.i(   t
   namedtuplet   OrderedDictiP   c         C   s\   y t  |   } Wn  t k
 r2 t j |   } n X| sL t |  t k  rP | S| t  d S(   Ns    [truncated]...(   t   reprt	   Exceptiont   objectt   __repr__t   lent   _MAX_LENGTH(   t   objt   shortt   result(    (    s#   /usr/lib/python2.7/unittest/util.pyt	   safe_repr   s    c         C   s   d |  j  |  j f S(   Ns   %s.%s(   t
   __module__t   __name__(   t   cls(    (    s#   /usr/lib/python2.7/unittest/util.pyt   strclass   s    c         C   sh  d } } g  } g  } xEt  r]y|  | } | | } | | k  r} | j |  | d 7} x |  | | k ry | d 7} q\ Wn | | k r | j |  | d 7} x | | | k r | d 7} q Wn^ | d 7} z% x |  | | k r | d 7} q WWd | d 7} x | | | k r | d 7} qWXWq t k
 rY| j |  |  | j | |  Pq Xq W| | f S(   sr  Finds elements in only one or the other of two, sorted input lists.

    Returns a two-element tuple of lists.    The first list contains those
    elements in the "expected" list but not in the "actual" list, and the
    second contains those elements in the "actual" list but not in the
    "expected" list.    Duplicate elements in either input list are ignored.
    i    i   N(   t   Truet   appendt
   IndexErrort   extend(   t   expectedt   actualt   it   jt   missingt
   unexpectedt   et   a(    (    s#   /usr/lib/python2.7/unittest/util.pyt   sorted_list_difference   s:    
	





	c         C   s  g  } g  } x |  r |  j    } y | j |  Wn t k
 rR | j |  n X| r xI |  | f D]8 } y x t r | j |  qr WWqf t k
 r qf Xqf Wq q W| rxU | r| j    } | j |  y x t r | j |  q WWq t k
 rq Xq W| | f S| | f S(   s   Same behavior as sorted_list_difference but
    for lists of unorderable items (like dicts).

    As it does a linear search per item (remove) it
    has O(n*n) performance.
    (   t   popt   removet
   ValueErrorR   R   (   R   R   t   ignore_duplicateR   R   t   itemt   lst(    (    s#   /usr/lib/python2.7/unittest/util.pyt   unorderable_list_difference>   s4    				
t   Mismatchs   actual expected valuec         C   s  t  |   t  |  } } t |  t |  } } t   } g  } x t |  D] \ } }	 |	 | k rl qN n  d }
 } x> t | |  D]- } | | |	 k r |
 d 7}
 | | | <q q Wx= t |  D]/ \ } } | |	 k r | d 7} | | | <q q W|
 | k rN t |
 | |	  } | j |  qN qN Wx t |  D] \ } }	 |	 | k rTq6n  d } x> t | |  D]- } | | |	 k rj| d 7} | | | <qjqjWt d | |	  } | j |  q6W| S(   sH   Returns list of (cnt_act, cnt_exp, elem) triples where the counts differi    i   (   t   listR   R   t	   enumeratet   ranget	   _MismatchR   (   R   R   t   st   tt   mt   nt   NULLR
   R   t   elemt   cnt_st   cnt_tR   t
   other_elemt   diff(    (    s#   /usr/lib/python2.7/unittest/util.pyt   _count_diff_all_purposed   s<    	



c         C   s8   t    } x( |  D]  } | j | d  d | | <q W| S(   s@   Return dict of element counts, in the order they were first seeni    i   (   R   t   get(   t   iterablet   cR.   (    (    s#   /usr/lib/python2.7/unittest/util.pyt   _ordered_count   s    	c   	      C   s   t  |   t  |  } } g  } xZ | j   D]L \ } } | j | d  } | | k r, t | | |  } | j |  q, q, WxH | j   D]: \ } } | | k r t d | |  } | j |  q q W| S(   sH   Returns list of (cnt_act, cnt_exp, elem) triples where the counts differi    (   R7   t   itemsR4   R(   R   (	   R   R   R)   R*   R
   R.   R/   R0   R2   (    (    s#   /usr/lib/python2.7/unittest/util.pyt   _count_diff_hashable   s    N(   t   __doc__t   collectionsR    R   R   t
   __unittestR   t   FalseR   R   R   R#   R(   R3   R7   R9   (    (    (    s#   /usr/lib/python2.7/unittest/util.pyt   <module>   s   
		)$	#	