Commits

Gael Pasgrimaud committed e88ac46

remove proxy

  • Participants
  • Parent commits e3329db

Comments (0)

Files changed (3)

 """
 
 import os, shutil, sys, tempfile, urllib2
+from optparse import OptionParser
 
 tmpeggs = tempfile.mkdtemp()
 
 is_jython = sys.platform.startswith('java')
 
+# parsing arguments
+parser = OptionParser()
+parser.add_option("-v", "--version", dest="version",
+                          help="use a specific zc.buildout version")
+parser.add_option("-d", "--distribute",
+                   action="store_true", dest="distribute", default=False,
+                   help="Use Distribute rather than Setuptools.")
+
+parser.add_option("-c", None, action="store", dest="config_file",
+                   help=("Specify the path to the buildout configuration "
+                         "file to be used."))
+
+options, args = parser.parse_args()
+
+# if -c was provided, we push it back into args for buildout' main function
+if options.config_file is not None:
+    args += ['-c', options.config_file]
+
+if options.version is not None:
+    VERSION = '==%s' % options.version
+else:
+    VERSION = ''
+
+USE_DISTRIBUTE = options.distribute
+args = args + ['bootstrap']
+
+to_reload = False
 try:
     import pkg_resources
+    if not hasattr(pkg_resources, '_distribute'):
+        to_reload = True
+        raise ImportError
 except ImportError:
     ez = {}
-    exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+    if USE_DISTRIBUTE:
+        exec urllib2.urlopen('http://python-distribute.org/distribute_setup.py'
                          ).read() in ez
-    ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+        ez['use_setuptools'](to_dir=tmpeggs, download_delay=0, no_fake=True)
+    else:
+        exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+                             ).read() in ez
+        ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
 
-    import pkg_resources
+    if to_reload:
+        reload(pkg_resources)
+    else:
+        import pkg_resources
 
 if sys.platform == 'win32':
     def quote(c):
 cmd = 'from setuptools.command.easy_install import main; main()'
 ws  = pkg_resources.working_set
 
-if len(sys.argv) > 2 and sys.argv[1] == '--version':
-    VERSION = '==%s' % sys.argv[2]
-    args = sys.argv[3:] + ['bootstrap']
+if USE_DISTRIBUTE:
+    requirement = 'distribute'
 else:
-    VERSION = ''
-    args = sys.argv[1:] + ['bootstrap']
+    requirement = 'setuptools'
 
 if is_jython:
     import subprocess
            quote(tmpeggs), 'zc.buildout' + VERSION],
            env=dict(os.environ,
                PYTHONPATH=
-               ws.find(pkg_resources.Requirement.parse('setuptools')).location
+               ws.find(pkg_resources.Requirement.parse(requirement)).location
                ),
            ).wait() == 0
 
         '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout' + VERSION,
         dict(os.environ,
             PYTHONPATH=
-            ws.find(pkg_resources.Requirement.parse('setuptools')).location
+            ws.find(pkg_resources.Requirement.parse(requirement)).location
             ),
         ) == 0
 

saladedefruits/proxy.py

-# -*- coding: utf-8 -*-
-from wsgiproxy.exactproxy import proxy_exact_request
-import urlparse
-from utils import Request
-
-class Proxy(object):
-    """This is the equivalent to the deliverance Proxy. eg. you can rewrite
-    links and strip script name."""
-    def __init__(self, href, rewrite_links=False, strip_script_name=False,**kwargs):
-        self.rewrite_links = rewrite_links
-        self.strip_script_name = strip_script_name
-        self.href_scheme, self.href_netloc, self.href_path, href_query, href_fragment = urlparse.urlsplit(href, 'http')
-        if self.href_path.endswith('/'):
-            self.href_path = self.href_path.rstrip('/')
-
-    def get_response(self, req):
-        if self.strip_script_name:
-            script_name = ''
-        else:
-            script_name = req.script_name
-        new_orig_base = '%s://%s%s' % (req.environ['wsgi.url_scheme'],
-                                       req.environ['SERVER_NAME'],
-                                       script_name
-                                      )
-        req.environ['SERVER_NAME'] = req.environ['HTTP_HOST'] = self.href_netloc
-        req.path_info = self.href_path + req.path_info
-        if self.strip_script_name:
-            req.script_name = ''
-        resp = req.get_response(proxy_exact_request)
-        if resp.content_type and resp.content_type.startswith('text/html'):
-            if self.rewrite_links:
-                doc = resp.doc
-                orig_base = '%s://%s' % (req.environ['wsgi.url_scheme'], self.href_netloc)
-                def link_repl(link):
-                    if link == orig_base:
-                        return new_orig_base
-                    if link.startswith('/'):
-                        return new_orig_base + link
-                    if not link.startswith(orig_base):
-                        return link
-                    return new_orig_base + link[len(orig_base):]
-                doc[0].make_links_absolute(orig_base)
-                doc[0].rewrite_links(link_repl)
-                resp.doc = doc
-            return resp
-        return resp
-
-    def __call__(self, environ, start_response=None):
-        req = Request(environ)
-        resp = self.get_response(req)
-        return resp(environ, start_response)
-
-
-
-def make_proxy(global_config, **local_config):
-    href = local_config.pop('href')
-    return Proxy(href, **local_config)
-
           # -*- Extra requirements: -*-
           'WebOb',
           'Paste',
-          'WSGIProxy',
+          'restkit',
           'pyquery',
       ],
       entry_points="""