lxml的主要proivdes zope3接口定义
gocept.lxml的Python项目详细描述
这个包为lxml对象提供zope接口。远非 完成,但只是一个起点。
接口
接口在这里:
>>> import gocept.lxml.interfaces
有一个lxml.etree元素的接口:
>>> import lxml.etree >>> xml = lxml.etree.fromstring('<a/>') >>> gocept.lxml.interfaces.IElement.providedBy(xml) True
对于对象:
>>> import lxml.objectify >>> obj = lxml.objectify.fromstring('<a><str>holla</str></a>') >>> gocept.lxml.interfaces.IElement.providedBy(obj) True >>> gocept.lxml.interfaces.IObjectified.providedBy(obj) True >>> gocept.lxml.interfaces.IElement.providedBy(obj.str) True >>> gocept.lxml.interfaces.IObjectified.providedBy(obj.str) True
对象化分析器
中有一个用于从文件句柄创建objectfied的帮助程序 gocept.lxml.objectify。打开文件:
>>> import os.path >>> import gocept.lxml.objectify >>> filename = os.path.join( ... os.path.dirname(__file__), ... 'ftesting.zcml') >>> xml_file = file(filename)
然后解析它:
>>> xml = gocept.lxml.objectify.fromfile(xml_file) >>> xml <Element {http://namespaces.zope.org/zope}configure at ...>
这确实是客观化的:
>>> gocept.lxml.interfaces.IObjectified.providedBy(xml) True >>> xml.include.get('package') 'zope.app.component'
为了方便起见,在gocept.lxml.objectify中也定义了fromstring中的:
>>> xml = gocept.lxml.objectify.fromstring('<a><b/></a>') >>> xml <Element a at ...> >>> gocept.lxml.interfaces.IObjectified.providedBy(xml) True
更改
0.2.1(2008-02-14)
- 提高了对lxml<;2.0dev的依赖性,因此现在可以使用lxml 2。