def as_url(scheme, host=None, port=None, user=None, password=None, path=None, query=None, sanitize=False, mask=u'**'):
 parts = [u'{0}://'.format(scheme)]
 if (user or password):
  if user:
   parts.append(safequote(user))
  if password:
   if sanitize:
    parts.extend(([u':', mask] if mask else [u':']))
   else:
    parts.extend([u':', safequote(password)])
  parts.append(u'@')
 parts.append((safequote(host) if host else u''))
 if port:
  parts.extend([u':', port])
 parts.extend([u'/', path])
 return u''.join((str(part) for part in parts if part))

def as_url ( scheme , host = None , port = None , user = None , password = None , path = None , query = None , sanitize = False , mask = u'**' ) : parts = [ u'{0}://' . format ( scheme ) ] if ( user or password ) : if user : parts . append ( safequote ( user ) ) if password : if sanitize : parts . extend ( ( [ u':' , mask ] if mask else [ u':' ] ) ) else : parts . extend ( [ u':' , safequote ( password ) ] ) parts . append ( u'@' ) parts . append ( ( safequote ( host ) if host else u'' ) ) if port : parts . extend ( [ u':' , port ] ) parts . extend ( [ u'/' , path ] ) return u'' . join ( ( str ( part ) for part in parts if part ) )
generate url from component parts .