def rewrite_video_url(cdn_base_url, original_video_url):
 if ((not cdn_base_url) or (not original_video_url)):
  return None
 parsed = urlparse(original_video_url)
 rewritten_url = ((cdn_base_url.rstrip('/') + '/') + parsed.path.lstrip('/'))
 validator = URLValidator()
 try:
  validator(rewritten_url)
  return rewritten_url
 except ValidationError:
  log.warn('Invalid CDN rewrite URL encountered, %s', rewritten_url)
 return None

def rewrite_video_url ( cdn_base_url , original_video_url ) : if ( ( not cdn_base_url ) or ( not original_video_url ) ) : return None parsed = urlparse ( original_video_url ) rewritten_url = ( ( cdn_base_url . rstrip ( '/' ) + '/' ) + parsed . path . lstrip ( '/' ) ) validator = URLValidator ( ) try : validator ( rewritten_url ) return rewritten_url except ValidationError : log . warn ( 'Invalid CDN rewrite URL encountered, %s' , rewritten_url ) return None
returns a re-written video url for cases when an alternate source has been configured and is selected using factors like user location .