PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/ svn-cassiopeia --username yuuma.tomita@gmail.com/cas_helper/xldb/utils/parsers/mapp.py

http://svn-cassiopeia.googlecode.com/
Python | 40 lines | 37 code | 1 blank | 2 comment | 0 complexity | 24382a1be106bc7484021c169b0cf337 MD5 | raw file
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ur"""test_section
  4. from xldb.utils.parsers.mapp import mapp
  5. import xldb.utils.parsers.mapp
  6. reload(xldb.utils.parsers.mapp)
  7. mapp = xldb.utils.parsers.mapp.mapp
  8. mapp(u'?', u"[?????]??>???")
  9. """
  10. import re
  11. from exceptions import ValueError
  12. from xldb.sheetutils import get_named_tablib
  13. re_flag = re.I|re.U|re.MULTILINE|re.DOTALL|re.VERBOSE
  14. parse_pattern_with_type = ur"""
  15. \[(.+)\](.+)\>([^:]+):?(.+)?
  16. """; with_type_re = re.compile(parse_pattern_with_type, re_flag)
  17. #teststr = u"[reg_sheet]header>derive"
  18. #with_type_re.search(teststr).groups()
  19. def mapp(value, eval_string):
  20. res = None
  21. reg_sheet, header, derive, force_type = with_type_re.search(eval_string).groups()
  22. d = get_named_tablib('jwits', 'odekake', reg_sheet)
  23. try:
  24. _index = d[header].index(value)
  25. except ValueError:
  26. print value, eval_string
  27. res = value
  28. if not res:
  29. res = d[derive][_index]
  30. if force_type:
  31. _type = eval(force_type)
  32. res = _type(res)
  33. return res