From 7229fcc3dfd6d07172c1f81cc49ac894cc2a2c84 Mon Sep 17 00:00:00 2001 From: Jamie Bliss Date: Mon, 23 Feb 2015 21:14:17 +0100 Subject: [PATCH] genPOI: use more pythonic ways ... One should use isinstance instead of `type(A) ==` because of inheritance. There should be an exception if a list of `elif`s don't match. Make Polyline not only accept tuples, but any iterable. --- overviewer_core/aux_files/genPOI.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/overviewer_core/aux_files/genPOI.py b/overviewer_core/aux_files/genPOI.py index 1b15044..4027d03 100755 --- a/overviewer_core/aux_files/genPOI.py +++ b/overviewer_core/aux_files/genPOI.py @@ -299,19 +299,19 @@ def create_marker_from_filter_result(poi, result): # Fill in the rest from result if isinstance(result, basestring): d.update(dict(text=result, hovertext=result)) - elif type(result) == tuple: + elif isinstance(result, tuple): d.update(dict(text=result[1], hovertext=result[0])) # Dict support to allow more flexible things in the future as well as polylines on the map. - elif type(result) == dict: + elif isinstance(result, dict): d['text'] = result['text'] # Use custom hovertext if provided... - if 'hovertext' in result and isinstance(result['hovertext'], basestring): - d['hovertext'] = result['hovertext'] + if 'hovertext' in result: + d['hovertext'] = unicode(result['hovertext']) else: # ...otherwise default to display text. d['hovertext'] = result['text'] - if 'polyline' in result and type(result['polyline']) == tuple: #if type(result.get('polyline', '')) == tuple: + if 'polyline' in result and hasattr(result['polyline'], '__iter__'): d['polyline'] = [] for point in result['polyline']: # This poor man's validation code almost definately needs improving. @@ -324,6 +324,8 @@ def create_marker_from_filter_result(poi, result): d["icon"] = result['icon'] if "createInfoWindow" in result: d["createInfoWindow"] = result['createInfoWindow'] + else: + raise ValueError("got an %s as result for POI with id %s" % (type(result).__name__, poi['id'])) return d