"""Fixed child-side bridge injected into a sandboxed generated business page.""" import re BRIDGE='''''' def inject(page): result,count=re.subn(r']*>',lambda match:match.group(0)+BRIDGE,page,count=1,flags=re.I) if count!=1:raise ValueError('BUSINESS_PAGE_INVALID') # Restore the trusted bridge after generated scripts; a model may accidentally # declare a global function with the same name. Onload handlers run afterward. restore='' result,count=re.subn(r'',lambda match:restore+match.group(0),result,count=1,flags=re.I) if not count:result=re.sub(r'',lambda match:restore+match.group(0),result,count=1,flags=re.I) return result