def __init__(self, url="", method="get"):

        """ Splits an url string into different parts.

        The parts are:
        protocol, domain, login, username, password, port, path, page, query, anchor.

        The method defaults to get when the url has a query part.
        Setting it to post will submit the query by POST
        when opening the url.

        """

        # If the url is a URLParser, copy POST parameters correctly.
        is_post_urlparser = False
        if isinstance(url, URLParser) and url.method == "post":
            is_post_urlparser = True
            url.method = "get"

        # If the url is a URLParser, use its string representation.
        # See that the original object's method is correctly reset.
        urlstr = str(url)
        if is_post_urlparser: url.method = "post"
        url = urlstr

        # Consider the following url:
        # http://user:pass@example.com:992/animal/bird?species=seagull#wings
        # protocol: http
        # domain: example.com
        url = urlparse.urlsplit(url)
        self.protocol = url[0]
        self.domain = url[1]

        # username: user
        # password: pass
        self.username = ""
        self.password = ""
        if self.domain.find("@") >= 0:
            login = self.domain.split("@")[0]
            if login.find(":") >= 0:
                self.username = login.split(":")[0]
                self.password = login.split(":")[1]
            self.domain = self.domain.split("@")[1]

        # port: 992
        self.port = ""
        if self.domain.find(":") >= 0:
            p = self.domain.split(":")
            if p[1].isdigit():
                self.port = p[1]
                self.domain = p[0]

        # path: /animal/
        # page: bird
        self.path = url[2]
        self.page = ""
        if not self.path.endswith("/"):
            if self.path.find("/") >= 0:
                self.page = self.path.split("/")[-1]
                self.path = self.path[:-len(self.page)]
            else:
                self.page = self.path
                self.path = ""
        self.filename = self.page

        # query: {"species": "seagull"}
        self.query = {}
        self.method = method
        if url[3] != "":
            self.method = "get"
        if is_post_urlparser:
            self.method = "post"
        for param in url[3].split("&"):
            key, value = "", ""
            if param.find("=") >= 0:
                try: (key, value) = param.split("=")
                except:
                    key = param
            else:
                key = param
            if key != "":
                self.query[key] = value

        # anchor: wings
        self.anchor = url[4]
def __init__ ( self , url = "" , method = "get" ) : is_post_urlparser = False if isinstance ( url , URLParser ) and url . method == "post" : is_post_urlparser = True url . method = "get" urlstr = str ( url ) if is_post_urlparser : url . method = "post" url = urlstr url = urlparse . urlsplit ( url ) self . protocol = url [ 0 ] self . domain = url [ 1 ] self . username = "" self . password = "" if self . domain . find ( "@" ) >= 0 : login = self . domain . split ( "@" ) [ 0 ] if login . find ( ":" ) >= 0 : self . username = login . split ( ":" ) [ 0 ] self . password = login . split ( ":" ) [ 1 ] self . domain = self . domain . split ( "@" ) [ 1 ] self . port = "" if self . domain . find ( ":" ) >= 0 : p = self . domain . split ( ":" ) if p [ 1 ] . isdigit ( ) : self . port = p [ 1 ] self . domain = p [ 0 ] self . path = url [ 2 ] self . page = "" if not self . path . endswith ( "/" ) : if self . path . find ( "/" ) >= 0 : self . page = self . path . split ( "/" ) [ - 1 ] self . path = self . path [ : - len ( self . page ) ] else : self . page = self . path self . path = "" self . filename = self . page self . query = { } self . method = method if url [ 3 ] != "" : self . method = "get" if is_post_urlparser : self . method = "post" for param in url [ 3 ] . split ( "&" ) : key , value = "" , "" if param . find ( "=" ) >= 0 : try : ( key , value ) = param . split ( "=" ) except : key = param else : key = param if key != "" : self . query [ key ] = value self . anchor = url [ 4 ]
Splits an url string into different parts.

        The parts are:
        protocol, domain, login, username, password, port, path, page, query, anchor.

        The method defaults to get when the url has a query part.
        Setting it to post will submit the query by POST
        when opening the url.