官术网_书友最值得收藏!

How it works

The URL is defined as a constant  const.ApodEclipseImage() in the const module:

def ApodEclipseImage():
return "https://apod.nasa.gov/apod/image/1709/BT5643s.jpg"

The constructor of the URLUtility class has the following implementation:

def __init__(self, url, readNow=True):
""" Construct the object, parse the URL, and download now if specified"""
self._url = url
self._response = None
self._parsed = urlparse(url)
if readNow:
self.read()

The constructor stores the URL, parses it, and downloads the file with the read() method.  The following is the code of the read() method:

def read(self):
self._response = urllib.request.urlopen(self._url)
self._data = self._response.read()

This function uses urlopen to get a response object, and then reads the stream and stores it as a property of the object.  That data can then be retrieved using the data property:

@property
def data(self):
self.ensure_response()
return self._data

The code then simply reports on the length of that data, with the value of 171014.

主站蜘蛛池模板: 五河县| 南城县| 米泉市| 景德镇市| 青阳县| 新民市| 新绛县| 邯郸市| 仁寿县| 象山县| 杭州市| 县级市| 平武县| 靖安县| 松桃| 商丘市| 元氏县| 淮阳县| 沙雅县| 福清市| 余干县| 广安市| 曲周县| 双鸭山市| 邹城市| 剑川县| 大渡口区| 盖州市| 诏安县| 崇仁县| 河西区| 乌拉特前旗| 东方市| 丰都县| 武邑县| 呼图壁县| 温宿县| 扶风县| 新竹市| 洱源县| 陕西省|