methodpool.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # ex:ts=4:sw=4:sts=4:et
  2. # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
  3. #
  4. #
  5. # Copyright (C) 2006 Holger Hans Peter Freyther
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License version 2 as
  9. # published by the Free Software Foundation.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License along
  17. # with this program; if not, write to the Free Software Foundation, Inc.,
  18. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. from bb.utils import better_compile, better_exec
  20. def insert_method(modulename, code, fn, lineno):
  21. """
  22. Add code of a module should be added. The methods
  23. will be simply added, no checking will be done
  24. """
  25. comp = better_compile(code, modulename, fn, lineno=lineno)
  26. better_exec(comp, None, code, fn)
  27. compilecache = {}
  28. def compile_cache(code):
  29. h = hash(code)
  30. if h in compilecache:
  31. return compilecache[h]
  32. return None
  33. def compile_cache_add(code, compileobj):
  34. h = hash(code)
  35. compilecache[h] = compileobj