1.1 --- a/vContent.py Sat Oct 18 01:41:15 2008 +0200
1.2 +++ b/vContent.py Thu Oct 23 22:57:11 2008 +0200
1.3 @@ -195,6 +195,8 @@
1.4
1.5 return self.parse_content_line()
1.6
1.7 + # Internal methods.
1.8 +
1.9 def parse_content_line(self):
1.10
1.11 """
1.12 @@ -285,11 +287,11 @@
1.13
1.14 self.names = []
1.15
1.16 - def parse(self, f):
1.17 + def parse(self, f, parser_cls=None):
1.18
1.19 "Parse the contents of the file 'f'."
1.20
1.21 - parser = StreamParser(f)
1.22 + parser = (parser_cls or StreamParser)(f)
1.23
1.24 for name, parameters, value in parser:
1.25
1.26 @@ -370,22 +372,21 @@
1.27
1.28 # Public methods.
1.29
1.30 - def parse(self, f):
1.31 + def parse(self, f, parser_cls=None):
1.32
1.33 "Parse the contents of the file 'f'."
1.34
1.35 - ParserBase.parse(self, f)
1.36 + ParserBase.parse(self, f, parser_cls)
1.37 return self.components[0]
1.38
1.39 # Public functions.
1.40
1.41 -def parse(f, non_standard_newline=0):
1.42 +def parse(f, non_standard_newline=0, parser_cls=None):
1.43
1.44 """
1.45 Parse the resource data found through the use of the file object 'f', which
1.46 - should provide Unicode data, and put the resource information in the given
1.47 - 'store'. (The codecs module can be used to open files or to wrap streams in
1.48 - order to provide Unicode data.)
1.49 + should provide Unicode data. (The codecs module can be used to open files or
1.50 + to wrap streams in order to provide Unicode data.)
1.51
1.52 The optional 'non_standard_newline' can be set to a true value (unlike the
1.53 default) in order to attempt to process files with CR as the end of line
1.54 @@ -395,8 +396,27 @@
1.55 is returned.
1.56 """
1.57
1.58 - reader = Reader(f, non_standard_newline=non_standard_newline)
1.59 - parser = Parser()
1.60 + reader = Reader(f, non_standard_newline)
1.61 + parser = (parser_cls or Parser)()
1.62 return parser.parse(reader)
1.63
1.64 +def iterparse(f, non_standard_newline=0, parser_cls=None):
1.65 +
1.66 + """
1.67 + Parse the resource data found through the use of the file object 'f', which
1.68 + should provide Unicode data. (The codecs module can be used to open files or
1.69 + to wrap streams in order to provide Unicode data.)
1.70 +
1.71 + The optional 'non_standard_newline' can be set to a true value (unlike the
1.72 + default) in order to attempt to process files with CR as the end of line
1.73 + character.
1.74 +
1.75 + An iterator is returned which provides event tuples describing parsing
1.76 + events of the form (name, parameters, value).
1.77 + """
1.78 +
1.79 + reader = Reader(f, non_standard_newline)
1.80 + parser = (parser_cls or StreamParser)(reader)
1.81 + return iter(parser)
1.82 +
1.83 # vim: tabstop=4 expandtab shiftwidth=4