• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Gallopsled / pwntools / 13600950642

01 Mar 2025 04:10AM UTC coverage: 74.211% (+3.2%) from 71.055%
13600950642

Pull #2546

github

web-flow
Merge 77df40314 into 60cff2437
Pull Request #2546: ssh: Allow passing `disabled_algorithms` keyword argument from `ssh` to paramiko

3812 of 6380 branches covered (59.75%)

0 of 1 new or added line in 1 file covered. (0.0%)

1243 existing lines in 37 files now uncovered.

13352 of 17992 relevant lines covered (74.21%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.59
/pwnlib/util/web.py
1
# -*- coding: utf-8 -*-
2
from __future__ import absolute_import
1✔
3
from __future__ import division
1✔
4

5
import os
1✔
6
import tempfile
1✔
7

8
from pwnlib.log import getLogger
1✔
9
from pwnlib.tubes.buffer import Buffer
1✔
10
from pwnlib.util.misc import size
1✔
11

12
log = getLogger(__name__)
1✔
13

14
def wget(url, save=None, timeout=5, **kwargs):
1✔
15
    r"""wget(url, save=None, timeout=5) -> str
16

17
    Downloads a file via HTTP/HTTPS.
18

19
    Arguments:
20
      url (str): URL to download
21
      save (str or bool): Name to save as.  Any truthy value
22
            will auto-generate a name based on the URL.
23
      timeout (int): Timeout, in seconds
24

25
    Example:
26

27
      >>> url    = 'https://httpbingo.org/robots.txt'
28
      >>> result = wget(url, timeout=60)
29
      >>> result
30
      b'User-agent: *\nDisallow: /deny\n'
31

32
      >>> filename = tempfile.mktemp()
33
      >>> result2 = wget(url, filename, timeout=60)
34
      >>> result == open(filename, 'rb').read()
35
      True
36
    """
37
    import requests
1✔
38

39
    with log.progress("Downloading %r" % url, rate=0.1) as w:
1✔
40
        w.status("Making request...")
1✔
41

42
        response = requests.get(url, stream=True, timeout=timeout, **kwargs)
1✔
43

44
        if not response.ok:
1✔
45
            w.failure("Got code %s" % response.status_code)
1✔
46
            return
1✔
47

48
        total_size = int(response.headers.get('content-length',0))
1✔
49

50
        w.status('0 / %s' % size(total_size))
1✔
51

52
        # Find out the next largest size we can represent as
53
        chunk_size = 1
1✔
54
        while chunk_size < (total_size/10):
1✔
55
            chunk_size *= 1000
1✔
56

57
        # Count chunks as they're received
58
        buf = Buffer()
1✔
59

60
        # Loop until we have all of the data
61
        for chunk in response.iter_content(chunk_size = 2**10):
1✔
62
            buf.add(chunk)
1✔
63
            if total_size:
1✔
64
                w.status('%s / %s' % (size(buf.size), size(total_size)))
1✔
65
            else:
66
                w.status('%s' % size(buf.size))
1✔
67

68
        total_data = buf.get()
1✔
69

70
        # Save to the target file if provided
71
        if save:
1✔
72
            if not isinstance(save, (bytes, str)):
1!
UNCOV
73
                save = os.path.basename(url)
×
74
                save = save or tempfile.NamedTemporaryFile(dir='.', delete=False).name
×
75
            with open(save,'wb+') as f:
1✔
76
                f.write(total_data)
1✔
77
                w.success('Saved %r (%s)' % (f.name, size(total_data)))
1✔
78
        else:
79
            w.success('%s' % size(total_data))
1✔
80

81
        return total_data
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc