|
22 | 22 | from folium import utilities |
23 | 23 | from folium.six import text_type, binary_type, iteritems |
24 | 24 |
|
| 25 | +import sys |
| 26 | + |
25 | 27 |
|
26 | 28 | ENV = Environment(loader=PackageLoader('folium', 'templates')) |
27 | 29 |
|
@@ -616,10 +618,21 @@ def _popup_render(self, popup=None, mk_name=None, count=None, |
616 | 618 | if not popup_on: |
617 | 619 | return 'var no_pop = null;' |
618 | 620 | else: |
619 | | - if isinstance(popup, str): |
| 621 | + if sys.version_info >= (3,0): |
| 622 | + utype, stype = str, bytes |
| 623 | + else: |
| 624 | + utype, stype = unicode, str |
| 625 | + |
| 626 | + if isinstance(popup, (utype, stype)): |
620 | 627 | popup_temp = self.env.get_template('simple_popup.js') |
| 628 | + if isinstance(popup, utype): |
| 629 | + popup_txt = popup.encode('ascii', 'xmlcharrefreplace') |
| 630 | + else: |
| 631 | + popup_txt = popup |
| 632 | + if sys.version_info >= (3,0): |
| 633 | + popup_txt = popup_txt.decode() |
621 | 634 | return popup_temp.render({'pop_name': mk_name + str(count), |
622 | | - 'pop_txt': json.dumps(popup), |
| 635 | + 'pop_txt': json.dumps(str(popup_txt)), |
623 | 636 | 'width': width}) |
624 | 637 | elif isinstance(popup, tuple): |
625 | 638 | #Update template with JS libs |
@@ -653,6 +666,8 @@ def _popup_render(self, popup=None, mk_name=None, count=None, |
653 | 666 | 'max_width': max_width, |
654 | 667 | 'json_out': json_out, |
655 | 668 | 'vega_id': vega_id}) |
| 669 | + else: |
| 670 | + raise TypeError("Unrecognized popup type: {!r}".format(popup)) |
656 | 671 |
|
657 | 672 | @iter_obj('geojson') |
658 | 673 | def geo_json(self, geo_path=None, geo_str=None, data_out='data.json', |
|
0 commit comments