Repository: bird-house/birdy

Issue:
`guess_type` function does not support Path objects. 

Comments:

Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index eee7b6e..74850b8 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -8,6 +8,7 @@ Changes:
 
 * Added a converter for loading GeoTIFF using xarray/rioxarray (#193).
 * Update notebook process forms. See `client.gui` function.
+* Add support for Path objects in `utils.guess_type`
 * Support multiple mimetypes in converters. API change: mimetype (str) replaced by mimetypes (tuple)
 * Removed geojson mimetypes from BINARY_MIMETYPES so it's embedded as a string rather than bytes.
 
diff --git a/birdy/utils.py b/birdy/utils.py
index eed9134..39cf0e5 100644
--- a/birdy/utils.py
+++ b/birdy/utils.py
@@ -136,7 +136,7 @@ def guess_type(url, supported):
 
     Parameters
     ----------
-    url : str
+    url : str, Path
       Path or URL to file.
     supported : list, tuple
       Supported mimetypes.
@@ -148,7 +148,7 @@ def guess_type(url, supported):
     import mimetypes
 
     try:
-        mime, enc = mimetypes.guess_type(url, strict=False)
+        mime, enc = mimetypes.guess_type(str(url), strict=False)
     except TypeError:
         mime, enc = None, None
 
@@ -158,7 +158,7 @@ def guess_type(url, supported):
     # netCDF
     if (
         mime == "application/x-netcdf"
-        and "dodsC" in url
+        and "dodsC" in str(url)
         and "application/x-ogc-dods" in supported
     ):
         mime = "application/x-ogc-dods"
@@ -169,14 +169,15 @@ def guess_type(url, supported):
         if mime in zips and set(zips).intersection(supported):
             mime = set(zips).intersection(supported).pop()
 
+    # GeoJSON
+    if mime == "application/json" and "application/geo+json" in supported:
+        mime = "application/geo+json"
+
     # FIXME: Verify whether this code is needed. Remove if not.
     # # GeoTIFF (workaround since this mimetype isn't correctly understoud)
     # if mime == "image/tiff" and (".tif" in url or ".tiff" in "url"):
     #     mime = "image/tiff; subtype=geotiff"
     #
-    # # GeoJSON (workaround since this mimetype isn't correctly understoud)
-    # if mime == "application/geo+json":
-    #     mime = "application/vnd.geo+json"
 
     # All the various XML schemes
     # TODO


Test patch:
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 2121501..1aa827b 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -95,3 +95,22 @@ class TestGuessType:  # noqa: D101
             ["application/x-ogc-dods", "application/x-netcdf"],
         )
         assert mime == "application/x-netcdf"
+
+    def test_path(self):  # noqa: D102
+        from pathlib import Path
+
+        mime, enc = utils.guess_type(
+            Path("shape.json"), ["wrong", "application/geo+json"]
+        )
+        assert mime == "application/geo+json"
+
+        mime, enc = utils.guess_type(
+            Path("data.nc"), ["application/x-ogc-dods", "application/x-netcdf"]
+        )
+        assert mime == "application/x-netcdf"
+
+        mime, enc = utils.guess_type(
+            Path("file:///dodsC/data.nc"),
+            ["application/x-netcdf", "application/x-ogc-dods"],
+        )
+        assert mime == "application/x-ogc-dods"