1.1 --- a/vCalendar.py Thu Jan 15 23:39:48 2009 +0100
1.2 +++ b/vCalendar.py Sat Mar 14 22:13:22 2009 +0100
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Parsing of vCalendar and iCalendar files.
1.6
1.7 -Copyright (C) 2008 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2008, 2009 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU Lesser General Public License as published by the Free
1.12 @@ -113,22 +113,7 @@
1.13
1.14 "A stream writer specifically for vCard."
1.15
1.16 - def write(self, name, parameters, value):
1.17 -
1.18 - """
1.19 - Write a content line for the given 'name', 'parameters' and 'value'
1.20 - information.
1.21 - """
1.22 -
1.23 - vContent.StreamWriter.write(self, name, self.encode_parameters(parameters), value)
1.24 -
1.25 - # Internal methods.
1.26 -
1.27 - def encode_quoted_value(self, value):
1.28 -
1.29 - "Encode the given 'value'."
1.30 -
1.31 - return '"%s"' % value
1.32 + # Overridden methods.
1.33
1.34 def encode_parameters(self, parameters):
1.35
1.36 @@ -140,7 +125,7 @@
1.37
1.38 for param_name, param_value in parameters.items():
1.39 if param_name in QUOTED_PARAMETERS:
1.40 - param_value = self.encode_quoted_value(param_value)
1.41 + param_value = self.encode_quoted_parameter_value(param_value)
1.42 separator = '","'
1.43 else:
1.44 separator = ","
1.45 @@ -152,7 +137,7 @@
1.46
1.47 def encode_content(self, value):
1.48
1.49 - "Encode the given 'value', replacing separator characters."
1.50 + "Encode the given 'value', quoting characters."
1.51
1.52 # Replace quoted characters (see 4.3.11 in RFC 2445).
1.53
1.54 @@ -161,7 +146,7 @@
1.55
1.56 # Public functions.
1.57
1.58 -def parse(stream_or_string, non_standard_newline=0):
1.59 +def parse(stream_or_string, encoding=None, non_standard_newline=0):
1.60
1.61 """
1.62 Parse the resource data found through the use of the 'stream_or_string',
1.63 @@ -169,6 +154,9 @@
1.64 used to open files or to wrap streams in order to provide Unicode data) or a
1.65 filename identifying a file to be parsed.
1.66
1.67 + The optional 'encoding' can be used to specify the character encoding used
1.68 + by the file to be parsed.
1.69 +
1.70 The optional 'non_standard_newline' can be set to a true value (unlike the
1.71 default) in order to attempt to process files with CR as the end of line
1.72 character.
1.73 @@ -177,9 +165,9 @@
1.74 is returned.
1.75 """
1.76
1.77 - return vContent.parse(stream_or_string, non_standard_newline, vCalendarParser)
1.78 + return vContent.parse(stream_or_string, encoding, non_standard_newline, vCalendarParser)
1.79
1.80 -def iterparse(stream_or_string, non_standard_newline=0):
1.81 +def iterparse(stream_or_string, encoding=None, non_standard_newline=0):
1.82
1.83 """
1.84 Parse the resource data found through the use of the 'stream_or_string',
1.85 @@ -187,6 +175,9 @@
1.86 used to open files or to wrap streams in order to provide Unicode data) or a
1.87 filename identifying a file to be parsed.
1.88
1.89 + The optional 'encoding' can be used to specify the character encoding used
1.90 + by the file to be parsed.
1.91 +
1.92 The optional 'non_standard_newline' can be set to a true value (unlike the
1.93 default) in order to attempt to process files with CR as the end of line
1.94 character.
1.95 @@ -195,9 +186,23 @@
1.96 events of the form (name, parameters, value).
1.97 """
1.98
1.99 - return vContent.iterparse(stream_or_string, non_standard_newline, vCalendarStreamParser)
1.100 + return vContent.iterparse(stream_or_string, encoding, non_standard_newline, vCalendarStreamParser)
1.101 +
1.102 +def iterwrite(stream_or_string, encoding=None, line_length=None):
1.103
1.104 -def iterwrite(stream_or_string, line_length=None):
1.105 - return vContent.iterwrite(stream_or_string, line_length, vCalendarStreamWriter)
1.106 + """
1.107 + Return a writer which will send data to the resource found through the use
1.108 + of 'stream_or_string', which is either a stream accepting Unicode data (the
1.109 + codecs module can be used to open files or to wrap streams in order to
1.110 + accept Unicode data) or a filename identifying a file to be parsed.
1.111 +
1.112 + The optional 'encoding' can be used to specify the character encoding used
1.113 + by the file to be written.
1.114 +
1.115 + The optional 'line_length' can be used to specify how long lines should be
1.116 + in the resulting data.
1.117 + """
1.118 +
1.119 + return vContent.iterwrite(stream_or_string, encoding, line_length, vCalendarStreamWriter)
1.120
1.121 # vim: tabstop=4 expandtab shiftwidth=4