Added http proxy support.

This commit is contained in:
Jeremy Fincher 2004-07-20 08:41:25 +00:00
parent 2b506b2fc7
commit 3b74c01463
2 changed files with 21 additions and 3 deletions

View File

@ -115,7 +115,6 @@ def registerUserValue(group, name, value):
value.supplyDefault = True value.supplyDefault = True
group.register(name, value) group.register(name, value)
class ValidNick(registry.String): class ValidNick(registry.String):
"""Value must be a valid IRC nick.""" """Value must be a valid IRC nick."""
def setValue(self, v): def setValue(self, v):
@ -167,7 +166,6 @@ def registerNetwork(name, password='', server=''):
for (name, s) in registry._cache.iteritems(): for (name, s) in registry._cache.iteritems():
if name.startswith('supybot.networks.'): if name.startswith('supybot.networks.'):
parts = name.split('.') parts = name.split('.')
print parts
name = parts[2] name = parts[2]
if name != 'default': if name != 'default':
registerNetwork(name) registerNetwork(name)
@ -395,6 +393,7 @@ registerChannelValue(supybot.replies, 'incorrectAuthentication',
tries to use a command that requires being identified or having a password tries to use a command that requires being identified or having a password
and neither credential is correct.""")) and neither credential is correct."""))
# XXX: This should eventually check that there's one and only one %s here.
registerChannelValue(supybot.replies, 'noUser', registerChannelValue(supybot.replies, 'noUser',
registry.NormalizedString("""I can't find %s in my user registry.NormalizedString("""I can't find %s in my user
database. If you didn't give a user name, then I might not know what your database. If you didn't give a user name, then I might not know what your
@ -548,7 +547,14 @@ def isNick(s, strictRfc=None):
return originalIsNick(s, strictRfc=strictRfc) return originalIsNick(s, strictRfc=strictRfc)
ircutils.isNick = isNick ircutils.isNick = isNick
###
# supybot.protocols
###
registerGroup(supybot, 'protocols') registerGroup(supybot, 'protocols')
###
# supybot.protocols.irc
###
registerGroup(supybot.protocols, 'irc') registerGroup(supybot.protocols, 'irc')
registerGlobalValue(supybot.protocols.irc, 'strictRfc', registerGlobalValue(supybot.protocols.irc, 'strictRfc',
registry.Boolean(False, """Determines whether the bot will strictly follow registry.Boolean(False, """Determines whether the bot will strictly follow
@ -573,10 +579,14 @@ registerGlobalValue(supybot.protocols.irc, 'ping',
earlier when it breaks. Really, this option only exists for debugging earlier when it breaks. Really, this option only exists for debugging
purposes: you always should make it True unless you're testing some strange purposes: you always should make it True unless you're testing some strange
server issues.""")) server issues."""))
registerGlobalValue(supybot.protocols.irc.ping, 'interval', registerGlobalValue(supybot.protocols.irc.ping, 'interval',
registry.Integer(120, """Determines the number of seconds between sending registry.Integer(120, """Determines the number of seconds between sending
pings to the server, if pings are being sent to the server.""")) pings to the server, if pings are being sent to the server."""))
###
# supybot.protocols.http
###
registerGroup(supybot.protocols, 'http') registerGroup(supybot.protocols, 'http')
registerGlobalValue(supybot.protocols.http, 'peekSize', registerGlobalValue(supybot.protocols.http, 'peekSize',
registry.PositiveInteger(4096, """Determines how many bytes the bot will registry.PositiveInteger(4096, """Determines how many bytes the bot will
@ -584,6 +594,10 @@ registerGlobalValue(supybot.protocols.http, 'peekSize',
similar. It'll give up after it reads this many bytes, even if it hasn't similar. It'll give up after it reads this many bytes, even if it hasn't
found what it was looking for.""")) found what it was looking for."""))
registerGlobalValue(supybot.protocols.http, 'proxy',
registry.String('', """Determines what proxy all HTTP requests should go
through."""))
### ###
# Especially boring stuff. # Especially boring stuff.

View File

@ -70,7 +70,11 @@ def strError(e):
def getUrlFd(url): def getUrlFd(url):
"""Gets a file-like object for a url.""" """Gets a file-like object for a url."""
try: try:
fd = urllib2.urlopen(url) request = urllib2.Request(url)
httpProxy = conf.supybot.protocols.http.proxy()
if httpProxy:
request.set_proxy(httpProxy, 'http')
fd = urllib2.urlopen(request)
return fd return fd
except socket.timeout, e: except socket.timeout, e:
raise WebError, TIMED_OUT raise WebError, TIMED_OUT