Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python3..../urllib
File: response.py
"""Response classes used by urllib.
[0] Fix | Delete
[1] Fix | Delete
The base class, addbase, defines a minimal file-like interface,
[2] Fix | Delete
including read() and readline(). The typical response object is an
[3] Fix | Delete
addinfourl instance, which defines an info() method that returns
[4] Fix | Delete
headers and a geturl() method that returns the url.
[5] Fix | Delete
"""
[6] Fix | Delete
[7] Fix | Delete
import tempfile
[8] Fix | Delete
[9] Fix | Delete
__all__ = ['addbase', 'addclosehook', 'addinfo', 'addinfourl']
[10] Fix | Delete
[11] Fix | Delete
[12] Fix | Delete
class addbase(tempfile._TemporaryFileWrapper):
[13] Fix | Delete
"""Base class for addinfo and addclosehook. Is a good idea for garbage collection."""
[14] Fix | Delete
[15] Fix | Delete
# XXX Add a method to expose the timeout on the underlying socket?
[16] Fix | Delete
[17] Fix | Delete
def __init__(self, fp):
[18] Fix | Delete
super(addbase, self).__init__(fp, '<urllib response>', delete=False)
[19] Fix | Delete
# Keep reference around as this was part of the original API.
[20] Fix | Delete
self.fp = fp
[21] Fix | Delete
[22] Fix | Delete
def __repr__(self):
[23] Fix | Delete
return '<%s at %r whose fp = %r>' % (self.__class__.__name__,
[24] Fix | Delete
id(self), self.file)
[25] Fix | Delete
[26] Fix | Delete
def __enter__(self):
[27] Fix | Delete
if self.fp.closed:
[28] Fix | Delete
raise ValueError("I/O operation on closed file")
[29] Fix | Delete
return self
[30] Fix | Delete
[31] Fix | Delete
def __exit__(self, type, value, traceback):
[32] Fix | Delete
self.close()
[33] Fix | Delete
[34] Fix | Delete
[35] Fix | Delete
class addclosehook(addbase):
[36] Fix | Delete
"""Class to add a close hook to an open file."""
[37] Fix | Delete
[38] Fix | Delete
def __init__(self, fp, closehook, *hookargs):
[39] Fix | Delete
super(addclosehook, self).__init__(fp)
[40] Fix | Delete
self.closehook = closehook
[41] Fix | Delete
self.hookargs = hookargs
[42] Fix | Delete
[43] Fix | Delete
def close(self):
[44] Fix | Delete
try:
[45] Fix | Delete
closehook = self.closehook
[46] Fix | Delete
hookargs = self.hookargs
[47] Fix | Delete
if closehook:
[48] Fix | Delete
self.closehook = None
[49] Fix | Delete
self.hookargs = None
[50] Fix | Delete
closehook(*hookargs)
[51] Fix | Delete
finally:
[52] Fix | Delete
super(addclosehook, self).close()
[53] Fix | Delete
[54] Fix | Delete
[55] Fix | Delete
class addinfo(addbase):
[56] Fix | Delete
"""class to add an info() method to an open file."""
[57] Fix | Delete
[58] Fix | Delete
def __init__(self, fp, headers):
[59] Fix | Delete
super(addinfo, self).__init__(fp)
[60] Fix | Delete
self.headers = headers
[61] Fix | Delete
[62] Fix | Delete
def info(self):
[63] Fix | Delete
return self.headers
[64] Fix | Delete
[65] Fix | Delete
[66] Fix | Delete
class addinfourl(addinfo):
[67] Fix | Delete
"""class to add info() and geturl() methods to an open file."""
[68] Fix | Delete
[69] Fix | Delete
def __init__(self, fp, headers, url, code=None):
[70] Fix | Delete
super(addinfourl, self).__init__(fp, headers)
[71] Fix | Delete
self.url = url
[72] Fix | Delete
self.code = code
[73] Fix | Delete
[74] Fix | Delete
def getcode(self):
[75] Fix | Delete
return self.code
[76] Fix | Delete
[77] Fix | Delete
def geturl(self):
[78] Fix | Delete
return self.url
[79] Fix | Delete
[80] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function