def encode_mirror_url(raw_url_or_path, remote_domain=None, is_scheme=None, is_escape=False):
 if is_escape:
  _raw_url_or_path = raw_url_or_path.replace('r\\/', '/')
 else:
  _raw_url_or_path = raw_url_or_path
 sp = urlsplit(_raw_url_or_path)
 if ('/extdomains/' == sp.path[:12]):
  return raw_url_or_path
 domain = (remote_domain or sp.netloc or parse.remote_domain or target_domain)
 if (domain not in allowed_domains_set):
  return raw_url_or_path
 if (is_scheme is not False):
  if (_raw_url_or_path[:2] == '//'):
   our_prefix = ('//' + my_host_name)
  elif (is_scheme or sp.scheme):
   our_prefix = myurl_prefix
  else:
   our_prefix = ''
 else:
  our_prefix = ''
 if is_external_domain(domain):
  middle_part = ('/extdomains/' + domain)
 else:
  middle_part = ''
 result = urljoin(((our_prefix + middle_part) + '/'), extract_url_path_and_query(_raw_url_or_path).lstrip('/'))
 if is_escape:
  result = s_esc(result)
 return result

def encode_mirror_url ( raw_url_or_path , remote_domain = None , is_scheme = None , is_escape = False ) : if is_escape : _raw_url_or_path = raw_url_or_path . replace ( 'r\\/' , '/' ) else : _raw_url_or_path = raw_url_or_path sp = urlsplit ( _raw_url_or_path ) if ( '/extdomains/' == sp . path [ : 12 ] ) : return raw_url_or_path domain = ( remote_domain or sp . netloc or parse . remote_domain or target_domain ) if ( domain not in allowed_domains_set ) : return raw_url_or_path if ( is_scheme is not False ) : if ( _raw_url_or_path [ : 2 ] == '//' ) : our_prefix = ( '//' + my_host_name ) elif ( is_scheme or sp . scheme ) : our_prefix = myurl_prefix else : our_prefix = '' else : our_prefix = '' if is_external_domain ( domain ) : middle_part = ( '/extdomains/' + domain ) else : middle_part = '' result = urljoin ( ( ( our_prefix + middle_part ) + '/' ) , extract_url_path_and_query ( _raw_url_or_path ) . lstrip ( '/' ) ) if is_escape : result = s_esc ( result ) return result
convert url from remote to mirror url :type raw_url_or_path: str :type remote_domain: str :type is_scheme: bool :type is_escape: bool :rtype: str .