Steve schrieb:
> I am developing locally.  Any requests by the application (external
> links, search engines) have to go through a proxy before they can
> reach the outside.

So your TurboGears application accesses resources on other servers?

> When I (eventually) move the application to production, there won't be
> a proxy so my goal is to somehow setup, like you said, an environment
> variable (at this point hopefully in one of the .cfg files) so that
> when the application is started it knows whether it need a proxy (in
> dev) or not (prod).

Just define your own config setting and then in your controller code or in your
start script do something like the following:

import os

if turbogears.config.get('http_proxy'):
    os.environ['http_proxy'] = turbogears.config.get('http_proxy')
import urllib


Test (with local Squid proxy):

>>> r = urllib.urlopen('http://docs.python.org/lib/module-urllib.html')
>>>r.headers.items()
[('content-length', '28486'),
 ('proxy-connection', 'close'),
 ('x-cache', 'HIT from musicbox.paddyland.lan'),
 ('accept-ranges', 'bytes'),
 ('server',
  'Apache/2.0.54 (Debian GNU/Linux) DAV/2 SVN/1.1.4 mod_python/3.1.3
Python/2.3.5 mod_ssl/2.0.54 OpenSSL/0.9.7e'),
 ('x-cache-lookup', 'HIT from musicbox.paddyland.lan:3128'),
 ('last-modified', 'Tue, 19 Sep 2006 05:56:53 GMT'),
 ('etag', '"659c2-6f46-28433340"'),
 ('date', 'Thu, 01 Mar 2007 19:58:14 GMT'),
 ('content-type', 'text/html'),
 ('age', '358')]


Just be sure to import urllib after you have set the environment variable. Also
note that this does not work on Windows. See the urllib doc for more.

Chris

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to