def process_static_urls(text, replacement_function, data_dir=None):
 def wrap_part_extraction(match):
  '\n        Unwraps a match group for the captures specified in _url_replace_regex\n        and forward them on as function arguments\n        '
  original = match.group(0)
  prefix = match.group('prefix')
  quote = match.group('quote')
  rest = match.group('rest')
  full_url = (prefix + rest)
  starts_with_static_url = full_url.startswith(unicode(settings.STATIC_URL))
  starts_with_prefix = full_url.startswith(XBLOCK_STATIC_RESOURCE_PREFIX)
  contains_prefix = (XBLOCK_STATIC_RESOURCE_PREFIX in full_url)
  if (starts_with_prefix or (starts_with_static_url and contains_prefix)):
   return original
  return replacement_function(original, prefix, quote, rest)
 return re.sub(_url_replace_regex(u'(?:{static_url}|/static/)(?!{data_dir})'.format(static_url=settings.STATIC_URL, data_dir=data_dir)), wrap_part_extraction, text)

def process_static_urls ( text , replacement_function , data_dir = None ) : def wrap_part_extraction ( match ) : original = match . group ( 0 ) prefix = match . group ( 'prefix' ) quote = match . group ( 'quote' ) rest = match . group ( 'rest' ) full_url = ( prefix + rest ) starts_with_static_url = full_url . startswith ( unicode ( settings . STATIC_URL ) ) starts_with_prefix = full_url . startswith ( XBLOCK_STATIC_RESOURCE_PREFIX ) contains_prefix = ( XBLOCK_STATIC_RESOURCE_PREFIX in full_url ) if ( starts_with_prefix or ( starts_with_static_url and contains_prefix ) ) : return original return replacement_function ( original , prefix , quote , rest ) return re . sub ( _url_replace_regex ( u'(?:{static_url}|/static/)(?!{data_dir})' . format ( static_url = settings . STATIC_URL , data_dir = data_dir ) ) , wrap_part_extraction , text )
run an arbitrary replacement function on any urls matching the static file directory .