@contextfunction
def inject_resources(context, content, clean=True):
 rc = get_resource_container(context)
 if (not rc):
  return content
 for (location_name, (regex, placement)) in LOCATION_INFO.items():
  match = regex.search(content)
  if (not match):
   continue
  injection = rc.render_resources(location_name, clean=clean)
  if (not injection):
   continue
  start = match.start()
  end = match.end()
  if (placement == u'pre'):
   content = ((content[:start] + injection) + content[start:])
  elif (placement == u'post'):
   content = ((content[:end] + injection) + content[end:])
  else:
   raise ValueError((u'Unknown placement %s' % placement))
 return content

@ contextfunction def inject_resources ( context , content , clean = True ) : rc = get_resource_container ( context ) if ( not rc ) : return content for ( location_name , ( regex , placement ) ) in LOCATION_INFO . items ( ) : match = regex . search ( content ) if ( not match ) : continue injection = rc . render_resources ( location_name , clean = clean ) if ( not injection ) : continue start = match . start ( ) end = match . end ( ) if ( placement == u'pre' ) : content = ( ( content [ : start ] + injection ) + content [ start : ] ) elif ( placement == u'post' ) : content = ( ( content [ : end ] + injection ) + content [ end : ] ) else : raise ValueError ( ( u'Unknown placement %s' % placement ) ) return content
inject all the resources in the contexts resourcecontainer into appropriate places in the content given .