~ubuntu-branches/ubuntu/vivid/python-dateutil/vivid-proposed

« back to all changes in this revision

Viewing changes to dateutil/tzwin.py

  • Committer: Package Import Robot
  • Author(s): Guido Günther
  • Date: 2014-09-27 21:24:01 UTC
  • mto: (8.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: package-import@ubuntu.com-20140927212401-0ardwnw0bjm40f5r
Tags: upstream-2.2
Import upstream version 2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# This code was originally contributed by Jeffrey Harris.
2
2
import datetime
3
3
import struct
4
 
import _winreg
 
4
import winreg
5
5
 
6
 
__author__ = "Jeffrey Harris & Gustavo Niemeyer <gustavo@niemeyer.net>"
7
6
 
8
7
__all__ = ["tzwin", "tzwinlocal"]
9
8
 
15
14
 
16
15
def _settzkeyname():
17
16
    global TZKEYNAME
18
 
    handle = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
 
17
    handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
19
18
    try:
20
 
        _winreg.OpenKey(handle, TZKEYNAMENT).Close()
 
19
        winreg.OpenKey(handle, TZKEYNAMENT).Close()
21
20
        TZKEYNAME = TZKEYNAMENT
22
21
    except WindowsError:
23
22
        TZKEYNAME = TZKEYNAME9X
49
48
 
50
49
    def list():
51
50
        """Return a list of all time zones known to the system."""
52
 
        handle = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
53
 
        tzkey = _winreg.OpenKey(handle, TZKEYNAME)
54
 
        result = [_winreg.EnumKey(tzkey, i)
55
 
                  for i in range(_winreg.QueryInfoKey(tzkey)[0])]
 
51
        handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
 
52
        tzkey = winreg.OpenKey(handle, TZKEYNAME)
 
53
        result = [winreg.EnumKey(tzkey, i)
 
54
                  for i in range(winreg.QueryInfoKey(tzkey)[0])]
56
55
        tzkey.Close()
57
56
        handle.Close()
58
57
        return result
79
78
    def __init__(self, name):
80
79
        self._name = name
81
80
 
82
 
        handle = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
83
 
        tzkey = _winreg.OpenKey(handle, "%s\%s" % (TZKEYNAME, name))
 
81
        handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
 
82
        tzkey = winreg.OpenKey(handle, "%s\%s" % (TZKEYNAME, name))
84
83
        keydict = valuestodict(tzkey)
85
84
        tzkey.Close()
86
85
        handle.Close()
118
117
    
119
118
    def __init__(self):
120
119
 
121
 
        handle = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
 
120
        handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
122
121
 
123
 
        tzlocalkey = _winreg.OpenKey(handle, TZLOCALKEYNAME)
 
122
        tzlocalkey = winreg.OpenKey(handle, TZLOCALKEYNAME)
124
123
        keydict = valuestodict(tzlocalkey)
125
124
        tzlocalkey.Close()
126
125
 
128
127
        self._dstname = keydict["DaylightName"].encode("iso-8859-1")
129
128
 
130
129
        try:
131
 
            tzkey = _winreg.OpenKey(handle, "%s\%s"%(TZKEYNAME, self._stdname))
 
130
            tzkey = winreg.OpenKey(handle, "%s\%s"%(TZKEYNAME, self._stdname))
132
131
            _keydict = valuestodict(tzkey)
133
132
            self._display = _keydict["Display"]
134
133
            tzkey.Close()
165
164
    """dayofweek == 0 means Sunday, whichweek 5 means last instance"""
166
165
    first = datetime.datetime(year, month, 1, hour, minute)
167
166
    weekdayone = first.replace(day=((dayofweek-first.isoweekday())%7+1))
168
 
    for n in xrange(whichweek):
 
167
    for n in range(whichweek):
169
168
        dt = weekdayone+(whichweek-n)*ONEWEEK
170
169
        if dt.month == month:
171
170
            return dt
173
172
def valuestodict(key):
174
173
    """Convert a registry key's values to a dictionary."""
175
174
    dict = {}
176
 
    size = _winreg.QueryInfoKey(key)[1]
 
175
    size = winreg.QueryInfoKey(key)[1]
177
176
    for i in range(size):
178
 
        data = _winreg.EnumValue(key, i)
 
177
        data = winreg.EnumValue(key, i)
179
178
        dict[data[0]] = data[1]
180
179
    return dict