Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install commentator

How to install commentator

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install commentator
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.1 Available View build log
Windows (64-bit)
0.1 Available View build log
Mac OS X (10.5+)
0.1 Available View build log
Linux (32-bit)
0.1 Available View build log
Linux (64-bit)
0.1 Available View build log
 
Author
License
GPL
Dependencies
Imports
Lastest release
version 0.1 on Jan 5th, 2011

WSGI commenting middleware

To use

Make a factory wrapping your app in the commentator middleware. Currently, commentator only pickles comments. To the constructor of Commentator, pass a database (the path to the pickle) and a pattern. The pattern is in the form of

<URL pattern>#<xpath pattern> -> URL

The URL pattern is a python regular expression to match against the request's PATH_INFO.

The xpath pattern is where you want to place the comments on the page. See http://www.w3schools.com/XPath/ for more about xpath expressions.

The URL is a python string template that is substituted for groups in the URL regular expression and element attributes in the found nodes. The element attributes are referenced by name (${id}, ${class}, etc) and the groups are referenced by number (${1}, ...).

Example

A reference implementation is illustrated in the commentator.ini file. This uses the pattern:

commentator.pattern = (.*)#.//div[@id='comment_on_this'] -> ${1}

What this pattern says is

  • comment on every PATH_INFO (.*)
  • append the rendered content template to div[@id='comment_on_this']
  • reference the PATH_INFO as the canonical URL ${1}

To comment on every HTML page at the end of the body, you would use

commentator.pattern = (.*)#.//body -> ${1}

A more complex example is in the .ini file, commented out, for use with bitsyblog :

commentator.pattern = /blog/.*#.//div[@class='blog-entry'] -> /blog/${id}

This pattern says:

  • comment on all paths under blog
  • put the comments at the end of each div[@class='blog-entry']
  • get the URI from the div's id, not from the PATH_INFO

TODO

This is very alpha. I'd be happy to work more on this if anyone wants it. A few outstanding issues:

  • fix weird lxml issue where you have to put .// for elements
  • allow commenting on multiple resources (multiple patterns per instance)
  • locking pickle files
  • fix couch....not sure what's wrong
  • allow use of CSS classes, not just xpath

--

http://k0s.org

Subscribe to package updates

Last updated Jan 5th, 2011

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.