Esempio n. 1
0
def find( site, pacfile, myip = "" ):
  pacparser.init()
  pac_file_cache = cache_pacfile.cache(pacfile)
  if not myip == "":
    pacparser.setmyip(myip)
  pacparser.parse_pac(pac_file_cache)

  return pacparser.find_proxy(site) 
Esempio n. 2
0
def proxy_test(pac_string, myip, url):
    pp.init()
    if myip:
        pp.setmyip(myip)
    if not url:
        url = 'http://www.google.com'
    pp._pacparser.parse_pac_string(pac_string)
    proxy = pp.find_proxy(url)
    return proxy
Esempio n. 3
0
def index(pacfile=None):

    myip = request.args.get('myip', '')
    url = request.args.get('url', 'http://www.google.com')

    pp.init()
    pp.setmyip(myip)
    pp.parse_pac('test.pac')
    proxy = pp.find_proxy(url)

    return proxy
Esempio n. 4
0
def runtests(pacfile, testdata, tests_dir):
  py_ver = '.'.join([str(x) for x in sys.version_info[0:2]])
  if sys.platform == 'win32':
    pacparser_module_path = os.path.join(
      tests_dir, '..', 'src', 'pymod',
      'pacparser-python%s' % sysconfig.get_config_vars('VERSION')[0])
    if os.path.exists(os.path.join(pacparser_module_path, '_pacparser.pyd')):
      raise Exception('Tests failed. Could not determine pacparser path.')
  else:
    try:
      pacparser_module_path = glob.glob(os.path.join(
        tests_dir, '..', 'src', 'pymod', 'build', 'lib*%s' % py_ver))[0]
    except Exception:
      raise Exception('Tests failed. Could not determine pacparser path.')
  if 'DEBUG' in os.environ: print('Pacparser module path: %s' %
                                  pacparser_module_path)
  sys.path.insert(0, pacparser_module_path)

  try:
    import pacparser
  except ImportError:
    raise Exception('Tests failed. Could not import pacparser.')

  if 'DEBUG' in os.environ: print('Imported pacparser module: %s' %
                                  sys.modules['pacparser'])

  f = open(testdata)
  for line in f:
    comment = ''
    if '#' in line:
      comment = line.split('#', 1)[1]
      line = line.split('#', 1)[0].strip()
    if not line:
      continue
    if ('NO_INTERNET' in os.environ and os.environ['NO_INTERNET'] and
        'INTERNET_REQUIRED' in comment):
      continue
    if 'DEBUG' in os.environ: print(line)
    (params, expected_result) = line.strip().split('|')
    args = dict(getopt.getopt(params.split(), 'eu:c:')[0])
    if '-e' in args:
      pacparser.enable_microsoft_extensions()
    if '-c' in args:
      pacparser.setmyip(args['-c'])
    pacparser.init()
    pacparser.parse_pac_file(pacfile)
    result = pacparser.find_proxy(args['-u'])
    pacparser.cleanup()
    if result != expected_result:
      raise Exception('Tests failed. Got "%s", expected "%s"' % (result, expected_result))
  print('All tests were successful.')
Esempio n. 5
0
def runtests(pacfile, testdata, tests_dir):
  py_ver = '.'.join([str(x) for x in sys.version_info[0:2]])
  if sys.platform == 'win32':
    pacparser_module_path = os.path.join(tests_dir, '..', 'src', 'pymod', 'dist')
    if os.path.exists(os.path.join(pacparser_module_path, '_pacparser.pyd')):
      raise Exception('Tests failed. Could not determine pacparser path.')
  else:
    try:
      pacparser_module_path = glob.glob(os.path.join(
        tests_dir, '..', 'src', 'pymod', 'build', 'lib*%s' % py_ver))[0]
    except Exception:
      raise Exception('Tests failed. Could not determine pacparser path.')
  if 'DEBUG' in os.environ: print('Pacparser module path: %s' %
                                  pacparser_module_path)
  sys.path.insert(0, pacparser_module_path)

  try:
    import pacparser
  except ImportError:
    raise Exception('Tests failed. Could not import pacparser.')

  if 'DEBUG' in os.environ: print('Imported pacparser module: %s' %
                                  sys.modules['pacparser'])

  f = open(testdata)
  for line in f:
    comment = ''
    if '#' in line:
      comment = line.split('#', 1)[1]
      line = line.split('#', 1)[0].strip()
    if not line:
      continue
    if ('NO_INTERNET' in os.environ and os.environ['NO_INTERNET'] and
        'INTERNET_REQUIRED' in comment):
      continue
    if 'DEBUG' in os.environ: print(line)
    (params, expected_result) = line.strip().split('|')
    args = dict(getopt.getopt(params.split(), 'eu:c:')[0])
    if '-e' in args:
      pacparser.enable_microsoft_extensions()
    if '-c' in args:
      pacparser.setmyip(args['-c'])
    pacparser.init()
    pacparser.parse_pac_file(pacfile)
    result = pacparser.find_proxy(args['-u'])
    pacparser.cleanup()
    if result != expected_result:
      raise Exception('Tests failed. Got "%s", expected "%s"' % (result, expected_result))
  print('All tests were successful.')