__all__ = ['writer_html']
+from m_lib.defenc import default_encoding
from bkmk_objects import Writer, BKMK_FORMAT, quote_title
self.outfile.write(ind_s*level + "</DL><p>\n")
def bookmark(self, b, level):
- self.outfile.write(ind_s*(level+1) + '<DT><A HREF="%s" ADD_DATE="%s"' % (b.href, b.add_date))
+ self.outfile.write(ind_s*(level+1) + '<DT><A HREF="%s" ADD_DATE="%s"' % (b.href.encode(default_encoding), b.add_date))
if b.last_visit: self.outfile.write('LAST_VISIT="%s"' % b.last_visit)
self.outfile.write('LAST_MODIFIED="%s"' % b.last_modified)
if BKMK_FORMAT == "MOZILLA":
]
-import os, cgi
-from m_lib.defenc import default_encoding as DEFAULT_CHARSET
+import os
BKMK_FORMAT = os.environ.get("BKMK_FORMAT", "MOZILLA")
def __init__(self, href, add_date, last_visit=None, last_modified=None,
keyword=None, comment='', icon_href=None, icon=None, charset=None):
+ 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))
self.href = href
self.add_date = add_date
self.last_visit = last_visit
__all__ = ['BkmkParser']
-import sys, os
+import os
+from m_lib.defenc import default_encoding
from m_lib.net.www.html import HTMLParser
-from bkmk_objects import DEFAULT_CHARSET, Folder, Bookmark, Ruler
+from bkmk_objects import Folder, Bookmark, Ruler
DEBUG = os.environ.has_key("BKMK_DEBUG")
def handle_data(self, data):
if data:
- if self.charset and DEFAULT_CHARSET:
- data = unicode(data, self.charset, "replace").encode(DEFAULT_CHARSET, "xmlcharrefreplace")
+ if self.charset and default_encoding:
+ data = unicode(data, self.charset, "replace").encode(default_encoding, "xmlcharrefreplace")
self.accumulator += data
# Mozilla - get charset
pass
def start_title(self, attrs):
- if DEFAULT_CHARSET:
- self.accumulator += '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=%s">\n' % DEFAULT_CHARSET
+ if default_encoding:
+ self.accumulator += '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=%s">\n' % default_encoding
self.accumulator += "<TITLE>"
def end_title(self):
add_date = None
last_visit = None
last_modified = None
- keyword = None
+ keyword = ''
icon = None
charset = None
debug("Bookmark points to: `%s'" % href)
bookmark = Bookmark(href, add_date, last_visit, last_modified,
- keyword=keyword or '', icon=icon, charset=charset)
+ keyword=keyword, icon=icon, charset=charset)
self.current_object = bookmark
self.current_folder.append(bookmark)
self.urls += 1