Skip to content

Commit

Permalink
Adds proxy plugin. fix Flexget#1490
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.flexget.com/trunk@2747 3942dd89-8c5d-46d7-aeed-044bccf3e60c
  • Loading branch information
gazpachoking committed Feb 27, 2012
1 parent 82360b6 commit 977ea3c
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions flexget/plugins/operate/proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
import logging
from flexget import plugin
from flexget import validator

log = logging.getLogger('proxy')

PROTOCOLS = ['http', 'https', 'ftp']


class Proxy(object):
"""Adds a proxy to the requests session."""

def validator(self):
root = validator.factory()
# Accept one proxy for everything
root.accept('url')
# Accept a dict mapping protocol to proxy
advanced = root.accept('dict')
for prot in PROTOCOLS:
advanced.accept('url', key=prot)
return root

@plugin.priority(255)
def on_feed_start(self, feed, config):
if not config:
# If no configuration is provided, see if there are any proxy env variables
proxies = {}
for prot in PROTOCOLS:
if os.environ.get(prot + '_proxy'):
proxies[prot] = os.environ[prot + '_proxy']
if not proxies:
# If there were no environment variables set, do nothing
return
elif isinstance(config, dict):
proxies = config
else:
# Map all protocols to the configured proxy
proxies = dict((prot, config) for prot in PROTOCOLS)
log.verbose('Setting proxy to %s' % proxies)
feed.requests.proxies = proxies


plugin.register_plugin(Proxy, 'proxy', builtin=True, api_ver=2)

0 comments on commit 977ea3c

Please sign in to comment.