/usr/share/pyshared/twill/extensions/match_parse/__init__.py is in python-twill 0.9-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | """
sureshvv's extension for slicing and dicing variables with regular expressions.
"""
import re
from twill.namespaces import get_twill_glocals
from twill.commands import browser
def showvar(which):
"""
>> showvar var
Shows the value of the variable 'var'.
"""
global_dict, local_dict = get_twill_glocals()
d = global_dict.copy()
d.update(local_dict)
print d.get(str(which))
def split(what):
"""
>> split <regexp>
Sets __matchlist__ to re.split(regexp, page).
"""
page = browser.get_html()
m = re.split(what, page)
global_dict, local_dict = get_twill_glocals()
local_dict['__matchlist__'] = m
def findall(what):
"""
>> findall <regexp>
Sets __matchlist__ to re.findall(regexp, page).
"""
page = browser.get_html()
regexp = re.compile(what, re.DOTALL)
m = regexp.findall(page)
global_dict, local_dict = get_twill_glocals()
local_dict['__matchlist__'] = m
def getmatch(where, what):
"""
>> getmatch into_var expression
Evaluates an expression against __match__ and puts it into 'into_var'.
"""
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 __matchlist__ to eval(expression); 'm' is set
to each element of __matchlist__ prior to processing.
"""
global_dict, local_dict = get_twill_glocals()
match = local_dict['__matchlist__']
if isinstance(match, str): # convert to list
match = [ match, ]
new_match = [ _do_eval(m, what) for m in match ]
local_dict['__matchlist__'] = 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 __matchlist__[i] into __match__.
"""
global_dict, local_dict = get_twill_glocals()
matchlist = local_dict['__matchlist__']
match = matchlist.pop(int(which))
local_dict['__match__'] = match
|