/ svn-cassiopeia --username yuuma.tomita@gmail.com/cas_helper/xldb/utils/parsers/mapp.py
Python | 40 lines | 37 code | 1 blank | 2 comment | 0 complexity | 24382a1be106bc7484021c169b0cf337 MD5 | raw file
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
-
- ur"""test_section
- from xldb.utils.parsers.mapp import mapp
-
- import xldb.utils.parsers.mapp
- reload(xldb.utils.parsers.mapp)
- mapp = xldb.utils.parsers.mapp.mapp
- mapp(u'?', u"[?????]??>???")
- """
-
- import re
- from exceptions import ValueError
- from xldb.sheetutils import get_named_tablib
-
- re_flag = re.I|re.U|re.MULTILINE|re.DOTALL|re.VERBOSE
- parse_pattern_with_type = ur"""
- \[(.+)\](.+)\>([^:]+):?(.+)?
- """; with_type_re = re.compile(parse_pattern_with_type, re_flag)
- #teststr = u"[reg_sheet]header>derive"
- #with_type_re.search(teststr).groups()
-
-
- def mapp(value, eval_string):
- res = None
- reg_sheet, header, derive, force_type = with_type_re.search(eval_string).groups()
- d = get_named_tablib('jwits', 'odekake', reg_sheet)
- try:
- _index = d[header].index(value)
- except ValueError:
- print value, eval_string
- res = value
- if not res:
- res = d[derive][_index]
- if force_type:
- _type = eval(force_type)
- res = _type(res)
- return res
-