[lxml-dev] lxml & parsing: return of a classes

Stefan Behnel stefan_ml at behnel.de
Sun Jul 22 16:18:13 CEST 2007


Stefan Behnel wrote:
> Stefan Behnel wrote:
>> Ian Bicking wrote:
>>> I'm not sure exactly how to attach the URL getting method to the Parser 
>>> object in this model, because I'm not sure how to give elements a 
>>> reference back to it.
>> I think we should try to integrate with the normal Resolver mechanism here
>> (doc/resolvers.txt). Not sure how this works exactly if we want to use it from
>> Python code (currently it's only called from libxml2 internally), but I would
>> like to avoid adding yet another way to resolve URLs. Currently, resolvers
>> receive an opaque "context" object as last argument and return an opaque
>> object with a string or file-like object etc. We could easily replace the
>> context with an object containing a sequence of form arguments (which would be
>> None when calling from libxml2).

I thought about this some more and I now think that it would be inappropriate
to use etree's resolver interface here. It serves a totally different purpose
and the extension with form data would be useless everywhere else. A simple
function passed as argument to submit would do. If you want a
set-once-use-everywhere setup, the parser is the only place where this would
work, although I dislike the idea of using the /parser/ to set a method for
/submitting/ form data. Especially if you have to parse the result yourself.

I now made the submit() method a "submit_form()" module function. That way,
you can easily write your own function with the same interface that simply
passes the appropriate HTTP mechanism in for you. The signature is:

  def submit_form(form, extra_values=None, open_http=None)

Stefan



More information about the lxml-dev mailing list