Skip to content

Commit

Permalink
Now passing strings to mimetypes.guess_extension.
Browse files Browse the repository at this point in the history
Also changing the default for images to .img (from None).

Also, whatever was originally implementing mime2extension did not include
the leading dot that mimetypes includes.  We are doing away with that, too.

This is supposed to address bug #552.
  • Loading branch information
msdemlei committed Jun 12, 2024
1 parent bfd75c9 commit 95d36b2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pyvo/dal/mimetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def mime2extension(mimetype, default=None):
if not mimetype:
return default

if isinstance(mimetype, str):
mimetype = mimetype.encode('utf-8')
if isinstance(mimetype, bytes):
mimetype = mimetype.decode('utf-8')

ext = mimetypes.guess_extension(mimetype, strict=False)
return ext
return ext[1:]


def mime_object_maker(url, mimetype, *, session=None):
Expand Down
2 changes: 1 addition & 1 deletion pyvo/dal/sia.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ def suggest_dataset_basename(self):
out = re.sub(r'\s+', '_', out.strip())
return out

def suggest_extension(self, *, default=None):
def suggest_extension(self, *, default='img'):
"""
returns a recommended filename extension for the dataset described
by this record. Typically, this would look at the column describing
Expand Down

0 comments on commit 95d36b2

Please sign in to comment.