[twill] Hacked some new commands

sureshvv suresh_vv at yahoo.com
Tue Nov 29 00:24:01 PST 2005


Helps me slice and dice the response.
--------------------------------------------------------------------------------------
def showvar(which):
     """
     >> showvar var

     Shows the variable
     """
     global_dict, local_dict = get_twill_glocals()
     print local_dict[str(which)]

def split(what):
     """
     >> split <regexp>

     Sets __match__ to re.split(what)
     """
     page = browser.get_html()

     m = re.split(what, page)

     global_dict, local_dict = get_twill_glocals()
     local_dict['__match__'] = m

def findall(what):
     """
     >> findall <regexp>

     Sets __match__ to re.findall(what)
     """
     page = browser.get_html()

     m = re.findall(what, page, re.DOTALL)

     global_dict, local_dict = get_twill_glocals()
     local_dict['__match__'] = m

def getmatch(where, what):
     """
     >> getmatch expression

     Evaluates an expression against __match__ and returns it
     """
     global_dict, local_dict = get_twill_glocals()
     match = local_dict['__match__']
     local_dict[where] = _do_eval(match, what)

def setmatch(what):
     """
     >> setmatch expression

     Sets each element __match__ to expression evaluated
     """
     global_dict, local_dict = get_twill_glocals()
     match = local_dict['__match__']
     new_match = [ _do_eval(m1, what) for m1 in match ]
     local_dict['__match__'] = new_match

def _do_eval(match, exp):
     """
     Used internally to evaluate an expresseion
     """
     return eval(exp, globals(), {'m': match})

def popmatch(which):
     """
     >> popmatch index

     Pops element at location
     """
     global_dict, local_dict = get_twill_glocals()
     match = local_dict['__match__']
     match.pop(int(which))
     local_dict['__match__'] = match
--------------------------------------------------------------------------------------









More information about the twill mailing list