Changeset 1dcaff4 for fedd/federation/util.py
- Timestamp:
- Mar 18, 2010 8:35:10 AM (14 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
- Children:
- 114d24b
- Parents:
- 3159f5d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/federation/util.py
r3159f5d r1dcaff4 5 5 import logging 6 6 7 import httplib 8 7 9 from M2Crypto import SSL 10 from M2Crypto.SSL import SSLError 8 11 from fedid import fedid 12 from service_error import service_error 13 from urlparse import urlparse 9 14 10 15 … … 169 174 d.close() 170 175 176 def get_url(url, cf, destdir, fn=None, max_retries=5): 177 """ 178 Get data from a federated data store. This presents the client cert/fedid 179 to the http server. We retry up to max_retries times. 180 """ 181 po = urlparse(url) 182 if not fn: 183 fn = po.path.rpartition('/')[2] 184 retries = 0 185 ok = False 186 failed_exception = None 187 while not ok and retries < 5: 188 try: 189 conn = httplib.HTTPSConnection(po.hostname, port=po.port, 190 cert_file=cf, key_file=cf) 191 conn.putrequest('GET', po.path) 192 conn.endheaders() 193 response = conn.getresponse() 194 195 lf = open("%s/%s" % (destdir, fn), "w") 196 buf = response.read(4096) 197 while buf: 198 lf.write(buf) 199 buf = response.read(4096) 200 lf.close() 201 ok = True 202 except IOError, e: 203 failed_excpetion = e 204 retries += 1 205 except httplib.HTTPException, e: 206 failed_exception = e 207 retries += 1 208 except SSLError, e: 209 failed_exception = e 210 retries += 1 211 212 if retries > 5 and failed_exception: 213 raise failed_excpetion 214
Note: See TracChangeset
for help on using the changeset viewer.