""" 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. """ import socket # This module needs access to sockets ! import select # This module needs access to select ! import DateTime import re,errno,exceptions,string,time # Enable to produce debugging output _debug = 0 # Port numbers try: DAYTIME_PORT = socket.getservbyname('daytime','tcp') except socket.error: DAYTIME_PORT = 13 try: TIME_PORT = socket.getservbyname('time','tcp') except socket.error: TIME_PORT = 37 # Known servers: daytime_servers = ('time.nist.gov', 'time-a.nist.gov', 'time-b.nist.gov', 'time-nw.nist.gov', 'time-a.timefreq.bldrdoc.gov', 'time-b.timefreq.bldrdoc.gov', 'time-c.timefreq.bldrdoc.gov', 'utcnist.colorado.edu', 'utcnist1.reston.mci.net', 'nist1.datum.com', ) # IP cache (XXX update these every now and then): ip_cache = {'utcnist1.reston.mci.net': '204.70.131.13', 'time-a.nist.gov': '129.6.16.35', 'time-c.timefreq.bldrdoc.gov': '132.163.135.132', 'time-a.timefreq.bldrdoc.gov': '132.163.135.130', 'nist1.datum.com': '209.0.72.7', 'time-nw.nist.gov': '131.107.1.10', 'time-b.timefreq.bldrdoc.gov': '132.163.135.131', 'time-b.nist.gov': '129.6.16.36', 'time.nist.gov': '192.43.244.18', 'utcnist.colorado.edu': '128.138.140.44'} # XXX Not yet implemented... # Use as fallback alternative for people behind firewalls: daytime_http_servers = ('http://time-a.timefreq.bldrdoc.gov:14/', ) ### Errors class Error(exceptions.StandardError): pass ### Parsers # NIST daytime signal (JJJJ YR-MO-DA HH:MM:SS TT L H msADV UTC(NIST) OTM); # see http://www.bldrdoc.gov/timefreq/service/nts.htm for details. _daytime = ('(?P\d+) ' '(?P\d+-\d\d-\d\d) ' '(?P\d?\d):(?P\d\d):(?P\d\d) ' '(?P\d\d) ' '(?P\d) ' '(?P\d) ' '(?P\d+(?:\.\d+)?) ' '(?P