Ejemplo n.º 1
0
 def ratelimit(self, direction, limit):
     log.debug('CLIHandler.ratelimit()')
     download_limit, upload_limit = get_ratelimits(self.ui_config)
     if direction is not None:
         if limit > 1000000:
             self.out('Limit cannot exceed 1000000 KB/s (1 GB/s).')
             return False
         if direction == 'up':
             upload_limit = limit
         elif direction == 'down':
             download_limit = limit
         else:
             self.out('First parameter must be \'up\' or \'down\'.')
             return False
         set_ratelimits(self.ui_config, download_limit, upload_limit)
         if self._daemon_already_running():
             self.daemon_client.networkSettingsChanged()
     if upload_limit == 0:
         self.out('Upload limit: N/A')
     else:
         self.out('Upload limit: {0} KB/s'.format(upload_limit))
     if download_limit == 0:
         self.out('Download limit: N/A')
     else:
         self.out('Download limit: {0} KB/s'.format(download_limit))
     return True
Ejemplo n.º 2
0
def get_network_settings(ui_config):
    network_settings = NetworkSettings()

    download_limit, upload_limit = get_ratelimits(ui_config)
    network_settings.downloadBandwidth = download_limit * 1024  # KB/s to B/s
    network_settings.uploadBandwidth = upload_limit * 1024  # KB/s to B/s

    proxy_url = get_proxy(ui_config)
    if proxy_url:
        try:
            parsed = urlparse.urlparse(proxy_url)
        except Exception:
            # Something went wrong while trying to parse proxy_url
            # Ignore and just don't use any proxy
            pass
        else:
            if parsed.hostname:
                network_settings.proxyAddress = parsed.hostname
                network_settings.proxyType = 'http'
                network_settings.proxyPort = parsed.port or 3128
                network_settings.proxyUser = parsed.user if hasattr(
                    parsed, 'user') else ''
                network_settings.proxyPassword = parsed.password if hasattr(
                    parsed, 'password') else ''

    return network_settings
Ejemplo n.º 3
0
 def ratelimit(self, direction, limit):
     log.debug('CLIHandler.ratelimit()')
     download_limit, upload_limit = get_ratelimits(self.ui_config)
     if direction is not None:
         if limit > 1000000:
             self.out('Limit cannot exceed 1000000 KB/s (1 GB/s).')
             return False
         if direction == 'up':
             upload_limit = limit
         elif direction == 'down':
             download_limit = limit
         else:
             self.out('First parameter must be \'up\' or \'down\'.')
             return False
         set_ratelimits(self.ui_config, download_limit, upload_limit)
         if self._daemon_already_running():
             self.daemon_client.networkSettingsChanged()
     if upload_limit == 0:
         self.out('Upload limit: N/A')
     else:
         self.out('Upload limit: {0} KB/s'.format(upload_limit))
     if download_limit == 0:
         self.out('Download limit: N/A')
     else:
         self.out('Download limit: {0} KB/s'.format(download_limit))
     return True
Ejemplo n.º 4
0
def get_network_settings(ui_config):
    network_settings = NetworkSettings()

    download_limit, upload_limit = get_ratelimits(ui_config)
    network_settings.downloadBandwidth = download_limit * 1024  # KB/s to B/s
    network_settings.uploadBandwidth = upload_limit * 1024  # KB/s to B/s

    proxy_url = get_proxy(ui_config)
    if proxy_url:
        try:
            parsed = urlparse.urlparse(proxy_url)
        except Exception:
            # Something went wrong while trying to parse proxy_url
            # Ignore and just don't use any proxy
            pass
        else:
            if parsed.hostname:
                network_settings.proxyAddress = parsed.hostname
                network_settings.proxyType = 'http'
                network_settings.proxyPort = parsed.port or 3128
                network_settings.proxyUser = parsed.user if hasattr(parsed, 'user') else ''
                network_settings.proxyPassword = parsed.password if hasattr(parsed, 'password') else ''

    return network_settings