Python 1.6a2 -- patch for urllib https POST support
Paul Schreiber
shrub at yahoo.com
Mon May 22 21:23:29 EDT 2000
I was futzing with urllib and noticed it supported POST and GET for http but only
GET for https. So I added support. :-)
This worked for me, but I haven't tested it thoroughly.
Here's a context diff...
Paul
*** /usr/local/lib/python1.6/urllib.py Mon May 22 15:46:39 2000
--- /home/shrub/urllib.py Mon May 22 18:14:25 2000
***************
*** 299,305 ****
raise IOError, ('http error', errcode, errmsg, headers)
if hasattr(socket, "ssl"):
! def open_https(self, url):
"""Use HTTPS protocol."""
import httplib
if type(url) is type(""):
--- 299,305 ----
raise IOError, ('http error', errcode, errmsg, headers)
if hasattr(socket, "ssl"):
! def open_https(self, url, data=None):
"""Use HTTPS protocol."""
import httplib
if type(url) is type(""):
***************
*** 323,338 ****
h = httplib.HTTPS(host, 0,
key_file=self.key_file,
cert_file=self.cert_file)
! h.putrequest('GET', selector)
if auth: h.putheader('Authorization: Basic %s' % auth)
for args in self.addheaders: apply(h.putheader, args)
h.endheaders()
errcode, errmsg, headers = h.getreply()
fp = h.getfile()
if errcode == 200:
return addinfourl(fp, headers, url)
else:
! return self.http_error(url, fp, errcode, errmsg, headers)
def open_gopher(self, url):
"""Use Gopher protocol."""
--- 323,349 ----
h = httplib.HTTPS(host, 0,
key_file=self.key_file,
cert_file=self.cert_file)
! if data is not None:
! h.putrequest('POST', selector)
! h.putheader('Content-type', 'application/x-www-form-urlencoded')
! h.putheader('Content-length', '%d' % len(data))
! else:
! h.putrequest('GET', selector)
!
if auth: h.putheader('Authorization: Basic %s' % auth)
for args in self.addheaders: apply(h.putheader, args)
h.endheaders()
+ if data is not None:
+ h.send(data + '\r\n')
errcode, errmsg, headers = h.getreply()
fp = h.getfile()
if errcode == 200:
return addinfourl(fp, headers, url)
else:
! if data is None:
! return self.http_error(url, fp, errcode, errmsg, headers)
! else:
! return self.http_error(url, fp, errcode, errmsg, headers,
data)
def open_gopher(self, url):
"""Use Gopher protocol."""
=====
shad 96c / 4A CS / mac activist / eda / fumbler
fan of / jewel / sophie b. / sarah slean / steve poltz / emm gryner /
/ x-files / buffy / dawson's creek / habs / bills / 49ers /
t h i n k d i f f e r e n t.
__________________________________________________
Do You Yahoo!?
Send instant messages & get email alerts with Yahoo! Messenger.
http://im.yahoo.com/
More information about the Python-list
mailing list