-í
›KX;c    
   s6    d  Z    d k Z  d k Z  d k Z  d k Z d k Z d k Z d k Z d k Z  d Z	  y  e i
 d d ƒ Z Wn"  e i j
 o  d Z n X! y " e i
 d d ƒ Z Wn" # e i j
 o $ d Z n X' d d	 d
 d d d d d d d f
 Z 4 h  d d <d d	 <d d <d d <d d <d d <d d <d d
 <d d <d d <Z A d f Z F d e i f d „  ƒ  YZ M d Z V e i e ƒ Z X d  „  Z w e i e i e i e i e e i e i e e i d! „	 Z ³ e i d" „ Z Ä e d# e i e e i e i e i d$ „ Z  ö d a! ÷ d% a" ø d& a# û g  Z$ ü d' Z% þ d e i e i& e i' e$ d( „ Z' 1e' Z( 3d e i) e' d) „ Z) ?e) Z* Cd* „  Z+ Sd' e i' e  e i d+ „ Z, rd, „  Z- d- d. „ Z. —e% e$ d/ „ Z/ °d0 „  Z0 Âe0 Z1 Äd1 „  Z2 d S(2   sP   Access routines to the NIST Network Time Services.

    This module allows you to access the UTC standard time bases via
    the Internet. The two functions localtime() and gmtime() will
    return accurate DateTime instances based on the NIST services.

    Since access through the Internet can be slow, the module also
    provides a way to calibrate the computer's clock and then have
    localtime() and gmtime() use the calibrated clock instead of the
    NIST services. To calibrate the two functions, call calibrate()
    with the number of calibration rounds you wish to apply.

    Copyright (c) 2000, Marc-Andre Lemburg; mailto:mal@lemburg.com
    Copyright (c) 2000-2001, eGenix.com Software GmbH; mailto:info@egenix.com
    See the documentation for further information on copyrights,
    or contact the author. All Rights Reserved.

Ni    s   daytimes   tcpi   s   timei%   s   time.nist.govs   time-a.nist.govs   time-b.nist.govs   time-nw.nist.govs   time-a.timefreq.bldrdoc.govs   time-b.timefreq.bldrdoc.govs   time-c.timefreq.bldrdoc.govs   utcnist.colorado.edus   utcnist1.reston.mci.nets   nist1.datum.coms   204.70.131.13s   129.6.16.35s   132.163.135.132s   132.163.135.130s
   209.0.72.7s   131.107.1.10s   132.163.135.131s   129.6.16.36s   192.43.244.18s   128.138.140.44s&   http://time-a.timefreq.bldrdoc.gov:14/s   Errorc      s   F t  Z G RS(   N(   s   __name__s
   __module__(    (    (    s:   /mit/seven/lib/python2.2/site-packages/mx/DateTime/NIST.pys   ErrorF s   	s·   (?P<mjd>\d+) (?P<date>\d+-\d\d-\d\d) (?P<hour>\d?\d):(?P<minute>\d\d):(?P<second>\d\d) (?P<dst>\d\d) (?P<leap>\d) (?P<health>\d) (?P<msadv>\d+(?:\.\d+)?) (?P<label>[\w()]+) (?P<otm>.)c    sù   X d e t  i |  ƒ } f | o g t d |  ‚ n h | i ƒ  } i t | ƒ } j x“ t t	 | ƒ ƒ Dj ]| } k | | } l y m t | ƒ | | <WnL n t j
 o= o y p t | ƒ | | <Wn q t j
 o
 r n Xn Xqk Ws | Sd S(   sS   Returns a sequence representing the parsed information in daytime.

        The sequence has the following format:
          [mjd,date,hour,minute,second,dst,leap,health,msadv,label,otm]

        Numbers are converted to numbers. Entries may be None.

        Raises a ValueError is the daytime information cannot be
        parsed.

    s   unkown daytime format: "%s"N(   s
   _daytimeREs   matchs   daytimes   ms
   ValueErrors   groupss   lists   ls   ranges   lens   is   values   ints   float(   s   daytimes   is   ms   ls   values   groups(    (    s:   /mit/seven/lib/python2.2/site-packages/mx/DateTime/NIST.pys   _parse_datetimeX s"    	c    s"  w ‡ ‰ |  } Š |
 i | ƒ o ‹ |
 | }  nD  y Ž | | ƒ }  Wn  |	 j
 o ‘ t Sn X“ |  |
 | <” | | | ƒ } – | i d ƒ — x^— d oS˜ y ™ | i |  | f ƒ } Wn9 š |	 j
 o* } › t o › d | GHn œ t Sn X t o  d t i | GHn ž | | j o¿   | g  | g g  | ƒ \ } } } ¡ | on £ | i d ƒ ¤ y ¥ | i |  | f ƒ } Wn8 ¦ |	 j
 o) } ¨ t o ¨ d | GHn © qž n Xn  « t o « d GHn ¬ d } n ­ Pqž W® | d j o ¯ t Sn ± | Sd S(   sñ    Connect to the given host and port and return a socket
        instance.

        timeout states the number of seconds to wait for the
        connection to be established.

        In case no connection is possible, None is returned.

    i    i   s
    error: %ss    received %ss    timeoutiÿÿÿÿN(   s   hosts   hostnames   ip_caches   has_keys   gethostbynames   errors   Nones   sockets   AF_INETs   SOCK_STREAMs   ss   setblockings
   connect_exs   DAYTIME_PORTs   rcs   whys   _debugs   errnos	   errorcodes   EINPROGRESSs   selects   timeouts   rs   ws   e(   s   hosts   ports   timeouts   sockets   AF_INETs   SOCK_STREAMs   selects   DAYTIME_PORTs   EINPROGRESSs   errors   ip_caches   gethostbynames   ws   rcs   whys   es   hostnames   ss   r(    (    s:   /mit/seven/lib/python2.2/site-packages/mx/DateTime/NIST.pys   _connectw sL   	 

 
 $

 
 	c    si   ³ ¼ ½ | |  g g  g  | ƒ \ } } } ¾ | o ¿ |  i | ƒ Sn Á t o Á d GHn Â t	 Sd S(   s¶    Read size at most bytes from socket.

        timeout defines the amount of time to wait for data to become
        available. In case this time is exceeded, None is returned.

    s    read timeoutN(
   s   selects   sockets   timeouts   rs   ws   es   recvs   sizes   _debugs   None(   s   sockets   sizes   timeouts   selects   rs   es   w(    (    s:   /mit/seven/lib/python2.2/site-packages/mx/DateTime/NIST.pys   _read³ s   	$

 i   c    s‡  Ä × Ø t  o Ø d GHn Ù x"|  DÙ ]}
 Ú t  o Ú d |
 GHn Û t |
 t | ƒ } Ü | oÌ Ý t | d d ƒ } Þ | t	 j o
 ß q& n à | | ƒ }	 á | ƒ  } â | i ƒ  ã t  o ã d |	 GHn ä y å | |	 ƒ }	 Wn æ t j
 o ç q& n Xé |	 d d j o
 ê q& n ë Pn q& Wí t d ‚ ï | |	 d ƒ | |	 d	 |	 d
 |	 d |	 d d ƒ | f Sd S(   s   Scans the given (NIST) daytime servers and returns a tuple:

        (DateTime instance representing the current UTC day time,
        ticks value of the time when the day time information was
        received)

        daytime_servers must be a list of servers providing the
        daytime protocol. They can be given by name or IP.

        timeout is used as timeout when connecting to each server.  It
        must be given in seconds. The total timeout depends on the
        number of servers listed in daytime_servers.

    s   Contacting NIST servers...s   Trying server: %si   f0.5s    read %si   i    s*   could not get accurate daytime informationi   i   i   i   f0.001N(   s   _debugs   daytime_serverss   hosts   _connects   DAYTIME_PORTs   timeouts   ss   _reads   datas   Nones   strips   daytimes   times	   timestamps   closes   _parse_datetimes
   ValueErrors   Errors   DateTimeFromMJDs   Time(   s   daytime_serverss   timeouts   strips   _parse_datetimes   DateTimeFromMJDs   Times   times	   timestamps   ss   daytimes   hosts   data(    (    s:   /mit/seven/lib/python2.2/site-packages/mx/DateTime/NIST.pys   _get_daytimeÄ s4   
 
 	
 


 
i   f0.0i
   c 
   s  þ  |  p t oÔ !y” "t | ƒ t j o #t ƒ  n $t ƒ  \ } } %| ƒ  } &| | i } '| ƒ  | }	 (| |	 } )| i | ƒ *| | |	 ƒ SWn6 +t j
 o' ,|  d j o -t d ‚ n n Xn .| | ƒ  t ƒ Sd S(   s©   Returns the current UTC time as DateTime instance.

        Works must like the standard DateTime.now(), but tries to use
        the NIST time servers as time reference -- not only the
        computer's builtin clock.

        Note that the contructor may take several seconds to return in
        case no calibration was performed (see calibrate()). With
        calibration information, the computer's clock is used as
        reference and the offset to NIST time is compensated by the
        contructor.

        In case the NIST service is not reachable, the contructor
        falls back to using either the calibrated or uncalibrated
        computer's clock.

        Setting nist_lookup to false (default) will cause the
        contructor to prefer the calibrated CPU time over the
        expensive Internet queries. If it is true, then Internet
        lookups are always tried first before using the local clock. A
        value of 2 will cause an Error to be raised in case the NIST
        servers are not reachable.

        The constructor will use the NIST information for auto
        calibration, unless an explicit call to calibrate() takes care
        of this.

    i   s!   could not connect to NIST serversN(   s   nist_lookups   calibratings   lens   _diffss
   _min_diffss   _update_calibrations   _get_daytimes   nists	   timestamps   utctimes   locals   secondss   diffs   times   adjs   appends   DateTimeDeltaFromSecondss   Errors   calibration(
   s   nist_lookups   times   DateTimeDeltaFromSecondss   utctimes   _diffss	   timestamps   diffs   locals   nists   adj(    (    s:   /mit/seven/lib/python2.2/site-packages/mx/DateTime/NIST.pys   utctimeþ s    !c    s#   3;<| | |  ƒ i ƒ  ƒ Sd S(   sa    Returns the current local time as DateTime instance.

        Same notes as for utctime().

    N(   s	   localtimes   utctimes   nist_lookups   gmticks(   s   nist_lookups	   localtimes   utctime(    (    s:   /mit/seven/lib/python2.2/site-packages/mx/DateTime/NIST.pys	   localtime3s   c      sB   CKLy Mt  ƒ  Wn Nt j
 o Od Sn	 XQd Sd S(   sÉ    Return 1/0 depending on whether the NIST service is
        currently reachable or not.

        This function is expensive since it actually fetches a daytime
        packet from a NIST server.

    i    i   N(   s   _get_daytimes   Error(    (    (    s:   /mit/seven/lib/python2.2/site-packages/mx/DateTime/NIST.pys   onlineCs   c    s·   Sfgg  } hx` t |  ƒ Dh]O } i| ƒ  \ }
 } j| ƒ  }	 k|
 |	 i	 | ƒ  | } l| i | ƒ q Wmd } nx | Dn] } o| | } qˆ Wp| t | ƒ Sd S(   s   Returns the average offset of the computer's clock to the NIST
        time base in seconds.

        If you add the return value to the return value of
        time.time(), you will have a pretty accurate time base to use
        in your applications.

        Note that due to network latencies and the socket overhead,
        the calculated offset will include a small hopefully constant
        error.

        iterations sets the number of queries done to the NIST time
        base.  The average is taken over all queries.

    i    N(   s   diffss   ranges
   iterationss   is   _get_daytimes   nists	   timestamps   utctimes   locals   secondss   times   diffs   appends   sums   len(   s
   iterationss   utctimes   _get_daytimes   times   diffss   is	   timestamps   sums   diffs   locals   nist(    (    s:   /mit/seven/lib/python2.2/site-packages/mx/DateTime/NIST.pys   time_offsetSs   	 		
 	c    s(   ryz{|  a |d a }d a d S(   s    Sets the calibration to be use by localtime() and utctime().

        This also sets the global calibrated to 1 and disables auto
        calibration.

    i   i    N(   s   calibration_offsets   calibrations
   calibrateds   calibrating(   s   calibration_offset(    (    s:   /mit/seven/lib/python2.2/site-packages/mx/DateTime/NIST.pys   set_calibrationrs
   		i   c    sO   y ‘t  |  ƒ } Wn ’t t f j
 o
 “n X•t | ƒ d S(   s_   Calibrates the localtime() and gmtime() functions supplied
        in this module (not the standard ones in DateTime !).

        Uses the NIST time service as time base. The computer must
        have an active internet connection to be able to do
        calibration using the NIST servers.

        iterations sets the number of round to be done.

        Note: This function takes a few seconds to complete. For long
        running processes you should recalibrate every now and then
        because the system clock tends to drift (usually more than the
        hardware clock in the computer).

    N(   s   time_offsets
   iterationss   calibrations
   ValueErrors   Errors   set_calibration(   s
   iterationss   calibration(    (    s:   /mit/seven/lib/python2.2/site-packages/mx/DateTime/NIST.pys	   calibrates   c    sr   —¦§¨d } ©| |  } ªx | Dª] } «| | } q* W¬| t | ƒ a ­g  | (®t t ƒ d S(   sŽ   Updates the calibration from the last use_last entries in 
        the global _diffs.

        _diffs is being updated with every call to the two current
        time APIs that goes out and gets genuine information from
        NIST.

        After calibration the entries in _diffs are cleared. This
        function is automatically called by utctime() and localtime()
        when needed.

    i    N(   s   sums   _diffss   use_lasts   diffss   diffs   lens   calibrations   set_calibration(   s   use_lasts   _diffss   diffss   sums   diff(    (    s:   /mit/seven/lib/python2.2/site-packages/mx/DateTime/NIST.pys   _update_calibration—s   	
 	
c      s    °¼½¾g  t  (¿d a d S(   sm   Enables and resets the auto calibration for a new round.

        This does not clear possibly available calibration
        information, so the two time APIs will continue to revert to
        the calibrated clock in case no connection to the NIST servers
        is possible.

        Auto calibration is on per default when the module is
        imported.

    i   N(   s   _diffss   calibrating(    (    (    s:   /mit/seven/lib/python2.2/site-packages/mx/DateTime/NIST.pys   reset_auto_calibration°s   
c      s   ÄÇÈÉd a  d S(   s!    Turns auto calibration off.
    i    N(   s   calibrating(    (    (    s:   /mit/seven/lib/python2.2/site-packages/mx/DateTime/NIST.pys   disable_auto_calibrationÄs   (3   s   __doc__s   sockets   selects   DateTimes   res   errnos
   exceptionss   strings   times   _debugs   getservbynames   DAYTIME_PORTs   errors	   TIME_PORTs   daytime_serverss   ip_caches   daytime_http_serverss   StandardErrors   Errors   _daytimes   compiles
   _daytimeREs   _parse_datetimes   AF_INETs   SOCK_STREAMs   EINPROGRESSs   gethostbynames   _connects   _reads   strips   DateTimeFromMJDs   Times   _get_daytimes
   calibrateds   calibratings   calibrations   _diffss
   _min_diffss   DateTimeDeltaFromSecondss   utctimes   gmtimes	   localtimes   nows   onlines   time_offsets   set_calibrations	   calibrates   _update_calibrations   reset_auto_calibrations   enable_auto_calibrations   disable_auto_calibration(#   s   nows   daytime_serverss   _get_daytimes	   TIME_PORTs   times   gmtimes   DateTimes   ip_caches   DAYTIME_PORTs   _update_calibrations   enable_auto_calibrations   _daytimes   onlines	   calibrates   Errors   set_calibrations   _parse_datetimes
   _daytimeREs   selects   strings   _diffss   reset_auto_calibrations   _connects   sockets   _debugs   errnos   _reads   res   utctimes   disable_auto_calibrations   daytime_http_serverss
   exceptionss   time_offsets
   _min_diffss	   localtime(    (    s:   /mit/seven/lib/python2.2/site-packages/mx/DateTime/NIST.pys   ? sP   0	'c		<<-2					$3			