Created
April 24, 2014 14:16
-
-
Save spuk-/11256147 to your computer and use it in GitHub Desktop.
Patch for making "pip search" use proxy set via *_proxy environment variables.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- /usr/lib/python2.6/site-packages/pip/commands/search.py.orig 2014-04-24 10:31:14.551357257 -0300 | |
+++ /usr/lib/python2.6/site-packages/pip/commands/search.py 2014-04-24 10:57:17.522362125 -0300 | |
@@ -1,5 +1,6 @@ | |
import sys | |
import textwrap | |
+import urllib2 | |
import pip.download | |
@@ -12,6 +13,22 @@ | |
from pip._vendor import pkg_resources | |
from distutils.version import StrictVersion, LooseVersion | |
+def xmlrpclib_ServerProxy(index_url): | |
+ p = Urllib2Transport() | |
+ return xmlrpclib.ServerProxy(index_url, transport=p) | |
+ | |
+ | |
+class Urllib2Transport(xmlrpclib.Transport): | |
+ SCHEME = 'https' | |
+ def request(self, host, handler, request_body, verbose=0): | |
+ self.verbose = 0 | |
+ scheme = self.SCHEME | |
+ url = '%(scheme)s://%(host)s%(handler)s' % locals() | |
+ req = urllib2.Request(url, data=request_body, | |
+ headers={'Content-Type':'text/xml'}) | |
+ fp = urllib2.urlopen(req) | |
+ return self.parse_response(fp) | |
+ | |
class SearchCommand(Command): | |
"""Search for PyPI packages whose name or summary contains <query>.""" | |
@@ -50,7 +67,7 @@ | |
return NO_MATCHES_FOUND | |
def search(self, query, index_url): | |
- pypi = xmlrpclib.ServerProxy(index_url) | |
+ pypi = xmlrpclib_ServerProxy(index_url) | |
hits = pypi.search({'name': query, 'summary': query}, 'or') | |
return hits | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You just saved me man, thanks!