Arne Grimstrup <[EMAIL PROTECTED]> writes: > > Hi Chris, > > On Tue, 9 Oct 2007 15:25:18 +0100 Chris Allan <[EMAIL PROTECTED]> wrote: > > > Hello again, > > > > The current version of process_includes.py raises an ImportError if > > you do not have lxml installed. Attached is a patch to fix the > > exception that allows me to run the script with ElementTree installed > > via an Egg on Python-2.4. > > > > I'm also currently investigating adding HTTP import retrieval for > > those of us who do not have local file locations in our XML Schema > > documents. Is this something that anyone else has tinkered with or > > who would benefit from? > > > > Ciao. > > > > -Chris > > I'm trying to generate Python classes for some schema that have nested > elements, so I believe I would benefit from your work on import retrieval. > I'm very interested to know if you have made any progress on this or not. >
Arne - I'm not sure what needs you or Chris have, but if you are trying to "import" and insert documents found on the Web, you might be interested in the following piece of code. This code is actually snipped from generateDS.py itself. I've included it as an example of how content could be found an inserted from various sources. As you can see from the commented-out version, you could also check the local file system if the document could not be found on the Web. Or, perhaps, a version that checked for the protocol with something like: if path.startswith('http:'): and: elif path.startswith('ftp:'): and: elif path.startswith('file:'): and so on. I suppose it also matters which order we try each of the different sources/ locations. Let me know what your thoughts are on this and whether you feel something like this is would be useful in process_includes.py. By the way, Chris, the version of process_includes.py that I have already checks for each of xml.etree.ElementTree (from Python 2.5), lxml, and elementtree.ElementTree (in that order). Are you using an older/different version from mine? - Dave # ================================================================ # # Retrieve the implementation body via an HTTP request to a # URL formed from the concatenation of the baseImplUrl and the # implUrl. # An alternative implementation of get_impl_body() that also # looks in the local file system is commented out below. # def get_impl_body(classBehavior, baseImplUrl, implUrl): impl = ' pass\n' if implUrl: if baseImplUrl: implUrl = '%s%s' % (baseImplUrl, implUrl) try: implFile = urllib2.urlopen(implUrl) impl = implFile.read() implFile.close() except urllib2.HTTPError: print '*** Implementation at %s not found.' % implUrl except urllib2.URLError: print '*** Connection refused for URL: %s' % implUrl return impl ### ### This alternative implementation of get_impl_body() tries the URL ### via http first, then, if that fails, looks in a directory on ### the local file system (baseImplUrl) for a file (implUrl) ### containing the implementation body. ### ##def get_impl_body(classBehavior, baseImplUrl, implUrl): ## impl = ' pass\n' ## if implUrl: ## trylocal = 0 ## if baseImplUrl: ## implUrl = '%s%s' % (baseImplUrl, implUrl) ## try: ## implFile = urllib2.urlopen(implUrl) ## impl = implFile.read() ## implFile.close() ## except: ## trylocal = 1 ## if trylocal: ## try: ## implFile = file(implUrl) ## impl = implFile.read() ## implFile.close() ## except: ## print '*** Implementation at %s not found.' % implUrl ## return impl # ================================================================ ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ generateds-users mailing list generateds-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/generateds-users