コード例 #1
0
ファイル: utils.py プロジェクト: parmegv/tor-browser-selenium
def launch_tbb_tor_with_stem(tbb_path=None, torrc=None, tor_binary=None):
    if not (tor_binary or tbb_path):
        raise StemLaunchError("Either pass tbb_path or tor_binary")
    if not tor_binary and tbb_path:
        tor_binary = join(tbb_path, cm.DEFAULT_TOR_BINARY_PATH)
    if not isfile(tor_binary):
        raise StemLaunchError("Invalid Tor binary")
    modify_env_var("LD_LIBRARY_PATH", dirname(tor_binary))
    temp_data_dir = tempfile.mkdtemp()
    if torrc is None:
        torrc = {
            'ControlPort': str(cm.STEM_CONTROL_PORT),
            'SOCKSPort': str(cm.STEM_SOCKS_PORT),
            'DataDirectory': temp_data_dir
        }

    return launch_tor_with_config(config=torrc, tor_cmd=tor_binary)
コード例 #2
0
def launch_tbb_tor_with_stem(tbb_path=None, torrc=None, tor_binary=None):
    """Launch the Tor binary in tbb_path using Stem."""
    if not (tor_binary or tbb_path):
        raise StemLaunchError("Either pass tbb_path or tor_binary")

    if not tor_binary and tbb_path:
        tor_binary = join(tbb_path, cm.DEFAULT_TOR_BINARY_PATH)

    if not isfile(tor_binary):
        raise StemLaunchError("Invalid Tor binary")

    prepend_to_env_var("LD_LIBRARY_PATH", dirname(tor_binary))
    if torrc is None:
        torrc = {
            'ControlPort': str(cm.STEM_CONTROL_PORT),
            'SOCKSPort': str(cm.STEM_SOCKS_PORT),
            'DataDirectory': tempfile.mkdtemp()
        }
コード例 #3
0
def launch_tbb_tor_with_stem_fixture(*args, **kwargs):
    for tries in range(MAX_FIXTURE_TRIES):
        try:
            return launch_tbb_tor_with_stem(*args, **kwargs)
        except OSError as last_err:
            print("\nlaunch_tor try %s %s" % ((tries + 1), last_err))
            if "timeout without success" in str(last_err):
                continue
            else:  # we don't want to retry if this is not a timeout
                raise
    # Raise if we didn't return yet
    to_raise = last_err if last_err else\
        StemLaunchError("Cannot start Tor")
    raise to_raise