Skip to content

Commit

Permalink
Macstodon 0.4.4 - fixes a rare crash that can happen after auth
Browse files Browse the repository at this point in the history
  • Loading branch information
smallsco committed Feb 24, 2023
1 parent f19f0ea commit 607d30d
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion AuthHandler.py
100755 → 100644

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions CHANGELOG.md
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## CHANGELOG

### v0.4.4 (2023-02-23)

* Fixed an edge case where the app could crash after authenticating.
* Updated some links in documentation.
* Updated copyright year to 2023.

### v0.4.3 (2022-12-23)

* Repackaged the v0.4.2 release but with separate 68K and PPC apps instead of a Fat Binary.
Expand Down
2 changes: 1 addition & 1 deletion ImageHandler.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"""Macstodon - a Mastodon client for classic Mac OSMIT LicenseCopyright (c) 2022 Scott Small and ContributorsPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associateddocumentation files (the "Software"), to deal in the Software without restriction, including without limitation therights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permitpersons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of theSoftware.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THEWARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS ORCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OROTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."""# ############### Python Imports # ##############import Imageimport GifImagePluginimport JpegImagePluginimport PngImagePluginimport osimport stringimport sysimport urllibimport urlparse# #################### Third-Party Imports# ###################from third_party.PixMapWrapper import PixMapWrapper# ########### My Imports# ##########from MacstodonHelpers import dprint# ############ Application# ###########class ImageHandler: def __init__(self, app): """ Initializes the ImageHandler class. """ self.app = app def getImageFromURL(self, url, cache=None): """ Wrapper function - given an image URL, either downloads and caches the image, or loads it from the cache if it already exists there. """ try: if cache: file_name = self.getFilenameFromURL(url) if not self.isCached(file_name, cache): self.downloadImage(url, file_name, cache) img = self.resizeAndGetImage(file_name, cache) else: img = self.getImageFromCache(file_name, cache) else: temp_path = self.downloadImage(url) img = self.resizeAndGetImage(temp_path) urllib.urlcleanup() return img except: etype, evalue = sys.exc_info()[:2] dprint("Error loading image: %s: %s" % (etype, evalue)) return None def getFilenameFromURL(self, url): """ Returns the file name, including extension, from a URL. i.e. http://www.google.ca/foo/bar/baz/asdf.jpg returns "asdf.jpg" """ parsed_url = urlparse.urlparse(url) path = parsed_url[2] file_name = os.path.basename(string.replace(path, "/", ":")) return file_name def isCached(self, file_name, cache): """ Checks if an image exists in cache or not and returns true/false. """ if cache == "account": cachepath = self.app.cacheacctfolderpath elif cache == "media": cachepath = self.app.cachemediafolderpath try: os.stat(os.path.join(cachepath, file_name)) return 1 except: exc_info = sys.exc_info() if str(exc_info[0]) == "mac.error" and exc_info[1][0] == 2: return 0 raise def getImageFromCache(self, file_name, cache): """ Loads an image file from the cache. """ pm = PixMapWrapper() if cache == "account": file_path = os.path.join(self.app.cacheacctfolderpath, file_name) elif cache == "media": file_path = os.path.join(self.app.cachemediafolderpath, file_name) pil_image = Image.open(file_path) pm.fromImage(pil_image) del pil_image return pm def downloadImage(self, url, file_name=None, cache=None): """ Downloads an image from the given URL and writes it to the cache. """ http_url = string.replace(url, "https://", "http://") if cache == "account": file_path = os.path.join(self.app.cacheacctfolderpath, file_name) urllib.urlretrieve(http_url, file_path) elif cache == "media": file_path = os.path.join(self.app.cachemediafolderpath, file_name) urllib.urlretrieve(http_url, file_path) else: file_path = None dest_path, headers = urllib.urlretrieve(http_url) return dest_path def resizeAndGetImage(self, file_name, cache=None): """ Resizes an image to 48x48 pixels and overwrites the existing cached image. """ if cache == "account": file_path = os.path.join(self.app.cacheacctfolderpath, file_name) elif cache == "media": file_path = os.path.join(self.app.cachemediafolderpath, file_name) else: file_path = file_name pil_image = Image.open(file_path) pil_image_small = pil_image.resize((48, 48)) del pil_image pil_image_small.save(file_path) pm = PixMapWrapper() pm.fromImage(pil_image_small) del pil_image_small return pm
"""Macstodon - a Mastodon client for classic Mac OSMIT LicenseCopyright (c) 2022-2023 Scott Small and ContributorsPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associateddocumentation files (the "Software"), to deal in the Software without restriction, including without limitation therights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permitpersons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of theSoftware.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THEWARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS ORCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OROTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."""# ############### Python Imports # ##############import Imageimport GifImagePluginimport JpegImagePluginimport PngImagePluginimport osimport stringimport sysimport urllibimport urlparse# #################### Third-Party Imports# ###################from third_party.PixMapWrapper import PixMapWrapper# ########### My Imports# ##########from MacstodonHelpers import dprint# ############ Application# ###########class ImageHandler: def __init__(self, app): """ Initializes the ImageHandler class. """ self.app = app def getImageFromURL(self, url, cache=None): """ Wrapper function - given an image URL, either downloads and caches the image, or loads it from the cache if it already exists there. """ try: if cache: file_name = self.getFilenameFromURL(url) if not self.isCached(file_name, cache): self.downloadImage(url, file_name, cache) img = self.resizeAndGetImage(file_name, cache) else: img = self.getImageFromCache(file_name, cache) else: temp_path = self.downloadImage(url) img = self.resizeAndGetImage(temp_path) urllib.urlcleanup() return img except: etype, evalue = sys.exc_info()[:2] dprint("Error loading image: %s: %s" % (etype, evalue)) return None def getFilenameFromURL(self, url): """ Returns the file name, including extension, from a URL. i.e. http://www.google.ca/foo/bar/baz/asdf.jpg returns "asdf.jpg" """ parsed_url = urlparse.urlparse(url) path = parsed_url[2] file_name = os.path.basename(string.replace(path, "/", ":")) return file_name def isCached(self, file_name, cache): """ Checks if an image exists in cache or not and returns true/false. """ if cache == "account": cachepath = self.app.cacheacctfolderpath elif cache == "media": cachepath = self.app.cachemediafolderpath try: os.stat(os.path.join(cachepath, file_name)) return 1 except: exc_info = sys.exc_info() if str(exc_info[0]) == "mac.error" and exc_info[1][0] == 2: return 0 raise def getImageFromCache(self, file_name, cache): """ Loads an image file from the cache. """ pm = PixMapWrapper() if cache == "account": file_path = os.path.join(self.app.cacheacctfolderpath, file_name) elif cache == "media": file_path = os.path.join(self.app.cachemediafolderpath, file_name) pil_image = Image.open(file_path) pm.fromImage(pil_image) del pil_image return pm def downloadImage(self, url, file_name=None, cache=None): """ Downloads an image from the given URL and writes it to the cache. """ http_url = string.replace(url, "https://", "http://") if cache == "account": file_path = os.path.join(self.app.cacheacctfolderpath, file_name) urllib.urlretrieve(http_url, file_path) elif cache == "media": file_path = os.path.join(self.app.cachemediafolderpath, file_name) urllib.urlretrieve(http_url, file_path) else: file_path = None dest_path, headers = urllib.urlretrieve(http_url) return dest_path def resizeAndGetImage(self, file_name, cache=None): """ Resizes an image to 48x48 pixels and overwrites the existing cached image. """ if cache == "account": file_path = os.path.join(self.app.cacheacctfolderpath, file_name) elif cache == "media": file_path = os.path.join(self.app.cachemediafolderpath, file_name) else: file_path = file_name pil_image = Image.open(file_path) pil_image_small = pil_image.resize((48, 48)) del pil_image pil_image_small.save(file_path) pm = PixMapWrapper() pm.fromImage(pil_image_small) del pil_image_small return pm
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Scott Small
Copyright (c) 2022-2023 Scott Small and Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading

0 comments on commit 607d30d

Please sign in to comment.