1.1 --- a/tests/test_calendar.py Sat Mar 14 22:13:22 2009 +0100
1.2 +++ b/tests/test_calendar.py Sun Mar 15 21:30:36 2009 +0100
1.3 @@ -4,6 +4,9 @@
1.4
1.5 this_dir = os.path.split(__file__)[0]
1.6 f = codecs.open(os.path.join(this_dir, "test.ics"), encoding="utf-8")
1.7 -doc = vCalendar.parse(f)
1.8 +try:
1.9 + doc = vCalendar.parse(f)
1.10 +finally:
1.11 + f.close()
1.12
1.13 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/tests/test_card.py Sat Mar 14 22:13:22 2009 +0100
2.2 +++ b/tests/test_card.py Sun Mar 15 21:30:36 2009 +0100
2.3 @@ -4,6 +4,9 @@
2.4
2.5 this_dir = os.path.split(__file__)[0]
2.6 f = codecs.open(os.path.join(this_dir, "test.vcf"), encoding="utf-8")
2.7 -doc = vContent.parse(f)
2.8 +try:
2.9 + doc = vContent.parse(f)
2.10 +finally:
2.11 + f.close()
2.12
2.13 # vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/vCalendar.py Sat Mar 14 22:13:22 2009 +0100
3.2 +++ b/vCalendar.py Sun Mar 15 21:30:36 2009 +0100
3.3 @@ -105,7 +105,7 @@
3.4 "A parser specifically for vCalendar/iCalendar."
3.5
3.6 def parse(self, f, parser_cls=None):
3.7 - return vContent.Parser.parse(self, f, vCalendarStreamParser)
3.8 + return vContent.Parser.parse(self, f, (parser_cls or vCalendarStreamParser))
3.9
3.10 # Writer classes.
3.11
4.1 --- a/vContent.py Sat Mar 14 22:13:22 2009 +0100
4.2 +++ b/vContent.py Sun Mar 15 21:30:36 2009 +0100
4.3 @@ -380,7 +380,7 @@
4.4 empty list of children as part of the component's content.
4.5 """
4.6
4.7 - component = self.handleProperty(name, parameters, [])
4.8 + component = self.handleProperty(name, parameters)
4.9 self.components.append(component)
4.10 return component
4.11
4.12 @@ -388,19 +388,23 @@
4.13
4.14 """
4.15 End the component with the given 'name' by removing it from the active
4.16 - component stack.
4.17 + component stack. If only one component exists on the stack, retain it
4.18 + for later inspection.
4.19 """
4.20
4.21 if len(self.components) > 1:
4.22 return self.components.pop()
4.23 +
4.24 + # Or return the only element.
4.25 +
4.26 elif self.components:
4.27 - return self.components[-1]
4.28 + return self.components[0]
4.29
4.30 - def handleProperty(self, name, parameters, value):
4.31 + def handleProperty(self, name, parameters, value=None):
4.32
4.33 """
4.34 - Record the property with the given 'name', 'parameters' and 'value' as
4.35 - part of the current component's children.
4.36 + Record the property with the given 'name', 'parameters' and optional
4.37 + 'value' as part of the current component's children.
4.38 """
4.39
4.40 component = self.makeComponent(name, parameters, value)
4.41 @@ -417,13 +421,14 @@
4.42 component_name, component_parameters, component_children = self.components[-1]
4.43 component_children.append(component)
4.44
4.45 - def makeComponent(self, name, parameters, value):
4.46 + def makeComponent(self, name, parameters, value=None):
4.47
4.48 """
4.49 - Make a component object from the given 'name', 'parameters' and 'value'.
4.50 + Make a component object from the given 'name', 'parameters' and optional
4.51 + 'value'.
4.52 """
4.53
4.54 - return (name, parameters, value)
4.55 + return (name, parameters, value or [])
4.56
4.57 # Public methods.
4.58