Changeset 49592
- Timestamp:
- 10/16/06 11:38:45 (2 years ago)
- Files:
-
- funkload/trunk/funkload/PatchWebunit.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
funkload/trunk/funkload/PatchWebunit.py
r49367 r49592 42 42 from utils import thread_sleep 43 43 44 boundary= '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'45 sep_boundary = '\r\n--' + boundary 46 end_boundary = sep_boundary+ '--'47 def mimeEncode(data, sep_boundary= sep_boundary, end_boundary=end_boundary):44 BOUNDARY = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254' 45 SEP_BOUNDARY = '\r\n--' + BOUNDARY 46 END_BOUNDARY = SEP_BOUNDARY + '--' 47 def mimeEncode(data, sep_boundary=SEP_BOUNDARY, end_boundary=END_BOUNDARY): 48 48 '''Take the mapping of data and construct the body of a 49 49 multipart/form-data message with it using the indicated boundaries. … … 54 54 continue 55 55 # handle multiple entries for the same name 56 if type(value) != type([]): value = [value] 56 if type(value) != type([]): 57 value = [value] 57 58 for value in value: 58 59 ret.write(sep_boundary) … … 82 83 83 84 def do_img(self, attributes): 85 """Process img tag.""" 84 86 newattributes = [] 85 87 for name, value in attributes: … … 108 110 109 111 def do_link(self, attributes): 112 """Process link tag.""" 110 113 newattributes = [('rel', 'stylesheet'), ('type', 'text/css')] 111 114 for name, value in attributes: … … 191 194 192 195 # TODO: allow override of the server and port from the URL! 193 if server is None: server = self.server 194 if port is None: port = self.port 195 if protocol is None: protocol = self.protocol 196 if ok_codes is None: ok_codes = self.expect_codes 196 if server is None: 197 server = self.server 198 if port is None: 199 port = self.port 200 if protocol is None: 201 protocol = self.protocol 202 if ok_codes is None: 203 ok_codes = self.expect_codes 197 204 198 205 if protocol == 'http': 199 h = httplib.HTTP(server, int(port)) 206 webproxy = {} 207 try: 208 proxystring = os.environ["http_proxy"].replace("http://", "") 209 webproxy['host'] = proxystring.split(":")[0] 210 webproxy['port'] = int(proxystring.split(":")[1]) 211 except (KeyError, IndexError, ValueError): 212 webproxy = False 213 214 if webproxy: 215 h = httplib.HTTPConnection(webproxy['host'], webproxy['port']) 216 else: 217 h = httplib.HTTP(server, int(port)) 200 218 if int(port) == 80: 201 219 host_header = server … … 225 243 h.putrequest('POST', url) 226 244 h.putheader('Content-type', 'multipart/form-data; boundary=%s'% 227 boundary)245 BOUNDARY) 228 246 h.putheader('Content-length', str(len(params))) 229 247 else: 230 # Normal GET 231 h.putrequest('GET', url) 248 if webproxy: 249 h.putrequest('GET', "http://%s%s" % (server, url)) 250 else: 251 # Normal GET 252 h.putrequest('GET', url) 232 253 233 254 # Other Full Request headers … … 282 303 283 304 # handle the reply 284 errcode, errmsg, headers = h.getreply() 285 286 # get the body and save it 287 f = h.getfile() 288 g = cStringIO.StringIO() 289 d = f.read() 290 while d: 291 g.write(d) 305 if webproxy: 306 r = h.getresponse() 307 errcode = r.status 308 errmsg = r.reason 309 headers = r.msg 310 data = r.read() 311 response = HTTPResponse(self.cookies, protocol, server, port, url, 312 errcode, errmsg, headers, data, 313 self.error_content) 314 315 else: 316 # get the body and save it 317 errcode, errmsg, headers = h.getreply() 318 f = h.getfile() 319 g = cStringIO.StringIO() 292 320 d = f.read() 293 response = HTTPResponse(self.cookies, protocol, server, port, url, 294 errcode, errmsg, headers, g.getvalue(), self.error_content) 295 f.close() 321 while d: 322 g.write(d) 323 d = f.read() 324 response = HTTPResponse(self.cookies, protocol, server, port, url, 325 errcode, errmsg, headers, g.getvalue(), 326 self.error_content) 327 f.close() 296 328 297 329 if errcode not in ok_codes:
