<s> try : <EOL> import _winreg as winreg <EOL> except ImportError : <EOL> try : <EOL> import winreg <EOL> except ImportError : <EOL> winreg = None <EOL> from babel . core import get_global <EOL> import pytz <EOL> try : <EOL> tz_names = get_global ( '<STR_LIT>' ) <EOL> except RuntimeError : <EOL> tz_names = { } <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 <EOL> def get_localzone_name ( ) : <EOL> handle = winreg . ConnectRegistry ( None , winreg . HKEY_LOCAL_MACHINE ) <EOL> TZLOCALKEYNAME = r'<STR_LIT>' <EOL> localtz = winreg . OpenKey ( handle , TZLOCALKEYNAME ) <EOL> keyvalues = valuestodict ( localtz ) <EOL> localtz . Close ( ) <EOL> if '<STR_LIT>' in keyvalues : <EOL> tzkeyname = keyvalues [ '<STR_LIT>' ] . split ( '<STR_LIT:\x00>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> else : <EOL> tzwin = keyvalues [ '<STR_LIT>' ] <EOL> TZKEYNAME = r'<STR_LIT>' <EOL> tzkey = winreg . OpenKey ( handle , TZKEYNAME ) <EOL> tzkeyname = None <EOL> for i in range ( winreg . QueryInfoKey ( tzkey ) [ <NUM_LIT:0> ] ) : <EOL> subkey = winreg . EnumKey ( tzkey , i ) <EOL> sub = winreg . OpenKey ( tzkey , subkey ) <EOL> data = valuestodict ( sub ) <EOL> sub . Close ( ) <EOL> if data [ '<STR_LIT>' ] == tzwin : <EOL> tzkeyname = subkey <EOL> break <EOL> tzkey . Close ( ) <EOL> handle . Close ( ) <EOL> if tzkeyname is None : <EOL> raise LookupError ( '<STR_LIT>' ) <EOL> timezone = tz_names . get ( tzkeyname ) <EOL> if timezone is None : <EOL> timezone = tz_names . get ( tzkeyname + '<STR_LIT>' ) <EOL> if timezone is None : <EOL> raise pytz . UnknownTimeZoneError ( '<STR_LIT>' + tzkeyname ) <EOL> return timezone <EOL> def _get_localzone ( ) : <EOL> if winreg is None : <EOL> raise pytz . UnknownTimeZoneError ( <EOL> '<STR_LIT>' ) <EOL> return pytz . timezone ( get_localzone_name ( ) ) </s>
