mò
f¾oBc           @   s¡  d  Z  d Z d Z y e Wn d \ Z Z n Xy| d k Z d k Z d k Z d k Z d k	 Z	 e i
 i e i i e	 i e i ƒ  ƒ d d d g ƒ ƒ d	 k l Z l Z Wn1 y e i i d
 e ƒ Wn e GHn X‚  n Xe i d i e i ƒ d Z e i i e i d i e i ƒ d d !ƒ Z e i ƒ  d Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d e  f d „  ƒ  YZ! e" d j o e ƒ  n d S(   sÚ   arcane tricks and other useful routines

   things that may or may not fit well in other libs but need to be
   put somewhere so I don't spend a half hour to figure them out again
   every time I need the functionalitysF  
    arcane - tricky or not-so-tricky little routines for various porpoises
    Copyright (C) 2004  John Comeau <jc@jcomeau.com>

    This program 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 2 of the License, or
    (at your option) any later version.

    This program 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
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    s5   Not all needed libraries found, upgrade or check pathi   i    Ni   t   libt   python(   s   gpls	   jclicenses   %s
iÿÿÿÿc          G   s   d  S(   N(    (   t   whatever(    (    t&   /cygdrive/m/home/jcomeau/src/arcane.pyt
   DebugPrint3   s    c           C   s   t  i i d ƒ d S(   s-   just in case someone called this as a programs   wtf do you think you're doing?
N(   t   syst   stderrt   write(    (    (    R   t   wtf6   s     c         C   s"   t  t d |  i ƒ  |  i ƒ  ƒ ƒ S(   s¼   reverses a dictionary whose values are all unique

    in other words, returns a new dictionary whose keys are the values of
    the original, and whose values are the keys of the originalN(   t   dictt   mapt   Nonet
   Dictionaryt   valuest   keys(   R   (    (    R   t   ReverseDict:   s     c          G   sH   t  |  ƒ d j o
 d }  n |  d }  t i i |  ƒ t i i ƒ  d  S(   Ni    s   Hit <ENTER> to continue...(   t   lent   PromptR   R   R   t   stdint   readline(   R   (    (    R   t   pauseA   s
    

c            s1   t  ‡  d †  | ƒ } | i d „  ƒ ˆ  | d S(   s;   returns the item in the list Items which is closest to Itemc            s   |  ˆ  S(   N(   t   it   Item(   R   (   R   (    R   t   <lambda>K   s    c         C   s   t  t |  ƒ t | ƒ ƒ S(   N(   t   cmpt   absR   t   j(   R   R   (    (    R   R   L   s    i    N(   R
   t   Itemst   modifiedt   sortR   (   R   R   R   (    (   R   R   t   NearestValueI   s     c            sB   t  ‡  d †  | ƒ } t | ƒ } | i d „  ƒ | i | d ƒ S(   s/   returns index in Items of nearest value to Itemc            s   |  ˆ  S(   N(   R   R   (   R   (   R   (    R   R   Q   s    c         C   s   t  t |  ƒ t | ƒ ƒ S(   N(   R   R   R   R   (   R   R   (    (    R   R   S   s    i    N(   R
   R   R   t   listt	   reorderedR   t   index(   R   R   R    R   (    (   R   R   t   NearestValueIndexO   s
     t	   countdictc           B   s   t  Z d  Z d „  Z RS(   sD   useful subclass for counting, initializes unknown keys to value of 0c         C   s8   y t  t |  ƒ i | ƒ SWn t j
 o d Sn Xd  S(   Ni    (   t   superR#   t   selft   __getitem__t   keyt   KeyError(   R%   R'   (    (    R   R&   X   s    (   t   __name__t
   __module__t   __doc__R&   (    (    (    R   R#   V   s    t   __main__(   i   i    (#   R+   t	   Copyrightt   errormessaget   Truet   FalseR   t   ost   typest   ret   pwdt   patht   appendt   sept   joint   getpwuidt   geteuidt   com.jcomeaut   gplt	   jclicenseR   R   t   argvt   splitR%   t   mypatht   originalselfR   R   R   R   R   R"   R	   R#   R)   (   R-   R   R   R<   R   R%   R3   R   R"   R/   RA   R#   R   R4   R   R2   R0   R.   R=   R@   R1   (    (    R   t   ?   s8   -8	,						