33
33
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34
34
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
35
35
# THE SOFTWARE.
36
+ from __future__ import annotations
36
37
37
38
import hashlib
38
39
import math
@@ -88,7 +89,8 @@ def prepare_image(self, width, height):
88
89
are those specified by width and height.
89
90
"""
90
91
if self .image :
91
- raise Exception ("Image already prepared." )
92
+ msg = "Image already prepared."
93
+ raise Exception (msg )
92
94
self .image = self .create_image (width , height )
93
95
94
96
def destroy_image (self ):
@@ -107,12 +109,14 @@ def paste_image_file(self, image_file, xy):
107
109
of that image, pastes the image into this object's internal image.
108
110
"""
109
111
if not self .image :
110
- raise Exception ("Image not prepared" )
112
+ msg = "Image not prepared"
113
+ raise Exception (msg )
111
114
112
115
try :
113
116
img = self .load_image_file (image_file )
114
117
except Exception as e :
115
- raise Exception (f"Could not load image { image_file } \n { e } " )
118
+ msg = f"Could not load image { image_file } \n { e } "
119
+ raise Exception (msg )
116
120
117
121
self .paste_image (img , xy )
118
122
del img
@@ -135,7 +139,8 @@ def __init__(self):
135
139
try :
136
140
import pygame
137
141
except ImportError :
138
- raise Exception ("Pygame could not be imported!" )
142
+ msg = "Pygame could not be imported!"
143
+ raise Exception (msg )
139
144
self .pygame = pygame
140
145
141
146
def create_image (self , width , height ):
@@ -164,7 +169,8 @@ def __init__(self, mode):
164
169
try :
165
170
import PIL .Image
166
171
except ImportError :
167
- raise Exception ("PIL could not be imported!" )
172
+ msg = "PIL could not be imported!"
173
+ raise Exception (msg )
168
174
self .PILImage = PIL .Image
169
175
170
176
def create_image (self , width , height ):
@@ -243,7 +249,8 @@ def __init__(self, **kwargs):
243
249
print (f"WARNING: Using { self .cache } to cache map tiles." )
244
250
if not os .access (self .cache , os .R_OK | os .W_OK ):
245
251
print (f" ERROR: Insufficient access to { self .cache } ." )
246
- raise Exception ("Unable to find/create/use map tile cache directory." )
252
+ msg = "Unable to find/create/use map tile cache directory."
253
+ raise Exception (msg )
247
254
248
255
# Get URL template, which supports the following fields:
249
256
# * {z}: tile zoom level
@@ -279,7 +286,8 @@ def __init__(self, **kwargs):
279
286
if mgr : # Assume it's a valid manager
280
287
self .manager = mgr
281
288
else :
282
- raise Exception ("OSMManager.__init__ requires argument image_manager" )
289
+ msg = "OSMManager.__init__ requires argument image_manager"
290
+ raise Exception (msg )
283
291
284
292
def get_tile_coord (self , lon_deg , lat_deg , zoom ):
285
293
"""
@@ -327,7 +335,8 @@ def retrieve_tile_image(self, tile_coord, zoom):
327
335
try :
328
336
urlretrieve (url , filename = filename )
329
337
except Exception as e :
330
- raise Exception (f"Unable to retrieve URL: { url } \n { e } " )
338
+ msg = f"Unable to retrieve URL: { url } \n { e } "
339
+ raise Exception (msg )
331
340
return filename
332
341
333
342
def tile_nw_lat_lon (self , tile_coord , zoom ):
@@ -354,7 +363,8 @@ def create_osm_image(self, bounds, zoom):
354
363
"""
355
364
(min_lat , max_lat , min_lon , max_lon ) = bounds
356
365
if not self .manager :
357
- raise Exception ("No ImageManager was specified, cannot create image." )
366
+ msg = "No ImageManager was specified, cannot create image."
367
+ raise Exception (msg )
358
368
359
369
topleft = min_x , min_y = self .get_tile_coord (min_lon , max_lat , zoom )
360
370
max_x , max_y = self .get_tile_coord (max_lon , min_lat , zoom )
0 commit comments