Mercurial > p > roundup > code
annotate roundup/cgi/TAL/XMLParser.py @ 2077:3e0961d6d44d
Added the "actor" property.
Metakit backend not done (still not confident I know how it's supposed
to work ;)
Currently it will come up as NULL in the RDBMS backends for older items.
The *dbm backends will look up the journal. I hope to remedy the former
before 0.7's release.
Fixed a bunch of migration issues in the rdbms backends while I was at it
(index changes for key prop changes) and simplified the class table update
code for RDBMSes that have "alter table" in their command set (ie. not
sqlite) ... migration from "version 1" to "version 2" still hasn't
actually been tested yet though.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Mon, 15 Mar 2004 05:50:20 +0000 |
| parents | fc52d57c6c3e |
| children | 8c2402a78bb0 |
| rev | line source |
|---|---|
| 1049 | 1 ############################################################################## |
| 2 # | |
| 3 # Copyright (c) 2001, 2002 Zope Corporation and Contributors. | |
| 4 # All Rights Reserved. | |
| 5 # | |
| 6 # This software is subject to the provisions of the Zope Public License, | |
| 7 # Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution. | |
| 8 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | |
| 9 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 10 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | |
| 11 # FOR A PARTICULAR PURPOSE | |
| 12 # | |
| 13 ############################################################################## | |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1071
diff
changeset
|
14 """Generic expat-based XML parser base class. |
|
1071
c08b3820edd1
Adhering to ZPL
Richard Jones <richard@users.sourceforge.net>
parents:
1049
diff
changeset
|
15 |
|
c08b3820edd1
Adhering to ZPL
Richard Jones <richard@users.sourceforge.net>
parents:
1049
diff
changeset
|
16 Modified for Roundup 0.5 release: |
|
c08b3820edd1
Adhering to ZPL
Richard Jones <richard@users.sourceforge.net>
parents:
1049
diff
changeset
|
17 |
|
c08b3820edd1
Adhering to ZPL
Richard Jones <richard@users.sourceforge.net>
parents:
1049
diff
changeset
|
18 - removed dependency on zLOG |
|
c08b3820edd1
Adhering to ZPL
Richard Jones <richard@users.sourceforge.net>
parents:
1049
diff
changeset
|
19 |
| 1049 | 20 """ |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1071
diff
changeset
|
21 __docformat__ = 'restructuredtext' |
| 1049 | 22 |
| 23 class XMLParser: | |
| 24 | |
| 25 ordered_attributes = 0 | |
| 26 | |
| 27 handler_names = [ | |
| 28 "StartElementHandler", | |
| 29 "EndElementHandler", | |
| 30 "ProcessingInstructionHandler", | |
| 31 "CharacterDataHandler", | |
| 32 "UnparsedEntityDeclHandler", | |
| 33 "NotationDeclHandler", | |
| 34 "StartNamespaceDeclHandler", | |
| 35 "EndNamespaceDeclHandler", | |
| 36 "CommentHandler", | |
| 37 "StartCdataSectionHandler", | |
| 38 "EndCdataSectionHandler", | |
| 39 "DefaultHandler", | |
| 40 "DefaultHandlerExpand", | |
| 41 "NotStandaloneHandler", | |
| 42 "ExternalEntityRefHandler", | |
| 43 "XmlDeclHandler", | |
| 44 "StartDoctypeDeclHandler", | |
| 45 "EndDoctypeDeclHandler", | |
| 46 "ElementDeclHandler", | |
| 47 "AttlistDeclHandler" | |
| 48 ] | |
| 49 | |
| 50 def __init__(self, encoding=None): | |
| 51 self.parser = p = self.createParser() | |
| 52 if self.ordered_attributes: | |
| 53 try: | |
| 54 self.parser.ordered_attributes = self.ordered_attributes | |
| 55 except AttributeError: | |
| 56 #zLOG.LOG("TAL.XMLParser", zLOG.INFO, | |
| 57 # "Can't set ordered_attributes") | |
| 58 self.ordered_attributes = 0 | |
| 59 for name in self.handler_names: | |
| 60 method = getattr(self, name, None) | |
| 61 if method is not None: | |
| 62 try: | |
| 63 setattr(p, name, method) | |
| 64 except AttributeError: | |
| 65 #zLOG.LOG("TAL.XMLParser", zLOG.PROBLEM, | |
| 66 # "Can't set expat handler %s" % name) | |
| 67 pass | |
| 68 | |
| 69 def createParser(self, encoding=None): | |
| 70 global XMLParseError | |
| 71 try: | |
| 72 from Products.ParsedXML.Expat import pyexpat | |
| 73 XMLParseError = pyexpat.ExpatError | |
| 74 return pyexpat.ParserCreate(encoding, ' ') | |
| 75 except ImportError: | |
| 76 from xml.parsers import expat | |
| 77 XMLParseError = expat.ExpatError | |
| 78 return expat.ParserCreate(encoding, ' ') | |
| 79 | |
| 80 def parseFile(self, filename): | |
| 81 self.parseStream(open(filename)) | |
| 82 | |
| 83 def parseString(self, s): | |
| 84 self.parser.Parse(s, 1) | |
| 85 | |
| 86 def parseURL(self, url): | |
| 87 import urllib | |
| 88 self.parseStream(urllib.urlopen(url)) | |
| 89 | |
| 90 def parseStream(self, stream): | |
| 91 self.parser.ParseFile(stream) | |
| 92 | |
| 93 def parseFragment(self, s, end=0): | |
| 94 self.parser.Parse(s, end) |
