Added "getClientFromURL()" function ZTK-1.1
authorThierry Florac <thierry.florac@onf.fr>
Mon, 15 Sep 2014 12:40:10 +0200
branchZTK-1.1
changeset 259 0ab973692504
parent 258 0e95f369857c
child 260 acc0d940133f
Added "getClientFromURL()" function
src/ztfy/utils/protocol/http.py
--- a/src/ztfy/utils/protocol/http.py	Tue May 20 15:54:43 2014 +0200
+++ b/src/ztfy/utils/protocol/http.py	Mon Sep 15 12:40:10 2014 +0200
@@ -17,6 +17,7 @@
 # import standard packages
 import httplib2
 import urllib
+import urlparse
 
 # import Zope3 interfaces
 
@@ -70,6 +71,15 @@
         return response, content
 
 
-def getClient(method, protocol, servername, url, params={}, credentials=(), proxy=(), rdns=True, proxy_auth=(), timeout=None, headers={}):
+def getClient(method, protocol, servername, url, params={}, credentials=(), proxy=(),
+              rdns=True, proxy_auth=(), timeout=None, headers={}):
     """HTTP client factory"""
-    return HTTPClient(method, protocol, servername, url, params, credentials, proxy, rdns, proxy_auth, timeout, headers)
+    return HTTPClient(method, protocol, servername, url, params, credentials, proxy,
+                      rdns, proxy_auth, timeout, headers)
+
+
+def getClientFromURL(url, credentials=(), proxy=(), rdns=True, proxy_auth=(), timeout=None, headers={}):
+    """HTTP client factory from URL"""
+    elements = urlparse.urlparse(url)
+    return HTTPClient('GET', elements.scheme, elements.netloc, elements.path, elements.params,
+                      credentials, proxy, rdns, proxy_auth, timeout, headers)