Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python3..../urllib
File: error.py
"""Exception classes raised by urllib.
[0] Fix | Delete
[1] Fix | Delete
The base exception class is URLError, which inherits from OSError. It
[2] Fix | Delete
doesn't define any behavior of its own, but is the base class for all
[3] Fix | Delete
exceptions defined in this package.
[4] Fix | Delete
[5] Fix | Delete
HTTPError is an exception class that is also a valid HTTP response
[6] Fix | Delete
instance. It behaves this way because HTTP protocol errors are valid
[7] Fix | Delete
responses, with a status code, headers, and a body. In some contexts,
[8] Fix | Delete
an application may want to handle an exception like a regular
[9] Fix | Delete
response.
[10] Fix | Delete
"""
[11] Fix | Delete
[12] Fix | Delete
import urllib.response
[13] Fix | Delete
[14] Fix | Delete
__all__ = ['URLError', 'HTTPError', 'ContentTooShortError']
[15] Fix | Delete
[16] Fix | Delete
[17] Fix | Delete
class URLError(OSError):
[18] Fix | Delete
# URLError is a sub-type of OSError, but it doesn't share any of
[19] Fix | Delete
# the implementation. need to override __init__ and __str__.
[20] Fix | Delete
# It sets self.args for compatibility with other OSError
[21] Fix | Delete
# subclasses, but args doesn't have the typical format with errno in
[22] Fix | Delete
# slot 0 and strerror in slot 1. This may be better than nothing.
[23] Fix | Delete
def __init__(self, reason, filename=None):
[24] Fix | Delete
self.args = reason,
[25] Fix | Delete
self.reason = reason
[26] Fix | Delete
if filename is not None:
[27] Fix | Delete
self.filename = filename
[28] Fix | Delete
[29] Fix | Delete
def __str__(self):
[30] Fix | Delete
return '<urlopen error %s>' % self.reason
[31] Fix | Delete
[32] Fix | Delete
[33] Fix | Delete
class HTTPError(URLError, urllib.response.addinfourl):
[34] Fix | Delete
"""Raised when HTTP error occurs, but also acts like non-error return"""
[35] Fix | Delete
__super_init = urllib.response.addinfourl.__init__
[36] Fix | Delete
[37] Fix | Delete
def __init__(self, url, code, msg, hdrs, fp):
[38] Fix | Delete
self.code = code
[39] Fix | Delete
self.msg = msg
[40] Fix | Delete
self.hdrs = hdrs
[41] Fix | Delete
self.fp = fp
[42] Fix | Delete
self.filename = url
[43] Fix | Delete
# The addinfourl classes depend on fp being a valid file
[44] Fix | Delete
# object. In some cases, the HTTPError may not have a valid
[45] Fix | Delete
# file object. If this happens, the simplest workaround is to
[46] Fix | Delete
# not initialize the base classes.
[47] Fix | Delete
if fp is not None:
[48] Fix | Delete
self.__super_init(fp, hdrs, url, code)
[49] Fix | Delete
[50] Fix | Delete
def __str__(self):
[51] Fix | Delete
return 'HTTP Error %s: %s' % (self.code, self.msg)
[52] Fix | Delete
[53] Fix | Delete
def __repr__(self):
[54] Fix | Delete
return '<HTTPError %s: %r>' % (self.code, self.msg)
[55] Fix | Delete
[56] Fix | Delete
# since URLError specifies a .reason attribute, HTTPError should also
[57] Fix | Delete
# provide this attribute. See issue13211 for discussion.
[58] Fix | Delete
@property
[59] Fix | Delete
def reason(self):
[60] Fix | Delete
return self.msg
[61] Fix | Delete
[62] Fix | Delete
@property
[63] Fix | Delete
def headers(self):
[64] Fix | Delete
return self.hdrs
[65] Fix | Delete
[66] Fix | Delete
@headers.setter
[67] Fix | Delete
def headers(self, headers):
[68] Fix | Delete
self.hdrs = headers
[69] Fix | Delete
[70] Fix | Delete
[71] Fix | Delete
class ContentTooShortError(URLError):
[72] Fix | Delete
"""Exception raised when downloaded size does not match content-length."""
[73] Fix | Delete
def __init__(self, message, content):
[74] Fix | Delete
URLError.__init__(self, message)
[75] Fix | Delete
self.content = content
[76] Fix | Delete
[77] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function