Exemplo n.º 1
0
 def init_poolmanager(self, connections, maxsize, block=False):
     context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
     context.options |= ssl.OP_NO_SSLv2
     context.options |= ssl.OP_NO_SSLv3
     self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize, block=block, ssl_version=context)
Exemplo n.º 2
0
 def init_poolmanager(self, connections, maxsize, block=False):
     self.poolmanager = PoolManager(num_pools=connections,
                                    maxsize=maxsize,
                                    block=block)
Exemplo n.º 3
0
 def init_poolmanager(self, connections, maxsize, block=False):
     self.poolmanager = PoolManager(num_pools=connections,
                                    maxsize=maxsize,
                                    block=block,
                                    ssl_version=ssl.PROTOCOL_TLSv1)
Exemplo n.º 4
0
 def init_poolmanager(self, connections, maxsize, **kwargs):
     self.poolmanager = PoolManager(num_pools=connections,
                                    maxsize=maxsize, **kwargs)
Exemplo n.º 5
0
 def init_poolmanager(self, *pool_args, **pool_kwargs):
     self.poolmanager = PoolManager(
         *pool_args,
         ssl_version=ssl.PROTOCOL_TLSv1_2,
         **pool_kwargs)
Exemplo n.º 6
0
 def init_poolmanager(self, connections, maxsize, block=False):
     self.poolmanager = PoolManager(num_pools=connections,
                                    maxsize=maxsize,
                                    block=block,
                                    assert_fingerprint=self.fingerprint)
Exemplo n.º 7
0
 def init_poolmanager(self, connections, maxsize, block=requests.adapters.DEFAULT_POOLBLOCK, **pool_kwargs):
     self.poolmanager = PoolManager(num_pools=connections,
                                    maxsize=maxsize,
                                    block=block,
                                    strict=True,
                                    assert_hostname=False, **pool_kwargs)
Exemplo n.º 8
0
 def init_poolmanager(self, connections, maxsize, block=False):
     # This method gets called when there's no proxy.
     self.poolmanager = PoolManager(num_pools=connections,
                                    maxsize=maxsize,
                                    block=block,
                                    ssl_version=ssl.PROTOCOL_TLSv1_2)
Exemplo n.º 9
0
 def init_pool(self, connections, block=False):
     self.pool = PoolManager(num_pools=connections, block=block)
Exemplo n.º 10
0
 def init_poolmanager(self, connections, maxsize, block):
     self.poolmanager = PoolManager(num_pools=connections,
                                    maxsize=maxsize,
                                    ssl_version=self.ssl_version,
                                    block=block)
Exemplo n.º 11
0
 def init_poolmanager(self, connections, maxsize, block=False, **kwargs):
     self.poolmanager = PoolManager(num_pools=connections,
                                    maxsize=maxsize, block=block,
                                    ssl_version=self.tls_version)
Exemplo n.º 12
0
    def init_poolmanager(self, *pool_args, **pool_kwargs):

        self.poolmanager = PoolManager(
            *pool_args,
            ssl_version=ssl.PROTOCOL_SSLv3,  # Noncompliant
            **pool_kwargs)
Exemplo n.º 13
0
 def init_poolmanager(pat, connections, maxsize, block=False):
     pat.poolmanager = PoolManager(num_pools=connections,
                                   maxsize=maxsize,
                                   block=block)
Exemplo n.º 14
0
 def init_poolmanager(self, connections, maxsize, block=DEFAULT_POOLBLOCK, **pool_kwargs):
     self.poolmanager = PoolManager(num_pools=connections,
                                    maxsize=maxsize,
                                    block=block,
                                    ssl_version=self.Protocol)
Exemplo n.º 15
0
    def init_poolmanager(self, connections, maxsize, **kwargs):
        """
        Initializes pool manager to use ssl version v1.
        """

        self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize, ssl_version=ssl.PROTOCOL_TLSv1, **kwargs)
Exemplo n.º 16
0
 def init_poolmanager(self, connections, maxsize, block=DEFAULT_POOLBLOCK):
     self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize)
Exemplo n.º 17
0
 def init_poolmanager(self, connections, maxsize, block=False):
     self.poolmanager = PoolManager(num_pools=connections,
                                    maxsize=maxsize,
                                    block=block,
                                    cert_file=self.cert_file,
                                    key_file=self.key_file)
Exemplo n.º 18
0
 def init_poolmanager(self, connections, maxsize, block=False):
     """Initialize :class:`.PoolManager` without hostname assertion."""
     self.poolmanager = PoolManager(num_pools=connections,
                                    maxsize=maxsize,
                                    block=block,
                                    assert_hostname=False)
Exemplo n.º 19
0
 def init_poolmanager(self, connections, maxsize, block=False, **pool_kwargs):
     self.poolmanager = PoolManager(num_pools=connections,
                                    maxsize=maxsize,
                                    block=block,
                                    assert_hostname=False, **pool_kwargs)
Exemplo n.º 20
0
 def init_poolmanager(self, connections, maxsize, **kwargs):
     self.poolmanager = PoolManager(num_pools=connections,
                                    maxsize=maxsize,
                                    ssl_version=ssl.PROTOCOL_SSLv3,
                                    **kwargs)
 def init_poolmanager(self, connections, maxsize, block=False):
     self.poolmanager = PoolManager(num_pools=connections,
                                    maxsize=maxsize,
                                    block=block,
                                    assert_hostname=False,
                                    ssl_version=ssl.PROTOCOL_SSLv23)
Exemplo n.º 22
0
 def init_poolmanager(self, connections, maxsize, block=False):
     """Set up a poolmanager to use TLS and our cipher list."""
     self.poolmanager = PoolManager(
         num_pools=connections, maxsize=maxsize, block=block,
         ssl_version=ssl.PROTOCOL_TLSv1)   # pylint: disable=no-member
     pyopenssl.DEFAULT_SSL_CIPHER_LIST = CIPHER_LIST
Exemplo n.º 23
0
def download_result_file(url, result_file_directory, result_file_name,
                         decompress, overwrite):
    """ Download file with specified URL and download parameters.

    :param result_file_directory: The download result local directory name.
    :type result_file_directory: str
    :param result_file_name: The download result local file name.
    :type result_file_name: str
    :param decompress: Determines whether to decompress the ZIP file.
                        If set to true, the file will be decompressed after download.
                        The default value is false, in which case the downloaded file is not decompressed.
    :type decompress: bool
    :param overwrite: Indicates whether the result file should overwrite the existing file if any.
    :type overwrite: bool
    :return: The download file path.
    :rtype: str
    """

    if result_file_directory is None:
        raise ValueError('result_file_directory cannot be None.')

    if result_file_name is None:
        result_file_name = "default_file_name"

    if decompress:
        name, ext = os.path.splitext(result_file_name)
        if ext == '.zip':
            raise ValueError(
                "Result file can't be decompressed into a file with extension 'zip'."
                " Please change the extension of the result_file_name or pass decompress=false"
            )
        zip_file_path = os.path.join(result_file_directory, name + '.zip')
        result_file_path = os.path.join(result_file_directory,
                                        result_file_name)
    else:
        result_file_path = os.path.join(result_file_directory,
                                        result_file_name)
        zip_file_path = result_file_path

    if os.path.exists(result_file_path) and overwrite is False:
        if six.PY3:
            raise FileExistsError(
                'Result file: {0} exists'.format(result_file_path))
        else:
            raise OSError('Result file: {0} exists'.format(result_file_path))

    pool_manager = PoolManager(ssl_version=ssl.PROTOCOL_SSLv3, )
    http_adapter = HTTPAdapter()
    http_adapter.poolmanager = pool_manager

    s = requests.Session()
    s.mount('https://', http_adapter)
    r = s.get(url, stream=True, verify=True)
    r.raise_for_status()
    try:
        with open(zip_file_path, 'wb') as f:
            for chunk in r.iter_content(chunk_size=4096):
                if chunk:
                    f.write(chunk)
                    f.flush()
        if decompress:
            with contextlib.closing(
                    zipfile.ZipFile(zip_file_path)) as compressed:
                first = compressed.namelist()[0]
                with open(result_file_path, 'wb') as f:
                    f.write(compressed.read(first))
    except Exception as ex:
        raise ex
    finally:
        if decompress and os.path.exists(zip_file_path):
            os.remove(zip_file_path)
    return result_file_path
Exemplo n.º 24
0
 def init_poolmanager(self, connections, maxsize, block=False,*args, **kwargs):
     context = create_urllib3_context(ciphers=CIPHERS)
     kwargs['ssl_context'] = context
     self.poolmanager = PoolManager(
         num_pools=connections, maxsize=maxsize,
         block=block, ssl_version=ssl.PROTOCOL_SSLv3,*args, **kwargs)
Exemplo n.º 25
0
 def init_poolmanager(self, connections, maxsize, block=False):
     self.poolmanager = PoolManager(num_pools=connections,
                                    maxsize=maxsize,
                                    block=block,
                                    ssl_version=self.ssl_protocol)
Exemplo n.º 26
0
 def init_poolmanager(self, connections, maxsize, **kwargs):
     self.poolmanager = PoolManager(num_pools=connections,
                                    maxsize=maxsize,
                                    ssl_version=SSL_VERSION,
                                    **kwargs)
Exemplo n.º 27
0
 def init_poolmanager(self, connections, maxsize, block=False):
     self.poolmanager = PoolManager(num_pools=connections,
                                    maxsize=maxsize,
                                    block=block,
                                    source_address=("", self._source_port))
Exemplo n.º 28
0
    def init_poolmanager(self, connections, maxsize, block=False):

        self.poolmanager = PoolManager(num_pools=connections,
                                       maxsize=maxsize,
                                       block=block,
                                       assert_hostname='localhost')
Exemplo n.º 29
0
 def init_poolmanager(self, connections, maxsize, block=False):
     self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize,
                                    block=block, ssl_version=latest_available_ssl_version())
 def init_poolmanager(self, connections, maxsize, block=False):
     self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize,
                                    block=block, ssl_version=latest_available_ssl_version(),
                                    assert_hostname=self._assert_hostname,
                                    assert_fingerprint=self._assert_fingerprint)