Пример #1
0
def download(uri, downfull=False):
    url = urlparse(uri)

    r = (url.netloc or url.path).split(':', 1)
    if len(r) > 1: port = int(r[1])
    else: port = 443 if url.scheme.lower() == 'https' else 80
    hostname, port = r[0], port
    uri = url.path + ('?' + url.query if url.query else '')

    req = http.request_http(uri)
    req.set_header("Host", url.hostname)
    res = http.http_client(req, (hostname, port), c)

    if downfull: return res.read_body()

    m = md5.new()
    cnt = 0
    for d in res.read_chunk(res.stream):
        cnt += len(d)
        m.update(d)
    sys.stdout.write('done\n')
    return m.hexdigest()
Пример #2
0
def download(uri, downfull=False):
    url = urlparse(uri)

    r = (url.netloc or url.path).split(':', 1)
    if len(r) > 1: port = int(r[1])
    else: port = 443 if url.scheme.lower() == 'https' else 80
    hostname, port = r[0], port
    uri = url.path + ('?'+url.query if url.query else '')

    req = http.request_http(uri)
    req.set_header("Host", url.hostname)
    res = http.http_client(req, (hostname, port), c)

    if downfull: return res.read_body()

    m = md5.new()
    cnt = 0
    for d in res.read_chunk(res.stream):
        cnt += len(d)
        m.update(d)
    sys.stdout.write('done\n')
    return m.hexdigest()