+ if isinstance(href, str):
+ try:
+ href = href.decode('idna')
+ except UnicodeDecodeError: # Non-ascii href
+ href = href.decode('utf-8')
+ elif not isinstance(href, unicode):
+ raise TypeError("Bookmark's href must be str or unicode, not %r" % type(href))