
"Ic           @   s   d  Z  d d k Z d d k Z d d k Z y d d k Z e i Z Wn e j
 o d Z e	 Z n Xd   Z
 e d j o2 x/ e i d D] Z e
 e  p d Ge GHq Wn d S(   s0   Guess which db package to use to open a db file.iNc         C   s  yt t  |  t i d d  } | i   t i d j o t i d j p( t  |  t i d d  } | i   n d SWn t j
 ov yS t  |  t i d d  } | i   t d j	 o t i  |   } | i   d SWq t t
 f j
 o q Xn Xy t i |  t i d  t i |  t i d  i } | d	 j o d
 St  |  t i d d  } z | i d  d j o d
 SWd | i   XWn t t f j
 o n Xy t  |  d  } Wn t j
 o d SX| i d  } | i   | d	 d !} t |  d j o d Sy t i d |  \ } Wn t i j
 o d SX| d j o d S| d j o d Sy t i d | d  \ } Wn t i j
 o d SX| d j o d Sd S(   sg  Guess which db package to use to open a db file.

    Return values:

    - None if the database file can't be read;
    - empty string if the file can be read but can't be recognized
    - the module name (e.g. "dbm" or "gdbm") if recognized.

    Importing the given module may still fail, and opening the
    database using that module may still fail.
    t   pagt   rbs   GNU gdbmt   os2emxt   dirt   dbmt   dbt   dati    t   dumbdbmi   t   't   "Ni   i   t    s   =liΚWt   gdbmia i at   bsddb185it   dbhash(   R   R	   (   ia i a(   ia i a(   t   opent   ost   extsept   closeR   t   libraryt   syst   platformt   IOErrort   Nonet	   _dbmerrort   statt   st_sizet   readt   OSErrort   lent   structt   unpackt   error(   t   filenamet   ft   dt   sizet   s16t   st   magic(    (    s$   /mit/python/lib/python2.6/whichdb.pyt   whichdb   sj    
 

	
	
t   __main__i   t   UNKNOWN(   t   __doc__R   R   R   R   R   R   t   ImportErrorR   R   R'   t   __name__t   argvR    (    (    (    s$   /mit/python/lib/python2.6/whichdb.pyt   <module>   s   	b 