prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  "[Errno 36] File name too long:" when using imread on remote resource with long querystring
  ## Description
  When using skimage.io.imread with a remote resource, a long query string on the remote resource will cause a failure to read the remote resource, because the temporary file cannot be created.
  
  e.g. 
  
  The following works fine
  ```
  >>> im = imread('https://c1.staticflickr.com/9/8370/8429454143_1066b73c04_o.jpg?{}'.format(''.join(['s' for i in range(100)])))
  
  ```
  
  while the one below fails
  
  ```
  >>> im = imread('https://c1.staticflickr.com/9/8370/8429454143_1066b73c04_o.jpg?{}'.format(''.join(['s' for i in range(300)])))
  Traceback (most recent call last):
    File "/usr/local/lib/python3.5/dist-packages/skimage/io/util.py", line 28, in file_or_url_context
      with tempfile.NamedTemporaryFile(delete=False, suffix=ext) as f:
    File "/usr/lib/python3.5/tempfile.py", line 688, in NamedTemporaryFile
      (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags, output_type)
    File "/usr/lib/python3.5/tempfile.py", line 399, in _mkstemp_inner
      fd = _os.open(file, flags, 0o600)
  OSError: [Errno 36] File name too long: '/tmp/tmpmfnujlq6.jpg?ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss'
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/local/lib/python3.5/dist-packages/skimage/io/_io.py", line 61, in imread
      with file_or_url_context(fname) as fname:
    File "/usr/lib/python3.5/contextlib.py", line 59, in __enter__
      return next(self.gen)
    File "/usr/local/lib/python3.5/dist-packages/skimage/io/util.py", line 34, in file_or_url_context
      os.remove(f.name)
  UnboundLocalError: local variable 'f' referenced before assignment
  
  ```
  
  ## Way to reproduce
  [If reporting a bug, please include the following important information:]
  - [x] Code example
  - [x] Operating system and version
  ```
  DISTRIB_ID=Ubuntu
  DISTRIB_RELEASE=16.04
  DISTRIB_CODENAME=xenial
  DISTRIB_DESCRIPTION="Ubuntu 16.04.5 LTS"
  ```
  - [x] Python version: Python 3.5.2
  - [x] scikit-image version (run `skimage.__version__`): skimage.__version__
  '0.14.1'
  
  ## Proposal
  
  https://github.com/scikit-image/scikit-image/blob/d24634d86e4f90fe96377209d66ed114b9b601e4/skimage/io/util.py#L22
  
  The querystring should be excluded from the temporary file name extension
  
  </issue>
  <code>
  [start of skimage/io/util.py]
  1 from urllib.request import urlopen
  2 
  3 import os
  4 import re
  5 import tempfile
  6 from contextlib import contextmanager
  7 
  8 
  9 URL_REGEX = re.compile(r'http://|https://|ftp://|file://|file:\\')
  10 
  11 
  12 def is_url(filename):
  13     """Return True if string is an http or ftp path."""
  14     return (isinstance(filename, str) and
  15             URL_REGEX.match(filename) is not None)
  16 
  17 
  18 @contextmanager
  19 def file_or_url_context(resource_name):
  20     """Yield name of file from the given resource (i.e. file or url)."""
  21     if is_url(resource_name):
  22         _, ext = os.path.splitext(resource_name)
  23         try:
  24             with tempfile.NamedTemporaryFile(delete=False, suffix=ext) as f:
  25                 u = urlopen(resource_name)
  26                 f.write(u.read())
  27             # f must be closed before yielding
  28             yield f.name
  29         finally:
  30             os.remove(f.name)
  31     else:
  32         yield resource_name
  33
  [end of skimage/io/util.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/skimage/io/util.py b/skimage/io/util.py
  --- a/skimage/io/util.py
  +++ b/skimage/io/util.py
  @@ -1,4 +1,4 @@
  -from urllib.request import urlopen
  +import urllib.parse
   
   import os
   import re
  @@ -19,10 +19,11 @@
   def file_or_url_context(resource_name):
       """Yield name of file from the given resource (i.e. file or url)."""
       if is_url(resource_name):
  -        _, ext = os.path.splitext(resource_name)
  +        url_components = urllib.parse.urlparse(resource_name)
  +        _, ext = os.path.splitext(url_components.path)
           try:
               with tempfile.NamedTemporaryFile(delete=False, suffix=ext) as f:
  -                u = urlopen(resource_name)
  +                u = urllib.request.urlopen(resource_name)
                   f.write(u.read())
               # f must be closed before yielding
               yield f.name
  
verification_info: {"golden_diff": "diff --git a/skimage/io/util.py b/skimage/io/util.py\n--- a/skimage/io/util.py\n+++ b/skimage/io/util.py\n@@ -1,4 +1,4 @@\n-from urllib.request import urlopen\n+import urllib.parse\n \n import os\n import re\n@@ -19,10 +19,11 @@\n def file_or_url_context(resource_name):\n     \"\"\"Yield name of file from the given resource (i.e. file or url).\"\"\"\n     if is_url(resource_name):\n-        _, ext = os.path.splitext(resource_name)\n+        url_components = urllib.parse.urlparse(resource_name)\n+        _, ext = os.path.splitext(url_components.path)\n         try:\n             with tempfile.NamedTemporaryFile(delete=False, suffix=ext) as f:\n-                u = urlopen(resource_name)\n+                u = urllib.request.urlopen(resource_name)\n                 f.write(u.read())\n             # f must be closed before yielding\n             yield f.name\n", "issue": "\"[Errno 36] File name too long:\" when using imread on remote resource with long querystring\n## Description\r\nWhen using skimage.io.imread with a remote resource, a long query string on the remote resource will cause a failure to read the remote resource, because the temporary file cannot be created.\r\n\r\ne.g. \r\n\r\nThe following works fine\r\n```\r\n>>> im = imread('https://c1.staticflickr.com/9/8370/8429454143_1066b73c04_o.jpg?{}'.format(''.join(['s' for i in range(100)])))\r\n\r\n```\r\n\r\nwhile the one below fails\r\n\r\n```\r\n>>> im = imread('https://c1.staticflickr.com/9/8370/8429454143_1066b73c04_o.jpg?{}'.format(''.join(['s' for i in range(300)])))\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python3.5/dist-packages/skimage/io/util.py\", line 28, in file_or_url_context\r\n    with tempfile.NamedTemporaryFile(delete=False, suffix=ext) as f:\r\n  File \"/usr/lib/python3.5/tempfile.py\", line 688, in NamedTemporaryFile\r\n    (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags, output_type)\r\n  File \"/usr/lib/python3.5/tempfile.py\", line 399, in _mkstemp_inner\r\n    fd = _os.open(file, flags, 0o600)\r\nOSError: [Errno 36] File name too long: '/tmp/tmpmfnujlq6.jpg?ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss'\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\n  File \"/usr/local/lib/python3.5/dist-packages/skimage/io/_io.py\", line 61, in imread\r\n    with file_or_url_context(fname) as fname:\r\n  File \"/usr/lib/python3.5/contextlib.py\", line 59, in __enter__\r\n    return next(self.gen)\r\n  File \"/usr/local/lib/python3.5/dist-packages/skimage/io/util.py\", line 34, in file_or_url_context\r\n    os.remove(f.name)\r\nUnboundLocalError: local variable 'f' referenced before assignment\r\n\r\n```\r\n\r\n## Way to reproduce\r\n[If reporting a bug, please include the following important information:]\r\n- [x] Code example\r\n- [x] Operating system and version\r\n```\r\nDISTRIB_ID=Ubuntu\r\nDISTRIB_RELEASE=16.04\r\nDISTRIB_CODENAME=xenial\r\nDISTRIB_DESCRIPTION=\"Ubuntu 16.04.5 LTS\"\r\n```\r\n- [x] Python version: Python 3.5.2\r\n- [x] scikit-image version (run `skimage.__version__`): skimage.__version__\r\n'0.14.1'\r\n\r\n## Proposal\r\n\r\nhttps://github.com/scikit-image/scikit-image/blob/d24634d86e4f90fe96377209d66ed114b9b601e4/skimage/io/util.py#L22\r\n\r\nThe querystring should be excluded from the temporary file name extension\n", "before_files": [{"content": "from urllib.request import urlopen\n\nimport os\nimport re\nimport tempfile\nfrom contextlib import contextmanager\n\n\nURL_REGEX = re.compile(r'http://|https://|ftp://|file://|file:\\\\')\n\n\ndef is_url(filename):\n    \"\"\"Return True if string is an http or ftp path.\"\"\"\n    return (isinstance(filename, str) and\n            URL_REGEX.match(filename) is not None)\n\n\n@contextmanager\ndef file_or_url_context(resource_name):\n    \"\"\"Yield name of file from the given resource (i.e. file or url).\"\"\"\n    if is_url(resource_name):\n        _, ext = os.path.splitext(resource_name)\n        try:\n            with tempfile.NamedTemporaryFile(delete=False, suffix=ext) as f:\n                u = urlopen(resource_name)\n                f.write(u.read())\n            # f must be closed before yielding\n            yield f.name\n        finally:\n            os.remove(f.name)\n    else:\n        yield resource_name\n", "path": "skimage/io/util.py"}]}