The Bookmarks Plugin

Todo

Write documentation on bookmarks.js.

bookmarks.py - A plugin for Gate One that adds fancy bookmarking capabilities.

Hooks

This Python plugin file implements the following hooks:

hooks = {
    'Web': [
        (r"/bookmarks/fetchicon", FaviconHandler),
        (r"/bookmarks/export", ExportHandler),
        (r"/bookmarks/import", ImportHandler),
    ],
    'WebSocket': {
        'bookmarks_sync': save_bookmarks,
        'bookmarks_get': get_bookmarks,
        'bookmarks_deleted': delete_bookmarks,
        'bookmarks_rename_tags': rename_tags,
    }
}

Docstrings

bookmarks.unescape(s)[source]

Unescape HTML code refs; c.f. http://wiki.python.org/moin/EscapingHtml

bookmarks.parse_bookmarks_html(html)[source]

Reads the Netscape-style bookmarks.html in string, html and returns a list of Bookmark objects.

bookmarks.get_json_tags(json_dict, url)[source]

Recursively looks inside json_dict trying to find tags associated with the given url. Returns the tags found as a list.

bookmarks.get_ns_json_bookmarks(json_dict, bookmarks)[source]

Given a json_dict, updates urls_list with each URL as it is found within.

Note

Only works with Netscape-style bookmarks.json files.

bookmarks.parse_bookmarks_json(json_str)[source]

Given json_str, returns a list of bookmark objects representing the data contained therein.

class bookmarks.BookmarksDB(user_dir, user)[source]

Used to read and write bookmarks to a file on disk. Can also synchronize a given list of bookmarks with what's on disk. Uses a given bookmark's updateSequenceNum to track what wins the "who is newer?" comparison.

Sets up our bookmarks database object and reads everything in.

open_bookmarks()[source]

Opens the bookmarks stored in self.user_dir. If not present, an empty file will be created.

save_bookmarks()[source]

Saves self.bookmarks to self.bookmarks_path as a JSON-encoded list.

sync_bookmarks(bookmarks)[source]

Given bookmarks, synchronize with self.bookmarks doing conflict resolution and whatnot.

delete_bookmark(bookmark)[source]

Deletes the given bookmark.

get_bookmarks(updateSequenceNum=0)[source]

Returns a list of bookmarks newer than updateSequenceNum. If updateSequenceNum is 0 or undefined, all bookmarks will be returned.

get_highest_USN()[source]

Returns the highest updateSequenceNum in self.bookmarks

rename_tag(old_tag, new_tag)[source]

Goes through all bookmarks and renames all tags named old_tag to be new_tag.

class bookmarks.FaviconHandler(application, request, **kwargs)[source]

Retrives the biggest favicon-like icon at the given URL. It will try to fetch apple-touch-icons (which can be nice and big) before it falls back to grabbing the favicon.

Note

Works with GET and POST requests but POST is preferred since it keeps the URL from winding up in the server logs.

get_favicon_url(html)[source]

Parses html looking for a favicon URL. Returns a tuple of:

(<url>, <mimetime>)

If no favicon can be found, returns:

(None, None)
icon_multifetch(urls, response)[source]

Fetches the icon at the given URLs, stopping when it finds the biggest. If an icon is not found, calls itself again with the next icon URL. If the icon is found, writes it to the client and finishes the request.

icon_fetch(url, mimetype, response)[source]

Returns the fetched icon to the client.

class bookmarks.ImportHandler(application, request, **kwargs)[source]

Takes a bookmarks.html in a POST and returns a list of bookmarks in JSON format

class bookmarks.ExportHandler(application, request, **kwargs)[source]

Takes a JSON-encoded list of bookmarks and returns a Netscape-style HTML file.

bookmarks.save_bookmarks(bookmarks, tws)[source]

Handles saving bookmarks for clients.

bookmarks.get_bookmarks(updateSequenceNum, tws)[source]

Returns a JSON-encoded list of bookmarks updated since the last updateSequenceNum.

If updateSequenceNum resolves to False, all bookmarks will be sent to the client.

bookmarks.delete_bookmarks(deleted_bookmarks, tws)[source]

Handles deleting bookmars given a deleted_bookmarks list.

bookmarks.rename_tags(renamed_tags, tws)[source]

Handles renaming tags.

Table Of Contents

Previous topic

go_process.js

Next topic

The Help Plugin

This Page