'Handle http errors.
Derived class can override this, or provide specific handlers
named http_error_DDD where DDD is the 3-digit error code.'

def http_error(self, url, fp, errcode, errmsg, headers, data=None):

    name = ('http_error_%d' % errcode)
    if hasattr(self, name):
        method = getattr(self, name)
        if (data is None):
            result = method(url, fp, errcode, errmsg, headers)
        else:
            result = method(url, fp, errcode, errmsg, headers, data)
        if result:
            return result
    return self.http_error_default(url, fp, errcode, errmsg, headers)
