User:DrTrigon/DrTrigonBot/subster-postproc.css


 * 1) /* Configuration DrTrigonBot */


 * 1) /* subster: postproc */

wikilinkedlist = lambda DATA, regex: formatedlist(DATA, regex, "* %s")
 * 1) create linked list in wiki format (shortcut and compatibility)
 * 2) syntax: ('wikilinkedlist', regex)

def formatedlist(DATA, regex, format, sep="\n"): comp     = re.compile(regex, re.S | re.I)    data_list = comp.findall(DATA[0]) if comp.groupindex: data_list = [ dict([ (j, item[comp.groupindex[j]-1]) for j in comp.groupindex ]) #+[ (str(j+1), item[j]) for j in range(len(comp.groupindex)) ])                     for item in data_list ]        format    = re.sub(r'\\g\<(.*?)\>', r'%(\g<1>)s', format)    DATA[0] = sep.join(map(lambda x: format % x, data_list))
 * 1) create list in generic format (e.g. for sumcatdisc)
 * 2) syntax: ('formatedlist', regex, format [, sep])

def formatedlist_frommatrix(DATA, regex, format, cols, head, check, types=[]): types    = dict(types) data_list = [] for line in DATA[0].splitlines[head:]: line = re.search(regex, line).groups if not check(line): continue data_list.append( format % tuple([types.get(i, str)(line[i].strip) for i in cols]) ) DATA[0] = "\n".join(data_list)
 * 1) create list in generic format from generic text matrix/table
 * 2) syntax: ('formatedlist_frommatrix', regex, format, cols, head, check [, types])

def _formatedlist_frommatrix(DATA, regex, format, head, check, types=[]): types    = dict(types) data_list = [] for line in DATA[0].splitlines[head:]: comp = re.compile(regex) line = comp.search(line) line = dict([ (k, types.get(k, str)(line.group(k))) for k in comp.groupindex ]) if check(line): data_list.append( format % line ) DATA[0] = "\n".join(data_list)
 * 1) syntax: ('formatedlist_frommatrix', regex, format, head, check [, types])

def replacetext(DATA, regex, sub=u'', flags=re.M): #DATA[0] = re.sub(regex, sub, DATA[0], flags=flags) DATA[0] = re.compile(regex, flags=flags).sub(sub, DATA[0])
 * 1) remove or replace all occurences of regex in text (re.sub wrapper)
 * 2) syntax: ('replacetext', regex [, sub] [, flags])

def reverselist(DATA): lines = DATA[0].splitlines lines.reverse DATA[0] = "\n".join(lines)
 * 1) reverse the list given to change sorting order (list.reverse)
 * 2) syntax: ('reverselist',)

def chain(DATA, postprocs, index=0): for item in postprocs: DATA.append(DATA[0]) eval(item[0])( *((DATA,) + item[1:]) ) DATA[0] = DATA[index]
 * 1) allow to chain multiple postproc functions and combine them
 * 2) syntax: ('chain', postprocs [, index])