[Zope3-checkins] CVS: zopeproducts/xml/dom - adapters.py:1.1 configure.zcml:1.1
Philipp von Weitershausen
philikon@philikon.de
Sun, 22 Jun 2003 20:17:35 -0400
Update of /cvs-repository/zopeproducts/xml/dom
In directory cvs.zope.org:/tmp/cvs-serv19777
Added Files:
adapters.py configure.zcml
Log Message:
Added two basic adapters:
* DOM to XML text
* XML text to DOM
=== Added File zopeproducts/xml/dom/adapters.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
DOM adapters
$Id: adapters.py,v 1.1 2003/06/23 00:17:35 philikon Exp $
"""
from StringIO import StringIO
from zope.interface import implements
from zope.app.interfaces.xml.source import IXMLText
import expatbuilder
from zopeproducts.xml.interfaces.dom.core import IDocument
from printer import Printer
class DocumentToXMLTextAdapter:
implements(IXMLText)
__used_for__ = IDocument
def __init__(self, context):
self.context = context
def _get_source(self):
printer = Printer()
out = StringIO()
printer.render(out, self.context)
out.seek(0)
return out.read()
source = property(_get_source)
class XMLTextToDocumentAdapterFactory:
__used_for__ = IXMLText
def __call__(self, context):
f = StringIO(context.source)
return expatbuilder.parse(f)
XMLTextToDocumentAdapter = XMLTextToDocumentAdapterFactory()
=== Added File zopeproducts/xml/dom/configure.zcml ===
<zopeConfigure xmlns="http://namespaces.zope.org/zope">
<include file="core.zcml" />
<!-- register DOM document to XML text adapter-->
<adapter
factory=".adapters.DocumentToXMLTextAdapter"
provides="zope.app.interfaces.xml.source.IXMLText"
for="zopeproducts.xml.interfaces.dom.core.IDocument" />
<!-- register XMLtext to DOM document adapter-->
<adapter
factory=".adapters.XMLTextToDocumentAdapter"
provides="zopeproducts.xml.interfaces.dom.core.IDocument"
for="zope.app.interfaces.xml.source.IXMLText" />
</zopeConfigure>