rules.py 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. # -*- coding: utf-8 -*-
  2. try:
  3. from deliverance.pyref import PyReference
  4. from deliverance import rules
  5. from ajax import PyQuery as pq
  6. except ImportError:
  7. pass
  8. else:
  9. class PyQuery(rules.AbstractAction):
  10. """Python function"""
  11. name = 'py'
  12. def __init__(self, source_location, pyref):
  13. self.source_location = source_location
  14. self.pyref = pyref
  15. def apply(self, content_doc, theme_doc, resource_fetcher, log):
  16. self.pyref(pq([content_doc]), pq([theme_doc]), resource_fetcher, log)
  17. @classmethod
  18. def from_xml(cls, el, source_location):
  19. """Parses and instantiates the class from an element"""
  20. pyref = PyReference.parse_xml(
  21. el, source_location=source_location,
  22. default_function='transform')
  23. return cls(source_location, pyref)
  24. rules._actions['pyquery'] = PyQuery
  25. def deliverance_proxy():
  26. import deliverance.proxycommand
  27. deliverance.proxycommand.main()