def render_injected(http_resp, extra_html):
 assert isinstance(http_resp, HttpResponse)
 if ('text/html' not in http_resp.get('content-type', '')):
  return http_resp
 markers = ('</body>', '</BODY>')
 content = http_resp.content
 for marker in markers:
  pos = content.rfind(marker)
  if (pos != (-1)):
   break
 else:
  return http_resp
 if hasattr(extra_html, 'html'):
  extra_html = extra_html.html
 if callable(extra_html):
  extra_html = extra_html()
 http_resp.content = ''.join((content[:pos], extra_html, content[pos:]))
 return http_resp

def render_injected ( http_resp , extra_html ) : assert isinstance ( http_resp , HttpResponse ) if ( 'text/html' not in http_resp . get ( 'content-type' , '' ) ) : return http_resp markers = ( '</body>' , '</BODY>' ) content = http_resp . content for marker in markers : pos = content . rfind ( marker ) if ( pos != ( - 1 ) ) : break else : return http_resp if hasattr ( extra_html , 'html' ) : extra_html = extra_html . html if callable ( extra_html ) : extra_html = extra_html ( ) http_resp . content = '' . join ( ( content [ : pos ] , extra_html , content [ pos : ] ) ) return http_resp
render_injected -> httpresponse inject the extra html into the content of the http_resp .