# Buggy code
def __init__(
    self,
    filename,
    width=None,
    height=None,
    kind="direct",
    mask="auto",
    lazy=1,
    client=None,
    target=None,
):
    # Client is mandatory.  Perhaps move it farther up if we refactor
    assert client is not None
    self.__kind = kind

    if filename.split("://")[0].lower() in ("http", "ftp", "https"):
        try:
            filename2, _ = urllib.urlretrieve(filename)
            if filename != filename2:
                client.to_unlink.append(filename2)
                filename = filename2
        except IOError:
            filename = missing
    self.filename, self._backend = self.get_backend(filename, client)
    srcinfo = client, self.filename

    if kind == "percentage_of_container":
        self.image = self._backend(
            self.filename, width, height, "direct", mask, lazy, srcinfo
        )
        self.image.drawWidth = width
        self.image.drawHeight = height
        self.__width = width
        self.__height = height
    else:
        self.image = self._backend(
            self.filename, width, height, kind, mask, lazy, srcinfo
        )
    self.__ratio = float(self.image.imageWidth) / self.image.imageHeight
    self.__wrappedonce = False
    self.target = target


# Traceback (AttributeError)
Traceback (most recent call last):
File "/home/sroeca/.pyenv/versions/test-rst-mzrgg/bin/rst2pdf", line 11, in <module>
load_entry_point('rst2pdf', 'console_scripts', 'rst2pdf')()
File "/home/sroeca/src/sandbox/test-rst/rst2pdf/rst2pdf/createpdf.py", line 1496, in main
compressed=options.compressed)
File "/home/sroeca/src/sandbox/test-rst/rst2pdf/rst2pdf/createpdf.py", line 553, in createPdf
elements = self.gen_elements(self.doctree)
File "/home/sroeca/src/sandbox/test-rst/rst2pdf/rst2pdf/basenodehandler.py", line 253, in elemdispatch
elements = self.getelements(client, node, style)
File "/home/sroeca/src/sandbox/test-rst/rst2pdf/rst2pdf/basenodehandler.py", line 228, in getelements
elements = self.gather_elements(client, node, style)
File "/home/sroeca/src/sandbox/test-rst/rst2pdf/rst2pdf/basenodehandler.py", line 208, in gather_elements
return client.gather_elements(node, style=style)
File "/home/sroeca/src/sandbox/test-rst/rst2pdf/rst2pdf/createpdf.py", line 385, in gather_elements
r.extend(self.gen_elements(n, style=style))
File "/home/sroeca/src/sandbox/test-rst/rst2pdf/rst2pdf/basenodehandler.py", line 253, in elemdispatch
elements = self.getelements(client, node, style)
File "/home/sroeca/src/sandbox/test-rst/rst2pdf/rst2pdf/basenodehandler.py", line 228, in getelements
elements = self.gather_elements(client, node, style)
File "/home/sroeca/src/sandbox/test-rst/rst2pdf/rst2pdf/genelements.py", line 432, in gather_elements
elements = client.gather_elements(node)
File "/home/sroeca/src/sandbox/test-rst/rst2pdf/rst2pdf/createpdf.py", line 385, in gather_elements
r.extend(self.gen_elements(n, style=style))
File "/home/sroeca/src/sandbox/test-rst/rst2pdf/rst2pdf/basenodehandler.py", line 253, in elemdispatch
elements = self.getelements(client, node, style)
File "/home/sroeca/src/sandbox/test-rst/rst2pdf/rst2pdf/basenodehandler.py", line 228, in getelements
elements = self.gather_elements(client, node, style)
File "/home/sroeca/src/sandbox/test-rst/rst2pdf/rst2pdf/genpdftext.py", line 158, in gather_elements
w, h, kind = MyImage.size_for_node(node, client=client)
File "/home/sroeca/src/sandbox/test-rst/rst2pdf/rst2pdf/image.py", line 223, in size_for_node
uri, _ = urllib.urlretrieve(uri)
AttributeError: module 'urllib' has no attribute 'urlretrieve'

# Fixed code
def __init__(
    self,
    filename,
    width=None,
    height=None,
    kind="direct",
    mask="auto",
    lazy=1,
    client=None,
    target=None,
):
    # Client is mandatory.  Perhaps move it farther up if we refactor
    assert client is not None
    self.__kind = kind

    if filename.split("://")[0].lower() in ("http", "ftp", "https"):
        try:
            filename2, _ = urlretrieve(filename)
            if filename != filename2:
                client.to_unlink.append(filename2)
                filename = filename2
        except IOError:
            filename = missing
    self.filename, self._backend = self.get_backend(filename, client)
    srcinfo = client, self.filename

    if kind == "percentage_of_container":
        self.image = self._backend(
            self.filename, width, height, "direct", mask, lazy, srcinfo
        )
        self.image.drawWidth = width
        self.image.drawHeight = height
        self.__width = width
        self.__height = height
    else:
        self.image = self._backend(
            self.filename, width, height, kind, mask, lazy, srcinfo
        )
    self.__ratio = float(self.image.imageWidth) / self.image.imageHeight
    self.__wrappedonce = False
    self.target = target