# Path: hornet/common/helpers.py
# def human_readable(num, suffix=''):
#     for unit in ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z']:
#         if abs(num) < 1024.0:
#             return "%3.1f%s%s" % (num, unit, suffix)
#         num /= 1024.0
#     return "%.1f%s%s" % (num, 'Yi', suffix)


import logging
import os
import random
import urlparse
import gevent
import requests
import requests.exceptions
import time
import socket
from contextlib import closing
from hornet.common.helpers import human_readable
        logger.debug('Total size set to: {}'.format(self.total_size))

    def _write_info_line(self):
        self.shell.writeline('--{}-- {}'.format(time.strftime('%Y-%m-%d %H:%M:%S'), self.url))

    def _write_dns_resolution_failed(self):
        self.shell.writeline('Resolving {} ({})... failed: Name or service '
                             'not known.'.format(self.parsed_url.hostname, self.parsed_url.hostname))

    def _write_dns_resolution_successful(self):
        try:
            # This will generally be successful. If the hostname was really not
            # resolved, `_get_total_size()` would have failed.
            self.ip_address = socket.gethostbyname(self.parsed_url.hostname)
        except socket.error:
            self.ip_address = '.'.join(''.format(random.randint(1, 254)) for i in range(4))
        self.shell.writeline('Resolving {0} ({0})... {1}'.format(
            self.parsed_url.hostname,
            self.ip_address,
        ))

    def _write_connection_info(self):
        self.shell.writeline('Connecting to {0} ({0})|{1}|:{2}... connected.'.format(
            self.parsed_url.hostname,
            self.ip_address,
            self.port
        ))
        self.shell.writeline('HTTP request sent, awaiting response... 200 OK')
        self.shell.writeline('Length: {} ({}) [{}]'.format(
            self.total_size,

# Path: hornet/common/helpers.py
# def human_readable(num, suffix=''):
#     for unit in ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z']:
#         if abs(num) < 1024.0:
#             return "%3.1f%s%s" % (num, unit, suffix)
#         num /= 1024.0
#     return "%.1f%s%s" % (num, 'Yi', suffix)


# Path: hornet/core/commands/wget_command.py
import logging
import os
import random
import urlparse
import gevent
import requests
import requests.exceptions
import time
import socket
from contextlib import closing
from hornet.common.helpers import human_readable

        logger.debug('Total size set to: {}'.format(self.total_size))

    def _write_info_line(self):
        self.shell.writeline('--{}-- {}'.format(time.strftime('%Y-%m-%d %H:%M:%S'), self.url))

    def _write_dns_resolution_failed(self):
        self.shell.writeline('Resolving {} ({})... failed: Name or service '
                             'not known.'.format(self.parsed_url.hostname, self.parsed_url.hostname))

    def _write_dns_resolution_successful(self):
        try:
            # This will generally be successful. If the hostname was really not
            # resolved, `_get_total_size()` would have failed.
            self.ip_address = socket.gethostbyname(self.parsed_url.hostname)
        except socket.error:
            self.ip_address = '.'.join(''.format(random.randint(1, 254)) for i in range(4))
        self.shell.writeline('Resolving {0} ({0})... {1}'.format(
            self.parsed_url.hostname,
            self.ip_address,
        ))

    def _write_connection_info(self):
        self.shell.writeline('Connecting to {0} ({0})|{1}|:{2}... connected.'.format(
            self.parsed_url.hostname,
            self.ip_address,
            self.port
        ))
        self.shell.writeline('HTTP request sent, awaiting response... 200 OK')
        self.shell.writeline('Length: {} ({}) [{}]'.format(
            self.total_size,

            human_readable(self.total_size),