[Checkins] SVN: zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/ won't block urls if they are local (file://*)

Tarek Ziade ziade.tarek at gmail.com
Mon Apr 7 09:28:25 EDT 2008


Log message for revision 85147:
  won't block urls if they are local (file://*)

Changed:
  U   zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/allowhosts.txt
  U   zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/easy_install.py

-=-
Modified: zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/allowhosts.txt
===================================================================
--- zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/allowhosts.txt	2008-04-07 13:25:56 UTC (rev 85146)
+++ zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/allowhosts.txt	2008-04-07 13:28:25 UTC (rev 85147)
@@ -58,24 +58,48 @@
 Now we can run the buildout and make sure all attempts to dist.plone.org fails::
 
     >>> print system(buildout)
+    Develop: '/sample-buildout/allowdemo'
+    Installing eggs.
     <BLANKLINE>
-    Link to file://.../setuptools/ ***BLOCKED*** by --allow-hosts
+    Link to http://dist.plone.org ***BLOCKED*** by --allow-hosts
     <BLANKLINE>
+    Couldn't find index page for 'kss.core' (maybe misspelled?)
+    Getting distribution for 'kss.core'.
+    While:
+      Installing eggs.
+      Getting distribution for 'kss.core'.
+    Error: Couldn't find a distribution for 'kss.core'.
     <BLANKLINE>
-    Link to file://.../ ***BLOCKED*** by --allow-hosts
-    <BLANKLINE>
+
+That's what we wanted : this will prevent any attempt to access
+unwanted domains. For instance, some packages are listing in their
+links `svn://` links. These can lead to error in some cases, and
+can therefore be protected like this::
+
+XXX (showcase with a svn:// file)
+
+    >>> write(sample_buildout, 'buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... develop = allowdemo
+    ... parts = eggs
+    ... allow-hosts =
+    ...     ^(!svn://).*
+    ...
+    ... [eggs]
+    ... recipe = zc.recipe.egg:eggs
+    ... eggs = allowdemo
+    ... ''')
+
+Now we can run the buildout and make sure all attempts to dist.plone.org fails::
+
+    >>> print system(buildout)
     Develop: '/sample-buildout/allowdemo'
     Installing eggs.
     <BLANKLINE>
     Link to http://dist.plone.org ***BLOCKED*** by --allow-hosts
     <BLANKLINE>
-    <BLANKLINE>
-    Link to file://.../kss.core/ ***BLOCKED*** by --allow-hosts
-    <BLANKLINE>
     Couldn't find index page for 'kss.core' (maybe misspelled?)
-    <BLANKLINE>
-    Link to file://.../ ***BLOCKED*** by --allow-hosts
-    <BLANKLINE>
     Getting distribution for 'kss.core'.
     While:
       Installing eggs.
@@ -83,3 +107,4 @@
     Error: Couldn't find a distribution for 'kss.core'.
     <BLANKLINE>
 
+

Modified: zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/easy_install.py
===================================================================
--- zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/easy_install.py	2008-04-07 13:25:56 UTC (rev 85146)
+++ zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/easy_install.py	2008-04-07 13:28:25 UTC (rev 85147)
@@ -71,6 +71,19 @@
         _versions[executable] = version
         return version
 
+FILE_SCHEME = re.compile('file://', re.I).match
+
+class AllowHostsPackageIndex(setuptools.package_index.PackageIndex):
+    """Will allow urls that are local to the system.
+
+    No matter what is allow_hosts.
+    """
+    def url_ok(self, url, fatal=False):
+        if FILE_SCHEME(url):
+            return True
+        return setuptools.package_index.PackageIndex.url_ok(self, url, False)
+        
+
 _indexes = {}
 def _get_index(executable, index_url, find_links, allow_hosts=('*',)):
     key = executable, index_url, tuple(find_links)
@@ -80,11 +93,10 @@
 
     if index_url is None:
         index_url = default_index_url
-    index = setuptools.package_index.PackageIndex(
+    index = AllowHostsPackageIndex(
         index_url, hosts=allow_hosts, python=_get_version(executable)
         )
         
-    index._l = allow_hosts
     if find_links:
         index.add_find_links(find_links)
 



More information about the Checkins mailing list