Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _build(self,mo,element_store):
body = mo.group(1).split(self.delimiter,1)
src_mo = self.src_regexp.search(body[0])
if not src_mo:
return bldr.tag.span('Bad Image src')
if sanitizer.is_safe_uri(src_mo.group(1)):
link = src_mo.group(1)
else:
link = "unsafe_uri_detected"
if len(body) == 1:
alias = link
else:
alias = body[1].strip()
return bldr.tag.__getattr__(self.tag)(src=link ,alt=alias)
def emit(self,element_store, environ,link_type,body,url,the_class, alt=None):
if alt is None:
if link_type == 'url':
alt = urlparse.urlsplit(url).path.split('/')[-1]
else:
alt = body.strip()
return bldr.tag.__getattr__(self.tag)(src=url ,alt=alt, title=alt,
#class_=the_class
def emit(self,element_store, environ,link_type,body,url,the_class, alt=None):
if self.disable_external and link_type == 'external':
return bldr.tag.span('External images are disabled', class_='external_image')
if alt is None:
if link_type == 'external':
alt = urlparse.urlsplit(url).path.split('/')[-1]
else:
alt = body.strip()
return bldr.tag.__getattr__(self.tag)(src=url ,alt=alt, title=alt,
#class_=the_class
def _build(self,mo,element_store):
if (not mo.group(1)) and (mo.group(3) in self.linking_protocols):
return bldr.tag.__getattr__(self.tag)(self.alias(mo,element_store),
href=self.href(mo))
else:
return self.href(mo)
def _build(self,mo,element_store, environ):
"""Returns a genshi Element that has ``self.tag`` as the
outermost tag.
This methods if called exclusively by ``_process``
:parameters:
mo
match object, usually the one returned by
self.regexp.search(s)
"""
return bldr.tag.__getattr__(self.tag)(fragmentize(mo.group(1),
self.child_elements,
element_store, environ))
def _build(self,mo,element_store, environ):
"""Returns a genshi Element that has ``self.tag`` as the
outermost tag.
This methods if called exclusively by ``_process``
:parameters:
mo
match object, usually the one returned by
self.regexp.search(s)
"""
return bldr.tag.__getattr__(self.tag)(fragmentize(mo.group(1),
self.child_elements,
element_store, environ))
macro = AttrDict(name=macro_name,arg_string=arg_string,
body=body, isblock=isblock, parsed_body=parsed_body)
try:
value = func(macro,environ,*pos,**kw)
except TypeError , detail:
tag = isblock and 'pre' or 'code'
e = str(detail)
msg = re.sub(r"^\w*\(\) ", '', e)
mo = re.match(r'(.+)(\d+)(.+)(\d+) given\)$',msg)
if mo: #re.search(r'given\)$',msg):
#mo = re.match(r'(.+)(\d+)(.+)(\d+)(.+)$',msg)
msg = mo.group(1) + str(int(mo.group(2))-2) \
+ re.sub('arguments?','argument(s)',mo.group(3)) \
+ str(int(mo.group(4))-2) + ' given)'
value = bldr.tag.__getattr__(tag)("Macro error: '%s' %s"% (macro_name, msg),class_='macro_error')
except MacroError, detail:
tag = isblock and 'pre' or 'code'
value = bldr.tag.__getattr__(tag)("Error in macro '%s': %s"% (macro_name,str(detail.value)),class_='macro_error')
except:
value = bldr.tag.pre('Unexpected error during macro execution!\n'
+ traceback.format_exc(20) ,
class_='macro_error')
return value
def _build(self,mo,element_store, environ):
heading_tag = self.tags[len(mo.group(1))-1]
return bldr.tag.__getattr__(heading_tag)(fragmentize(mo.group(2),
self.child_elements,
element_store, environ))
def _build(self,mo,element_store):
return bldr.tag.__getattr__(self.tag)()