src/ztfy/utils/protocol/http.py
branchZTK-1.1
changeset 259 0ab973692504
parent 159 6404eb9f238d
child 274 0126d5a339de
equal deleted inserted replaced
258:0e95f369857c 259:0ab973692504
    15 
    15 
    16 
    16 
    17 # import standard packages
    17 # import standard packages
    18 import httplib2
    18 import httplib2
    19 import urllib
    19 import urllib
       
    20 import urlparse
    20 
    21 
    21 # import Zope3 interfaces
    22 # import Zope3 interfaces
    22 
    23 
    23 # import local interfaces
    24 # import local interfaces
    24 
    25 
    68             uri += '?' + urllib.urlencode(self.params)
    69             uri += '?' + urllib.urlencode(self.params)
    69         response, content = http.request(uri, self.method, headers=self.headers)
    70         response, content = http.request(uri, self.method, headers=self.headers)
    70         return response, content
    71         return response, content
    71 
    72 
    72 
    73 
    73 def getClient(method, protocol, servername, url, params={}, credentials=(), proxy=(), rdns=True, proxy_auth=(), timeout=None, headers={}):
    74 def getClient(method, protocol, servername, url, params={}, credentials=(), proxy=(),
       
    75               rdns=True, proxy_auth=(), timeout=None, headers={}):
    74     """HTTP client factory"""
    76     """HTTP client factory"""
    75     return HTTPClient(method, protocol, servername, url, params, credentials, proxy, rdns, proxy_auth, timeout, headers)
    77     return HTTPClient(method, protocol, servername, url, params, credentials, proxy,
       
    78                       rdns, proxy_auth, timeout, headers)
       
    79 
       
    80 
       
    81 def getClientFromURL(url, credentials=(), proxy=(), rdns=True, proxy_auth=(), timeout=None, headers={}):
       
    82     """HTTP client factory from URL"""
       
    83     elements = urlparse.urlparse(url)
       
    84     return HTTPClient('GET', elements.scheme, elements.netloc, elements.path, elements.params,
       
    85                       credentials, proxy, rdns, proxy_auth, timeout, headers)