Skip to content

Parser:externalEntityRefHandler() #527

Closed

Description

Hello,

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.

Activity

  1. peterjc commented on Apr 23, 2015

    @peterjc
    Member

    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 when urlinfo[0]=='' the code is mixing the url and source variables...

  2. mdehoon commented on May 1, 2015

    @mdehoon
    Contributor

    @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.

  3. peterjc commented on May 4, 2015

    @peterjc
    Member

    @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).

    @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

  4. peterjc commented on May 12, 2015

    @peterjc
    Member

    I think 0c4bd6a fixes this (including a test based on your bug report). Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions