You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i found a little problem in the externalEntityRefHandler() function of the Parser class.
My input:
handle = Entrez.efetch(id = "1134002", db = "biosystems", retmode = "xml")
data = Entrez.read(handle)
handle.close()
causes a "UnboundLocalError: local variable 'url' referenced before assignment" here:
Parser.py start line 469
if urlinfo[0]=='http':
# Then this is an absolute path to the DTD.
url = systemId
elif urlinfo[0]=='':
# Then this is a relative path to the DTD.
# Look at the parent URL to find the full path.
try:
url = self.dtd_urls[-1]
except IndexError:
# Assume the default URL for DTDs if the top parent
# does not contain an absolute path
source = "http://www.ncbi.nlm.nih.gov/dtd/"
else:
source = os.path.dirname(url)
# urls always have a forward slash, don't use os.path.join
url = source.rstrip("/") + "/" + systemId
self.dtd_urls.append(url)
because the urlinfo[0] parameter is set to "ftp" in my case. That case is not handled by the if/elif construct and causes the UnboundLocalError.
For this specific case, perhaps we can switch to if urlinfo[0] in ['http', 'https', 'ftp']: or similar to detect an absolute URL? However, separately when urlinfo[0]=='' the code is mixing the url and source variables...
@Thargor128 can you create a Pull Request? I would also suggest to use urlinfo.scheme instead of urlinfo[0], as the latter is only needed for Python older than 2.5, while Biopython nowadays requires version 2.6 at least.
@mdehoon Note that the workaround I proposed doesn't fix the underlying problem in the code (line source = os.path.dirname(url) using url which has not been defined).
Activity
peterjc commentedon Apr 23, 2015
Confirmed, your test case fails for me too.
For this specific case, perhaps we can switch to
if urlinfo[0] in ['http', 'https', 'ftp']:or similar to detect an absolute URL? However, separately whenurlinfo[0]==''the code is mixing theurlandsourcevariables...mdehoon commentedon May 1, 2015
@Thargor128 can you create a Pull Request? I would also suggest to use urlinfo.scheme instead of urlinfo[0], as the latter is only needed for Python older than 2.5, while Biopython nowadays requires version 2.6 at least.
peterjc commentedon May 4, 2015
@mdehoon Note that the workaround I proposed doesn't fix the underlying problem in the code (line
source = os.path.dirname(url)usingurlwhich has not been defined).@Thargor128 if you want to submit this as a pull request, start by forking biopython/biopython on GitHub to make Thargor128/biopython (just click fork and follow defaults). Then at the command line ideally make a branch from our master branch. See http://biopython.org/wiki/GitUsage
Cope with FTP references in Entrez XML.
peterjc commentedon May 12, 2015
I think 0c4bd6a fixes this (including a test based on your bug report). Thank you!