Skip to content

Instantly share code, notes, and snippets.

@spuk-
Created April 24, 2014 14:16
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spuk-/11256147 to your computer and use it in GitHub Desktop.
Save spuk-/11256147 to your computer and use it in GitHub Desktop.
Patch for making "pip search" use proxy set via *_proxy environment variables.
--- /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
@mastier
Copy link

mastier commented Oct 7, 2014

awesome, any plans to be included in PIP ? have you sent some pull request ?

@spuk-
Copy link
Author

spuk- commented Dec 2, 2014

The issue has been closed (fixed), don't think they used specifically my patch though. I'm not used to Github, didn't figure I should have sent a pull request. :]

cya

@Bcy1
Copy link

Bcy1 commented Dec 18, 2014

Thanks for this fix. It fixed the search issue for me.

@hoomand
Copy link

hoomand commented May 18, 2015

You just saved me man, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment