[lxml-dev] Resolvers and open files

I have a long-running process that uses a custom resolver to resolve a simple filename to a file relative to a pre-configured directory. It looks like this: class RelativeUrlResolver(etree.Resolver): def __init__(self, prefix): self.prefix = prefix def resolve(self, url, id, context): print "Resolving URL '%s'" % url if not url.startswith('http'): url = self.prefix + urllib.quote_plus(url) ssf = urllib.urlopen(url) if ssf is None: raise ValueError, 'could not resolve url: %r' % url return self.resolve_file(ssf, context) I'm creating the parser like this: parser = etree.XMLParser() parser.resolvers.add(RelativeUrlResolver(BASE)) (Where BASE = 'file:///path/to/some/dir') Now, the issue that's biting me is that it looks like the file is kept open after the processing has finished. The parser is re-created every time ATM, and goes 'out of scope' right after doing the transformation, so I would expect it all to be garbage collected, and the file to be closed. Do I need to do anything special to get this file to be closed? Thanks. -- Sidnei da Silva Enfold Systems http://enfoldsystems.com Fax +1 832 201 8856 Office +1 713 942 2377 Ext 214

On Wed, Oct 25, 2006 at 09:49:36AM +0200, Stefan Behnel wrote: | Right, the resolver context that stores the temporary references was not | cleaned up after use. | | Should be fixed on the trunk now. Please test it with your setup. Ok, seems to work now! Thank you a lot! -- Sidnei da Silva Enfold Systems http://enfoldsystems.com Fax +1 832 201 8856 Office +1 713 942 2377 Ext 214

On Wed, Oct 25, 2006 at 09:49:36AM +0200, Stefan Behnel wrote: | Right, the resolver context that stores the temporary references was not | cleaned up after use. | | Should be fixed on the trunk now. Please test it with your setup. Ok, seems to work now! Thank you a lot! -- Sidnei da Silva Enfold Systems http://enfoldsystems.com Fax +1 832 201 8856 Office +1 713 942 2377 Ext 214
participants (2)
-
Sidnei da Silva
-
Stefan Behnel