# HG changeset patch # User Jeff Hammel # Date 1285556326 25200 # Node ID 7800c6553c77890820150741ec88f670ee2bf25c # Parent 0ad456dbb4c5d83527d8a9bfac7702adc693589d# Parent 6cbe4172b54b25a45d3e9ba3882073bd57668d69 merge commit diff -r 0ad456dbb4c5 -r 7800c6553c77 contenttransformer/transformers.py --- a/contenttransformer/transformers.py Sun Sep 26 16:03:33 2010 -0700 +++ b/contenttransformer/transformers.py Sun Sep 26 19:58:46 2010 -0700 @@ -1,5 +1,6 @@ import docutils.core import subprocess +from utils import import_path from webob import Request, Response class Transformer(object): @@ -65,7 +66,15 @@ class GenshiTransformer(Transformer): - def __init__(self, content, content_type): + def __init__(self, content, content_type, modules=()): + """ + - modules : strings of modules + """ + self.variables = {} + for path in modules: + module = import_path(path) + name = path.rsplit('.')[-1] + self.variables[name] = module Transformer.__init__(self, content, content_type) def transform(self, request): diff -r 0ad456dbb4c5 -r 7800c6553c77 contenttransformer/utils.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contenttransformer/utils.py Sun Sep 26 19:58:46 2010 -0700 @@ -0,0 +1,13 @@ +#!/usr/bin/env python + +def import_path(module): + path = module.split('.') + module = __import__(path[0]) + for name in path[1:]: + module = getattr(module, name) + return module + +if __name__ == '__main__': + import sys + for i in sys.argv[1:]: + print import_path(i)