diff options
author | Georg Brandl <georg@python.org> | 2008-01-20 11:43:03 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-01-20 11:43:03 (GMT) |
commit | 9b0d46db115c10767b240a0a64286214b50fe6ad (patch) | |
tree | 7ecec7b9261dfc50941932036aaec79af5a0a1ce /Lib/urllib.py | |
parent | dcd6b522060d9b14e26046519770e718e65802cd (diff) | |
download | cpython-9b0d46db115c10767b240a0a64286214b50fe6ad.zip cpython-9b0d46db115c10767b240a0a64286214b50fe6ad.tar.gz cpython-9b0d46db115c10767b240a0a64286214b50fe6ad.tar.bz2 |
#1178141: add addinfourl.code to get http status code from urllib.
Diffstat (limited to 'Lib/urllib.py')
-rw-r--r-- | Lib/urllib.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/urllib.py b/Lib/urllib.py index c6751b8..4a49fc0 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -343,7 +343,7 @@ class URLopener: # According to RFC 2616, "2xx" code indicates that the client's # request was successfully received, understood, and accepted. if (200 <= errcode < 300): - return addinfourl(fp, headers, "http:" + url) + return addinfourl(fp, headers, "http:" + url, errcode) else: if data is None: return self.http_error(url, fp, errcode, errmsg, headers) @@ -438,7 +438,7 @@ class URLopener: # According to RFC 2616, "2xx" code indicates that the client's # request was successfully received, understood, and accepted. if (200 <= errcode < 300): - return addinfourl(fp, headers, "https:" + url) + return addinfourl(fp, headers, "https:" + url, errcode) else: if data is None: return self.http_error(url, fp, errcode, errmsg, headers) @@ -610,7 +610,7 @@ class FancyURLopener(URLopener): def http_error_default(self, url, fp, errcode, errmsg, headers): """Default error handling -- don't raise an exception.""" - return addinfourl(fp, headers, "http:" + url) + return addinfourl(fp, headers, "http:" + url, errcode) def http_error_302(self, url, fp, errcode, errmsg, headers, data=None): """Error 302 -- relocated (temporarily).""" @@ -953,14 +953,18 @@ class addinfo(addbase): class addinfourl(addbase): """class to add info() and geturl() methods to an open file.""" - def __init__(self, fp, headers, url): + def __init__(self, fp, headers, url, code=None): addbase.__init__(self, fp) self.headers = headers self.url = url + self.code = code def info(self): return self.headers + def getcode(self): + return self.code + def geturl(self): return self.url |