carsonyl / pypac

Find and use proxy auto-config (PAC) files with Python and Requests.
https://pypac.readthedocs.io
Apache License 2.0
71 stars 18 forks source link

Using the same proxy file for parser_functions #38

Closed Ipv6Python closed 5 years ago

Ipv6Python commented 5 years ago

Hi, thank you for creating pypac. I'm not certain if below use case was addressed before and I was not successful in finding this. Please help.

After loading the file I was able to use find_proxy_for_url to test the hosts and called parser_functions as an individual for testing. But how can I use the same file to run the parser_functions so I can pass the new URL/Host to the existing file "f" for testing? something like below:

and yes, I used find_proxy_for_url it returns the proxy redirect. which doesn't help in my use case.

proxy.pac if(shExpMatch(host, *.abc)) return proxy_general;

with open('proxy.pac') as f: pac = PACFile(f.read()) session = PACSession(pac)

shExp = parser_functions.shExpMatch(bc, pac ) or shExp = parser_functions.shExpMatch (bc, f)

this returns me below error, but how can I achieve this?

shExpMatch return fnmatch(host.lower(), pattern.lower()) AttributeError: 'PACFile' object has no attribute 'lower'

carsonyl commented 5 years ago

Sorry, I don't think I fully understand your question. You're getting errors because you're passing PACFile and PAC file contents as the second argument to shExpMatch(), which isn't correct. It needs to be a shell expression pattern.