Classes | |
class | psv |
class | Ret |
Functions | |
def | ccsv_parse |
Variables | |
tuple | spec = open( os.path.expandvars( "$DYBDBIROOT/spec/GSimPmtSpec.spec" ), "r") |
tuple | p = ccsv_parse( spec ) |
def DybDbiPre::ccsv::ccsv_parse | ( | ccsv, | ||
dialect = psv | ||||
) |
Parse compound-csv strings into a list of dicts (one for each csv line) Compound-csv format comprises standard csv (with 1 line fieldname header) separated by lines containing only ";" * whitespace at front and back of keys and values is stripped * lines starting with # are regarded as ignored TODO : improve robustness ... * trailing spaces after the ";" cause parse errors, as those spaces are taken to be the fieldspec yielding:: AttributeError: 'NoneType' object has no attribute 'strip'
Definition at line 12 of file ccsv.py.
00012 : 00013 """ 00014 Parse compound-csv strings into a list of dicts (one for each csv line) 00015 00016 Compound-csv format comprises standard csv (with 1 line fieldname header) 00017 separated by lines containing only ";" 00018 00019 * whitespace at front and back of keys and values is stripped 00020 * lines starting with # are regarded as ignored 00021 00022 TODO : improve robustness ... 00023 00024 * trailing spaces after the ";" cause parse errors, as those 00025 spaces are taken to be the fieldspec yielding:: 00026 00027 AttributeError: 'NoneType' object has no attribute 'strip' 00028 00029 """ 00030 docp = re.compile('"""([^"""]*)"""',re.DOTALL) 00031 docstrings = lambda t:docp.findall(t) 00032 undoc = lambda t:docp.sub("", t) 00033 00034 uncomment = lambda lines:re.compile("^#.*$\n",re.MULTILINE).sub("",lines) 00035 unblank_line = lambda line:len(line)>0 00036 unblank_segm = lambda segm:"\n".join( filter(unblank_line, segm.split("\n") )) 00037 stripr = lambda s:map(strip,s) 00038 00039 docs = "".join( docstrings( ccsv ) ) 00040 bits = uncomment( undoc(ccsv) ).split(";") 00041 regs = filter( unblank_line , bits ) 00042 segs = map( unblank_segm, regs ) 00043 00044 ret = Ret() 00045 for segm in segs: 00046 rdr = csv.DictReader( StringIO(segm) , dialect = dialect ) 00047 for r in rdr: 00048 d = dict( map(stripr, r.items()) ) 00049 ret.append( d ) 00050 ret.docs = docs 00051 return ret 00052 00053 00054 if __name__ == '__main__':
tuple DybDbiPre::ccsv::spec = open( os.path.expandvars( "$DYBDBIROOT/spec/GSimPmtSpec.spec" ), "r") [static] |
tuple DybDbiPre::ccsv::p = ccsv_parse( spec ) [static] |