1 #!/usr/bin/env python 2 3 """ 4 SVG-specific document support. 5 6 Copyright (C) 2007 Paul Boddie <paul@boddie.org.uk> 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU Lesser General Public 10 License as published by the Free Software Foundation; either 11 version 2.1 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 Lesser General Public License for more details. 17 18 You should have received a copy of the GNU Lesser General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 21 """ 22 23 import libxml2dom 24 from libxml2dom.macrolib import * 25 from libxml2dom.macrolib import \ 26 createDocument as Node_createDocument, \ 27 parseString as Node_parseString, parseURI as Node_parseURI, \ 28 parseFile as Node_parseFile, \ 29 toString as Node_toString, toStream as Node_toStream, \ 30 toFile as Node_toFile 31 32 class SVGImplementation(libxml2dom.Implementation): 33 34 "Contains an SVG-specific implementation." 35 36 def get_node(self, _node, context_node): 37 if Node_nodeType(_node) == context_node.ELEMENT_NODE and \ 38 Node_namespaceURI(_node) == "http://www.w3.org/2000/svg" and \ 39 Node_localName(_node) == "svg": 40 41 return SVGElement(_node, self, context_node.ownerDocument) 42 else: 43 return libxml2dom.Implementation.get_node(self, _node, context_node) 44 45 class SVGElement(libxml2dom.Node): 46 47 "An SVG-specific top-level element." 48 49 NAV_AUTO = 1 50 NAV_NEXT = 2 51 NAV_PREV = 3 52 NAV_UP = 4 53 NAV_UP_RIGHT = 5 54 NAV_RIGHT = 6 55 NAV_DOWN_RIGHT = 7 56 NAV_DOWN = 8 57 NAV_DOWN_LEFT = 9 58 NAV_LEFT = 10 59 NAV_UP_LEFT = 11 60 61 def parse(stream_or_string, html=0): 62 return libxml2dom.parse(stream_or_string, html, default_impl) 63 64 def parseFile(filename, html=0): 65 return libxml2dom.parseFile(filename, html, default_impl) 66 67 def parseString(s, html=0): 68 return libxml2dom.parseString(s, html, default_impl) 69 70 def parseURI(uri, html=0): 71 return libxml2dom.parseURI(uri, html, default_impl) 72 73 # Single instance of the implementation. 74 75 default_impl = SVGImplementation() 76 77 # vim: tabstop=4 expandtab shiftwidth=4