nebius/SWE-bench-extra huggingface dataset:
Repository: imageio/imageio

Issue:
imageiov2.10.1. The imwrite will raise ValueError when filename include "#".
Imageio V2.10.1
```
import imageio
import numpy as np

imageio.imwrite('#1.jpg', np.zeros([512, 512, 3], dtype=np.uint8))
```
It will raise ValueError: Could not find a format to read the specified file in ImageMode.single_image mode.

But it will good. No raise.
```
imageio.imwrite('#1.jpg', np.zeros([512, 512, 3], dtype=np.uint8), '.jpg')
```

Comments:

Patch:
diff --git a/imageio/core/request.py b/imageio/core/request.py
index d24e259..d2ddae2 100644
--- a/imageio/core/request.py
+++ b/imageio/core/request.py
@@ -244,8 +244,11 @@ class Request(object):
 
         # Set extension
         if self._filename is not None:
-            parts = urlparse(self._filename)
-            ext = Path(parts.path).suffix.lower()
+            if self._uri_type in (URI_FILENAME, URI_ZIPPED):
+                path = self._filename
+            else:
+                path = urlparse(self._filename).path
+            ext = Path(path).suffix.lower()
             self._extension = ext if ext != "" else None
 
     def _parse_uri(self, uri):


Test patch:
diff --git a/tests/test_core.py b/tests/test_core.py
index bcb584e..9700f5e 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -783,6 +783,21 @@ def test_imwrite_not_array_like():
         imageio.imwrite("foo.bmp", "asd")
 
 
+def test_imwrite_symbol_name():
+    # this is a regression test for https://github.com/imageio/imageio/issues/674
+    if sys.platform == "linux":
+        name = """#!~:@$%^&`-+{};',.()? []_=.jpg"""
+    elif sys.platform == "win32":
+        name = """#!~@$%^&`-+{};',.() []_=.jpg"""
+    elif sys.platform == "darwin":
+        name = """#!~@$%^&`-+{};',.()? []_=.jpg"""
+    else:
+        pytest.skip("Unknown OS.")
+    tmp_request = imageio.core.Request(name, "w")
+    assert tmp_request.extension == ".jpg"
+    tmp_request.finish()
+
+
 def test_legacy_empty_image():
     with pytest.raises(RuntimeError):
         with iio.imopen("foo.bmp", "wI", format="GIF-PIL") as file: