url builder for python -


I know about urlib and urlparse , but I I want to believe I do not want to modify the wheel again.

My problem is that I am going to bring URLs from the same domain through the urlib library. I want to be able to originally generate URLs (in the form of wire) to use with different paths and query parameters. I expected that some syntax might be:

  url_builder = UrlBuilder ("some.domain.com") # should give me "http://some.domain.com/blah ?  

Actually I want to be able.

Is there something like this Is it possible for people to agree that it is possible? To throw together?

It's still not sure who you are searching for ... but I give it a shot.If you just do one You are looking to create garges that will maintain your default values ​​and in this way, it is very easy to create your own class and use Python magic like str Here is a scratched- Examples (sub-finite):

class UrlBuilder: def __init __ (self, domain, path = "blah", params = "fo o = bar"): self.domain = domain Self.path = path self.params = params def with path (self, path): self.path = Path back with self def: Perth (self, parameter): self. Self def __str __ (self): return 'http: //' + self.domain + '/' + self.path + '?' + Self. Ultimate # or return urlparse.urlunparse (("http", self.domain, self.path, self.params, "", "") Def manufacture (self): return self.__ str __ () if __name__ == ' __main__ ': u = UrlBuilder (' www.example.com ') print u.withPath (' bobloblaw ') print u.withParams (' lawyer = yes ') with print u.withPath (' Elvis '). Params (' Theking = true ')

If you are looking for more of the builder design pattern, then (also).


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -