Source

gae-rproxy / gae_rproxy / niceurllib.py

Full commit
# -*- coding: utf-8 -*-
'''
Created on 2010-7-16

@author: GL
'''
import urllib
from urllib import addinfourl as rawaddinfourl
class addinfourlstatus(rawaddinfourl):
    def __init__(self, fp, headers, url, status=200, errmsg=None):
        rawaddinfourl.__init__(self, fp, headers, url)
        self.status = status
        self.errmsg = errmsg

urllib.addinfourl = addinfourlstatus

class SimpleURLopener(urllib.FancyURLopener):
    def __init__(self, proxies=None, **x509):
        urllib.FancyURLopener.__init__(self, proxies, **x509)
        self.addheaders = []

    def http_error(self, url, fp, errcode, errmsg, headers, data=None):
        """Handle http errors.
        """
        return addinfourlstatus(fp, headers, url, errcode, errmsg)