Thanks Chris,

I'm on windows.  Rats.  However, your sample has given me a number of
things to think about.  Right now I have set the proxy this way:

def getConfigItem(key):
    #Using this as my config file till I figure out how to use the dev/
prod.cfg
    configdict = dict(
              proxy=True,
              proxyserver="myproxy.com",
              proxyport=8080

                  )
    return configdict[key]

Then throughout the project I import the object above and use it as
necessary:

self.proxy = getConfigItem("proxy")
self.proxyurl = getConfigItem("proxyserver")
self.proxyport = getConfigItem("proxyport")

And this all works fine, I was just looking for perhaps a prettier way
to let the entire application know whether it needed to the use the
proxy (because it's a development environment) or not (prod.) without
having to edit too much code between environments.


Thanks again for your tips, I'll continue to chip away.

-Bishop



On Mar 1, 3:08 pm, Christopher Arndt <[EMAIL PROTECTED]> wrote:
> 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