def start_Bookmark(self, node): date_attr = _fmt_date_attr added = date_attr(node.add_date(), "added") modified = date_attr(node.last_modified(), "modified") visited = date_attr(node.last_visited(), "visited") desc = string.strip(node.description() or '') idref = node.id() or '' if idref: idref = 'id="%s"' % idref title = bookmarks._prepstring(node.title() or '') uri = bookmarks._prepstring(node.uri() or '') attrs = filter(None, (idref, added, modified, visited)) # tab = " " * self._depth if attrs: sep = "\n%s " % tab attrs = " " + string.join(attrs, sep) else: sep = " " attrs = "" self.write('%s<bookmark%s%shref="%s">\n' % (tab, attrs, sep, uri)) if title: self.write("%s <title>%s</title>\n" % (tab, title)) if node.info(): self.__write_info(node.info()) if desc: self.__write_description(desc, tab) self.write(tab + " </bookmark>\n")
def __write_description(self, desc, tab): w = 60 - len(tab) desc = bookmarks._prepstring(desc) if len(desc) > w: desc = _wrap_lines(desc, 70 - len(tab), indentation=len(tab) + 4) desc = "%s\n%s " % (desc, tab) self.write("%s <desc>%s</desc>\n" % (tab, desc))
def start_Folder(self, node): info = node.info() title = node.title() desc = node.description() tab = " " * self._depth attrs = '' added = node.add_date() if added: attrs = '\n added="%s"' % iso8601.ctime(added) if node.id(): if not attrs: attrs = "\n " attrs = '%s id="%s"' % (attrs, node.id()) # if not self._depth: self.write('<xbel%s>\n' % attrs) if title: self.write("%s <title>%s</title>\n" % (tab, bookmarks._prepstring(title))) if info: self.__write_info(info) if desc: self.__write_description(desc, tab) self._depth = 1 self.__close_folders.append(0) return # if node.expanded_p(): attrs = attrs + ' folded="no"' else: attrs = attrs + ' folded="yes"' if title or info or desc or node.children(): self.write(tab + '<folder%s>\n' % attrs) if title: self.write("%s <title>%s</title>\n" % (tab, bookmarks._prepstring(title))) if info: self.__write_info(info) if desc: self.__write_description(desc, tab) self._depth = self._depth + 1 self.__close_folders.append(1) # children are handled through the walker else: self.write(tab + '<folder%s/>\n' % attrs) self.__close_folders.append(0)
def start_Bookmark(self, node): alias = self.__compute_alias_info(node) modified = node.last_modified() or '' if modified: modified = ' LAST_MODIFIED="%d"' % modified add_date = node.add_date() or '' if add_date: add_date = ' ADD_DATE="%d"' % add_date last_visit = node.last_visited() if last_visit: last_visit = ' LAST_VISIT="%d"' % last_visit print '%s<DT><A HREF="%s"%s%s%s%s>%s</A>' % \ (self.__tab(), node.uri(), alias, add_date, last_visit, modified, bookmarks._prepstring(node.title())) self.__write_description(node.description())
def __dump_xml(self, stuff, L, tab): tag, attrs, content = stuff has_text = 0 append = L.append append("<") append(tag) space = " " for attr, value in attrs.items(): append('%s%s="%s"' % (space, attr, bookmarks._prepstring(value))) space = "\n%s%s" % (tab, " "*len(tag)) if not content: append("/>") return has_text = (tab is None) or (attrs.get("xml:space") == "preserve") if not has_text: for citem in content: if type(citem) is type(""): has_text = 1 break if has_text: # some plain text in the data; assume significant: append(">") for citem in content: if type(citem) is type(""): append(bookmarks._prepstring(citem)) else: # element self.__dump_xml(citem, L, None) else: append(">\n") for citem in content: append(tab) self.__dump_xml(citem, L, tab + " ") append("\n") append(tab) append("</%s>" % tag)
def __dump_xml(self, stuff, L, tab): tag, attrs, content = stuff has_text = 0 append = L.append append("<") append(tag) space = " " for attr, value in attrs.items(): append('%s%s="%s"' % (space, attr, bookmarks._prepstring(value))) space = "\n%s%s" % (tab, " " * len(tag)) if not content: append("/>") return has_text = (tab is None) or (attrs.get("xml:space") == "preserve") if not has_text: for citem in content: if type(citem) is type(""): has_text = 1 break if has_text: # some plain text in the data; assume significant: append(">") for citem in content: if type(citem) is type(""): append(bookmarks._prepstring(citem)) else: # element self.__dump_xml(citem, L, None) else: append(">\n") for citem in content: append(tab) self.__dump_xml(citem, L, tab + " ") append("\n") append(tab) append("</%s>" % tag)
def __write_description(self, desc): if not desc: return # write the description, sans leading and trailing whitespace print '<DD>%s' % string.strip(bookmarks._prepstring(desc))