<s> from __future__ import absolute_import <EOL> import six <EOL> from six . moves import urllib <EOL> if not six . PY3 : <EOL> import urlparse <EOL> else : <EOL> from urllib import parse as urlparse <EOL> wsschemes = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> urlparse . uses_relative . extend ( wsschemes ) <EOL> urlparse . uses_netloc . extend ( wsschemes ) <EOL> urlparse . uses_params . extend ( wsschemes ) <EOL> urlparse . uses_query . extend ( wsschemes ) <EOL> urlparse . uses_fragment . extend ( wsschemes ) <EOL> __all__ = ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> def create_url ( hostname , port = None , isSecure = False , path = None , params = None ) : <EOL> """<STR_LIT>""" <EOL> if port is not None : <EOL> netloc = "<STR_LIT>" % ( hostname , port ) <EOL> else : <EOL> if isSecure : <EOL> netloc = "<STR_LIT>" % hostname <EOL> else : <EOL> netloc = "<STR_LIT>" % hostname <EOL> if isSecure : <EOL> scheme = "<STR_LIT>" <EOL> else : <EOL> scheme = "<STR_LIT>" <EOL> if path is not None : <EOL> ppath = urllib . parse . quote ( path ) <EOL> else : <EOL> ppath = "<STR_LIT:/>" <EOL> if params is not None : <EOL> query = urllib . parse . urlencode ( params ) <EOL> else : <EOL> query = None <EOL> return urllib . parse . urlunparse ( ( scheme , netloc , ppath , None , query , None ) ) <EOL> def parse_url ( url ) : <EOL> """<STR_LIT>""" <EOL> parsed = urlparse . urlparse ( url ) <EOL> if not parsed . hostname or parsed . hostname == "<STR_LIT>" : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if parsed . scheme not in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> raise Exception ( "<STR_LIT>" % parsed . scheme ) <EOL> if parsed . port is None or parsed . port == "<STR_LIT>" : <EOL> if parsed . scheme == "<STR_LIT>" : <EOL> port = <NUM_LIT> <EOL> else : <EOL> port = <NUM_LIT> <EOL> else : <EOL> port = int ( parsed . port ) <EOL> if parsed . fragment is not None and parsed . fragment != "<STR_LIT>" : <EOL> raise Exception ( "<STR_LIT>" % parsed . fragment ) <EOL> if parsed . path is not None and parsed . path != "<STR_LIT>" : <EOL> ppath = parsed . path <EOL> path = urllib . parse . unquote ( ppath ) <EOL> else : <EOL> ppath = "<STR_LIT:/>" <EOL> path = ppath <EOL> if parsed . query is not None and parsed . query != "<STR_LIT>" : <EOL> resource = ppath + "<STR_LIT:?>" + parsed . query <EOL> params = urlparse . parse_qs ( parsed . query ) <EOL> else : <EOL> resource = ppath <EOL> params = { } <EOL> return parsed . scheme == "<STR_LIT>" , parsed . hostname , port , resource , path , params </s>
