since Paul kept bugging me, I created a new branch (resolver-new) and
implemented an API for the custom resolvers stuff. It should be pretty simple
to use, just create a parser and register the resolver:
parser = XMLParser()
"my_resolver" must be of type etree.Resolver and provide a method
resolve(system_url, public_id, context)
that returns either None (== "can't resolve, ask someone else") or a
_ParserInput object. These can be built from files or strings using the
Resolver methods 'resolve_string' and 'resolve_filename'.
So, to create a custom resolver, you basically do this
entity = "This was an entity"
def resolve(self, url, id, context):
if url == 'my.dtd':
# I can handle this
u'<!ENTITY myentity "%s">' % self.entity, context)
# the default resolver can handle this
return super(MyResolver, self).resolve(url, id, context)
# don't know what to do, let someone else try
my_resolver = MyResolver()
I'll see how to integrate that in other places of the API, especially XSLT and
schemas. Anyway, this works so far. Feel free to comment on it.