views:

308

answers:

1

Follow on from this question:

I am working on a Python 2.4 app which will run on Windows XP. It needs to be able to download various resources from HTTP and it's got to work in all of our office locations which use "PAC" files to automatically select http proxies.

Thanks to somebody who responded to my previous question I managed to find a technique to execute Javascript from within Python, it's really easy:

js = win32com.client.Dispatch('MSScriptControl.ScriptControl')
js.Language = 'JavaScript'
js.AddCode('function foo(a,b) {return a;}'  )
result = js.Run( "foo", "hello" )

But here comes the problem:

The PAC file references a number of functions such as shExpMatch and isPlainHostName - these are presumably provided for free by Microsoft Internet Explorer. If I simply run the PAC file in Widnows Scripting using the recipe above it will fail because these functions are not missing.

So what I need is a way to set up the environment exactly the same way that IE does. The obvious way is to somehow import the functions in the same way that IE does.

I found that Firefox contains a single JS file which includes these functions, I suppose I could try to run Firefox's JS on Microsoft's scripting-host, but that sounds like a risky idea. What I really want is to make the javascript environment 100% Microsoft standard without anything that can make my life harder.

Any suggestions?

PS. You can see an example of a PAC file on Wikipedia. Unfortunately I cannot publish ours... that would violate company security.

+1  A: 

Are you able to download the PAC file from the remote host? I am asking because usually urllib in python uses static information for the proxy, retrieved from the registry.
However, if you are able to get that file, then I think you could be able to get also another file - and then your idea of using FF version could kick in.

Roberto Liffredo
Yes, I can download it. That's the easy part. I can also push it into Windows Scripting host via Win32Com. The problem is that it will not run because I do not have Microsoft's implementations of the standard PAC functions.
Salim Fadhley
So, if you can download or push it, you can download/push also another version of the file, where functions like shExpMatch are already defined (like, you said, in the way FF does). In this way, you can evaluate the PAC even without the full blown IE environment.
Roberto Liffredo
Exactly so I need to find Microsoft's implementation of these functions. I can see the Mozilla implementation - It's in a JS file. But I need this to be as close to MS standard as possible.
Salim Fadhley