Patches item #1065257, was opened at 2004-11-12 16:48 Message generated for change (Comment added) made by loewis You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1065257&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Modules Group: None >Status: Closed >Resolution: Accepted Priority: 5 Private: No Submitted By: Alessandro Forghieri (alien_life_form) Assigned to: Nobody/Anonymous (nobody) Summary: httplib: allowing stream-type body part in requests Initial Comment: Greetings. The attached patch makes it possible to use a file-like object in httplib requests (useful to PUT large files without exhausting the machine memory - think a DAV server). The supplied object must be able to read(). If Content-Length support is desired, the body object must either have a __length__ method (so len(body) works) OR have a stat-able "name" property (file objects are in the second category). Having applied this patch the following works: import httplib import base64 hh={} auth = base64.encodestring("%s:%s" % ("guest","guest")).rstrip() hh['Authorization']='Basic %s' % auth conn=HTTPConnection('localhost',8080) conn.debuglevel=99 thestream=open(r'\tmp\huge.pdf','rb') conn.request('PUT', '/dav/streamed', thestream,hh) thestream.close() rsp=conn.getresponse() print rsp.status,"-",rsp.reason,repr(rsp.msg.dict),rsp.read() conn.close() Opening in 'rb' mode - on windoze - is important for this to work, or the content length header will be wrong, which is probably BAD. Alessandro Forghieri ---------------------------------------------------------------------- >Comment By: Martin v. Löwis (loewis) Date: 2006-11-12 11:33 Message: Logged In: YES user_id=21627 Thanks for the patch. Committed (with modifications) as r52736. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1065257&group_id=5470 _______________________________________________ Patches mailing list Patches@python.org http://mail.python.org/mailman/listinfo/patches