Acrylamid Library

Asynchronous Tasks

A simple thread pool implementation, that can be used for parallel I/O.

Example usage:

>>> def takes(long=10):
...     sleep(long)
>>> pool = Threadpool(5)
>>> for x in range(10):
...     pool.add_task(takes, x)
>>> pool.wait_completion()

You can’t retrieve the return values, just wait until they finish.

class acrylamid.lib.async.Threadpool(num_threads, wait=True)

Initialize pool with number of workers, that run a function with given arguments and catch all exceptions.

add_task(func, *args, **kargs)

Add a task to the queue


Wait for completion of all the tasks in the queue

Generic HTML tools

A collection of tools that ease reading and writing HTML. Currently, there’s only a improved version of python’s HTMLParser.HTMLParser, that returns the HTML untouched, so you can override specific calls to add custom behavior.

This implementation is used acrylamid.filters.acronyms, acrylamid.filters.hyphenation and more advanced in acrylamid.filters.summarize. It is quite fast, but remains an unintuitive way of working with HTML.

class acrylamid.lib.html.HTMLParser(html)

A more useful base HTMLParser that returns the actual HTML by default:

>>> "<b>Foo</b>" == HTMLParser("<b>Foo</b>").result

It is intended to use this class as base so you don’t make the same mistakes I did before.


This is the processed HTML.


An escaped umlaut like "&auml;"


Preserve HTML comments.


Everything that is not a tag shows up as data, but you can’t expect that it is always a continous sentence or word.


Append ending tag to result and pop it from the stack too.


An escaped ampersand like "&#38;".

handle_startendtag(tag, attrs)

Something like "<br />"

handle_starttag(tag, attrs)

Append tag to stack and write it to result.

class acrylamid.lib.html.HTMLParseError

Internal Webserver

Launch a dumb webserver as thread.

class acrylamid.lib.httpd.Webserver(port=8000, root='.', log_message=<function <lambda> at 0x106de7500>)

A single-threaded webserver to serve while generation.

  • port – port to listen on
  • root – serve this directory under /

“Sets kill_recieved and closes the server socket.

Lazy Import

Two switches that enable/disable automatic demandloading of modules. Imports of the following forms will be demand-loaded:

import a, b.c
import a.b as c
from a import b,c # a will be loaded immediately

These imports will not be delayed:

from a import *
b = __import__(a)

This is dark magic, currently only used for lazy import in filters as there have been mysterious exceptions in the jinja2 templating engine when enabled for views as well.


Enable global demand-loading of modules.


Disable global demand-loading of modules.


A simple wrapper around urllib2.

acrylamid.lib.requests.head(url, **hdrs)

Sends a HEAD request to given url but does not catch any exception.

  • url – url to send the request to
  • hdrs – a key-value pair that is send within the HTTP header
acrylamid.lib.requests.get(url, **hdrs)

Same like head() but for GET.

class acrylamid.lib.requests.HTTPError
class acrylamid.lib.requests.URLError

Table Of Contents

Related Topics

This Page