<s> import datetime <EOL> import struct <EOL> import winreg <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> ONEWEEK = datetime . timedelta ( <NUM_LIT:7> ) <EOL> TZKEYNAMENT = r"<STR_LIT>" <EOL> TZKEYNAME9X = r"<STR_LIT>" <EOL> TZLOCALKEYNAME = r"<STR_LIT>" <EOL> def _settzkeyname ( ) : <EOL> global TZKEYNAME <EOL> handle = winreg . ConnectRegistry ( None , winreg . HKEY_LOCAL_MACHINE ) <EOL> try : <EOL> winreg . OpenKey ( handle , TZKEYNAMENT ) . Close ( ) <EOL> TZKEYNAME = TZKEYNAMENT <EOL> except WindowsError : <EOL> TZKEYNAME = TZKEYNAME9X <EOL> handle . Close ( ) <EOL> _settzkeyname ( ) <EOL> class tzwinbase ( datetime . tzinfo ) : <EOL> """<STR_LIT>""" <EOL> def utcoffset ( self , dt ) : <EOL> if self . _isdst ( dt ) : <EOL> return datetime . timedelta ( minutes = self . _dstoffset ) <EOL> else : <EOL> return datetime . timedelta ( minutes = self . _stdoffset ) <EOL> def dst ( self , dt ) : <EOL> if self . _isdst ( dt ) : <EOL> minutes = self . _dstoffset - self . _stdoffset <EOL> return datetime . timedelta ( minutes = minutes ) <EOL> else : <EOL> return datetime . timedelta ( <NUM_LIT:0> ) <EOL> def tzname ( self , dt ) : <EOL> if self . _isdst ( dt ) : <EOL> return self . _dstname <EOL> else : <EOL> return self . _stdname <EOL> def list ( ) : <EOL> """<STR_LIT>""" <EOL> handle = winreg . ConnectRegistry ( None , winreg . HKEY_LOCAL_MACHINE ) <EOL> tzkey = winreg . OpenKey ( handle , TZKEYNAME ) <EOL> result = [ winreg . EnumKey ( tzkey , i ) <EOL> for i in range ( winreg . QueryInfoKey ( tzkey ) [ <NUM_LIT:0> ] ) ] <EOL> tzkey . Close ( ) <EOL> handle . Close ( ) <EOL> return result <EOL> list = staticmethod ( list ) <EOL> def display ( self ) : <EOL> return self . _display <EOL> def _isdst ( self , dt ) : <EOL> dston = picknthweekday ( dt . year , self . _dstmonth , self . _dstdayofweek , <EOL> self . _dsthour , self . _dstminute , <EOL> self . _dstweeknumber ) <EOL> dstoff = picknthweekday ( dt . year , self . _stdmonth , self . _stddayofweek , <EOL> self . _stdhour , self . _stdminute , <EOL> self . _stdweeknumber ) <EOL> if dston < dstoff : <EOL> return dston <= dt . replace ( tzinfo = None ) < dstoff <EOL> else : <EOL> return not dstoff <= dt . replace ( tzinfo = None ) < dston <EOL> class tzwin ( tzwinbase ) : <EOL> def __init__ ( self , name ) : <EOL> self . _name = name <EOL> handle = winreg . ConnectRegistry ( None , winreg . HKEY_LOCAL_MACHINE ) <EOL> tzkey = winreg . OpenKey ( handle , "<STR_LIT>" % ( TZKEYNAME , name ) ) <EOL> keydict = valuestodict ( tzkey ) <EOL> tzkey . Close ( ) <EOL> handle . Close ( ) <EOL> self . _stdname = keydict [ "<STR_LIT>" ] . encode ( "<STR_LIT>" ) <EOL> self . _dstname = keydict [ "<STR_LIT>" ] . encode ( "<STR_LIT>" ) <EOL> self . _display = keydict [ "<STR_LIT>" ] <EOL> tup = struct . unpack ( "<STR_LIT>" , keydict [ "<STR_LIT>" ] ) <EOL> self . _stdoffset = - tup [ <NUM_LIT:0> ] - tup [ <NUM_LIT:1> ] <EOL> self . _dstoffset = self . _stdoffset - tup [ <NUM_LIT:2> ] <EOL> ( self . _stdmonth , <EOL> self . _stddayofweek , <EOL> self . _stdweeknumber , <EOL> self . _stdhour , <EOL> self . _stdminute ) = tup [ <NUM_LIT:4> : <NUM_LIT:9> ] <EOL> ( self . _dstmonth , <EOL> self . _dstdayofweek , <EOL> self . _dstweeknumber , <EOL> self . _dsthour , <EOL> self . _dstminute ) = tup [ <NUM_LIT:12> : <NUM_LIT> ] <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % repr ( self . _name ) <EOL> def __reduce__ ( self ) : <EOL> return ( self . __class__ , ( self . _name , ) ) <EOL> class tzwinlocal ( tzwinbase ) : <EOL> def __init__ ( self ) : <EOL> handle = winreg . ConnectRegistry ( None , winreg . HKEY_LOCAL_MACHINE ) <EOL> tzlocalkey = winreg . OpenKey ( handle , TZLOCALKEYNAME ) <EOL> keydict = valuestodict ( tzlocalkey ) <EOL> tzlocalkey . Close ( ) <EOL> self . _stdname = keydict [ "<STR_LIT>" ] . encode ( "<STR_LIT>" ) <EOL> self . _dstname = keydict [ "<STR_LIT>" ] . encode ( "<STR_LIT>" ) <EOL> try : <EOL> tzkey = winreg . OpenKey ( handle , "<STR_LIT>" % ( TZKEYNAME , self . _stdname ) ) <EOL> _keydict = valuestodict ( tzkey ) <EOL> self . _display = _keydict [ "<STR_LIT>" ] <EOL> tzkey . Close ( ) <EOL> except OSError : <EOL> self . _display = None <EOL> handle . Close ( ) <EOL> self . _stdoffset = - keydict [ "<STR_LIT>" ] - keydict [ "<STR_LIT>" ] <EOL> self . _dstoffset = self . _stdoffset - keydict [ "<STR_LIT>" ] <EOL> tup = struct . unpack ( "<STR_LIT>" , keydict [ "<STR_LIT>" ] ) <EOL> ( self . _stdmonth , <EOL> self . _stddayofweek , <EOL> self . _stdweeknumber , <EOL> self . _stdhour , <EOL> self . _stdminute ) = tup [ <NUM_LIT:1> : <NUM_LIT:6> ] <EOL> tup = struct . unpack ( "<STR_LIT>" , keydict [ "<STR_LIT>" ] ) <EOL> ( self . _dstmonth , <EOL> self . _dstdayofweek , <EOL> self . _dstweeknumber , <EOL> self . _dsthour , <EOL> self . _dstminute ) = tup [ <NUM_LIT:1> : <NUM_LIT:6> ] <EOL> def __reduce__ ( self ) : <EOL> return ( self . __class__ , ( ) ) <EOL> def picknthweekday ( year , month , dayofweek , hour , minute , whichweek ) : <EOL> """<STR_LIT>""" <EOL> first = datetime . datetime ( year , month , <NUM_LIT:1> , hour , minute ) <EOL> weekdayone = first . replace ( day = ( ( dayofweek - first . isoweekday ( ) ) % <NUM_LIT:7> + <NUM_LIT:1> ) ) <EOL> for n in range ( whichweek ) : <EOL> dt = weekdayone + ( whichweek - n ) * ONEWEEK <EOL> if dt . month == month : <EOL> return dt <EOL> def valuestodict ( key ) : <EOL> """<STR_LIT>""" <EOL> dict = { } <EOL> size = winreg . QueryInfoKey ( key ) [ <NUM_LIT:1> ] <EOL> for i in range ( size ) : <EOL> data = winreg . EnumValue ( key , i ) <EOL> dict [ data [ <NUM_LIT:0> ] ] = data [ <NUM_LIT:1> ] <EOL> return dict </s>
