From 15fb3852351f1d7dd539bef32a50240712efa322 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Tue, 2 Jul 2013 17:50:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BB=A3=E7=90=86=E6=94=AF?= =?UTF-8?q?=E6=8C=81=EF=BC=88=E4=BD=BF=E7=94=A8=20pycurl=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.rst | 3 +++ get_version.py | 19 ++++++++++++++++++- sample_config.ini | 5 +++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index df3eb41..3c1190a 100644 --- a/README.rst +++ b/README.rst @@ -61,6 +61,9 @@ regex When multiple version strings are found, the maximum of those is chosen. +proxy + The HTTP proxy to use. The format is ``host:port``, e.g. ``localhost:8087``. + Find with a Command ------------------- Use a shell command line to get the version. The output is striped first, so trailing newlines do not bother. diff --git a/get_version.py b/get_version.py index d7a0b08..7319de6 100644 --- a/get_version.py +++ b/get_version.py @@ -4,6 +4,7 @@ import logging from functools import partial import queue import json +import urllib.parse from pkg_resources import parse_version from tornado.httpclient import AsyncHTTPClient @@ -13,6 +14,12 @@ from tornado.ioloop import IOLoop logger = logging.getLogger(__name__) handler_precedence = ('github', 'aur', 'cmd', 'regex') +try: + import pycurl + AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient") +except ImportError: + pycurl = None + def get_version(name, conf, callback): g = globals() for key in handler_precedence: @@ -34,9 +41,19 @@ def get_version_by_regex(name, conf, callback): encoding = conf.get('encoding', 'latin1') httpclient = AsyncHTTPClient() + + kwargs = {} + if conf.get('proxy'): + if pycurl: + host, port = urllib.parse.splitport(conf['proxy']) + kwargs['proxy_host'] = host + kwargs['proxy_port'] = int(port) + else: + logger.warn('%s: proxy set but not used because pycurl is unavailable.', name) + httpclient.fetch(conf['url'], partial( _get_version_by_regex, name, r, encoding, callback - )) + ), **kwargs) def _get_version_by_regex(name, regex, encoding, callback, res): body = res.body.decode(encoding) diff --git a/sample_config.ini b/sample_config.ini index 8eeb7bd..3339673 100644 --- a/sample_config.ini +++ b/sample_config.ini @@ -24,3 +24,8 @@ github = lilydjwg/winterpy [nvchecker] github = lilydjwg/nvchecker + +[ssed] +url = http://sed.sourceforge.net/grabbag/ssed/ +regex = The current version is ([\d.]+)\. +proxy = localhost:8087