Skip to content

Commit

Permalink
Adjustments to additional_mimes
Browse files Browse the repository at this point in the history
Work with a member attribute rather than the class one.
Default to empty dict rather than None.

Bump version

Revert
  • Loading branch information
ahaith committed Jul 28, 2022
1 parent 51ddfb9 commit c504b72
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from setuptools import setup

# Update version here when you want to increment the version in PyPi
sdk_version = '0.4.7'
sdk_version = '0.4.8'

# If no ZEGAMI_SDK_VERSION set use the version
try:
Expand Down
19 changes: 11 additions & 8 deletions zegami_sdk/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class UploadableSource():
)

def __init__(self, name, image_dir, column_filename='__auto_join__', recursive_search=True, filename_filter=[],
additional_mimes=None):
additional_mimes={}):
"""
Used in conjunction with create_collection().
Expand All @@ -142,6 +142,10 @@ def __init__(self, name, image_dir, column_filename='__auto_join__', recursive_s
To limit to an allowed specific list of filenames, provide
'filename_filter'. This filter will check against
os.path.basename(filepath).
Common mime types are inferred from the file extension,
but a dict of additional mime type mappings can be provided eg to
cater for files with no extension.
"""

self.name = name
Expand All @@ -152,7 +156,7 @@ def __init__(self, name, image_dir, column_filename='__auto_join__', recursive_s
self._source = None
self._index = None

UploadableSource.IMAGE_MIMES = {**UploadableSource.IMAGE_MIMES, **additional_mimes}
self.image_mimes = {**UploadableSource.IMAGE_MIMES, **additional_mimes}

# Check the directory exists
if not os.path.exists(image_dir):
Expand Down Expand Up @@ -390,15 +394,14 @@ def _parse_list(cls, uploadable_sources) -> list:

return uploadable_sources

@classmethod
def _get_mime_type(cls, path) -> str:
def _get_mime_type(self, path) -> str:
"""Gets the mime_type of the path. Raises an error if not a valid image mime_type."""
if '.' not in path:
return cls.IMAGE_MIMES['']
return self.image_mimes['']
ext = os.path.splitext(path)[-1]
if ext in cls.IMAGE_MIMES.keys():
return cls.IMAGE_MIMES[ext]
raise TypeError('"{}" is not a supported image mime_type ({})'.format(path, cls.IMAGE_MIMES))
if ext in self.image_mimes.keys():
return self.image_mimes[ext]
raise TypeError('"{}" is not a supported image mime_type ({})'.format(path, self.image_mimes))


class UrlSource(UploadableSource):
Expand Down

0 comments on commit c504b72

Please sign in to comment.