remove utctz method and normalize_timezone. utctz is too tiny to be a senseful wrapper and normalize_tiezone did a bit too much (allowing tzinfo instances, where never one could be passed)

pull/42/head
Johannes Raggam 2012-03-19 18:12:39 +01:00
rodzic 4881f84d43
commit b2fec30125
4 zmienionych plików z 20 dodań i 27 usunięć

Wyświetl plik

@ -19,15 +19,15 @@ To create a calendar and write it to disk::
>>> cal = Calendar()
>>> from datetime import datetime
>>> from icalendar.tools import utctz # timezone
>>> cal.add('prodid', '-//My calendar product//mxm.dk//')
>>> cal.add('version', '2.0')
>>> import pytz
>>> event = Event()
>>> event.add('summary', 'Python meeting about calendaring')
>>> event.add('dtstart', datetime(2005,4,4,8,0,0,tzinfo=utctz()))
>>> event.add('dtend', datetime(2005,4,4,10,0,0,tzinfo=utctz()))
>>> event.add('dtstamp', datetime(2005,4,4,0,10,0,tzinfo=utctz()))
>>> event.add('dtstart', datetime(2005,4,4,8,0,0,tzinfo=pytz.utc))
>>> event.add('dtend', datetime(2005,4,4,10,0,0,tzinfo=pytz.utc))
>>> event.add('dtstamp', datetime(2005,4,4,0,10,0,tzinfo=pytz.utc))
>>> event['uid'] = '20050115T101010/27346262376@mxm.dk'
>>> event.add('priority', 5)

Wyświetl plik

@ -40,6 +40,8 @@ them directly.
"""
import pytz
# from python >= 2.3
from datetime import datetime, timedelta, time, date, tzinfo
from types import TupleType, ListType
@ -47,12 +49,10 @@ SequenceTypes = [TupleType, ListType]
import re
import time as _time
import binascii
from icalendar.tools import utctz
# from this package
from icalendar.caselessdict import CaselessDict
from icalendar.parser import Parameters
from icalendar.parser import normalized_timezone
DATE_PART = r'(\d+)D'
TIME_PART = r'T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?'
@ -501,8 +501,6 @@ class vDatetime:
created. Be aware that there are certain limitations with timezone naive
DATE-TIME components in the icalendar standard.
>>> from icalendar.tools import utctz
>>> d = datetime(2001, 1,1, 12, 30, 0)
>>> dt = vDatetime(d)
@ -512,7 +510,7 @@ class vDatetime:
>>> vDatetime.from_ical('20000101T120000')
datetime.datetime(2000, 1, 1, 12, 0)
>>> dutc = datetime(2001, 1,1, 12, 30, 0, tzinfo=utctz())
>>> dutc = datetime(2001, 1,1, 12, 30, 0, tzinfo=pytz.utc)
>>> vDatetime(dutc).to_ical()
'20010101T123000Z'
@ -551,10 +549,12 @@ class vDatetime:
""" Parses the data format from ical text format.
"""
# TODO: ical string should better contain also the TZID property.
tzinfo = None
if timezone:
timezone = normalized_timezone(timezone)
try:
tzinfo = pytz.timezone(timezone)
except pytz.UnknownTimeZoneError:
pass
try:
timetuple = map(int, ((
@ -565,12 +565,12 @@ class vDatetime:
ical[11:13], # minute
ical[13:15], # second
)))
if timezone:
return datetime(tzinfo=timezone, *timetuple)
if tzinfo:
return datetime(tzinfo=tzinfo, *timetuple)
elif not ical[15:]:
return datetime(*timetuple)
elif ical[15:16] == 'Z':
return datetime(tzinfo=utctz(), *timetuple)
return datetime(tzinfo=pytz.utc, *timetuple)
else:
raise ValueError, ical
except:

Wyświetl plik

@ -224,7 +224,6 @@ Init the calendar::
>>> cal = Calendar()
>>> from datetime import datetime
>>> from icalendar.tools import utctz # timezone
Some properties are required to be compliant::
@ -232,12 +231,13 @@ Some properties are required to be compliant::
>>> cal.add('version', '2.0')
We need at least one subcomponent for a calendar to be compliant::
>>> import pytz
>>> event = Event()
>>> event.add('summary', 'Python meeting about calendaring')
>>> event.add('dtstart', datetime(2005,4,4,8,0,0,tzinfo=utctz()))
>>> event.add('dtend', datetime(2005,4,4,10,0,0,tzinfo=utctz()))
>>> event.add('dtstamp', datetime(2005,4,4,0,10,0,tzinfo=utctz()))
>>> event.add('dtstart', datetime(2005,4,4,8,0,0,tzinfo=pytz.utc))
>>> event.add('dtend', datetime(2005,4,4,10,0,0,tzinfo=pytz.utc))
>>> event.add('dtstamp', datetime(2005,4,4,0,10,0,tzinfo=pytz.utc))
A property with parameters. Notice that they are an attribute on the value::

Wyświetl plik

@ -5,13 +5,6 @@ eh?
import random
from string import ascii_letters, digits
from datetime import datetime
import pytz
def utctz():
""" Return an UTC tzinfo object from the pytz library.
"""
return pytz.timezone('UTC')
class UIDGenerator: