[Python-checkins] distutils2: merged

tarek.ziade python-checkins at python.org
Fri Oct 8 22:24:51 CEST 2010


tarek.ziade pushed 16ab2f33a61a to distutils2:

http://hg.python.org/distutils2/rev/16ab2f33a61a
changeset:   759:16ab2f33a61a
tag:         tip
parent:      757:b3c21fc3d270
parent:      758:8444211ef6d1
user:        Tarek Ziade <tarek at ziade.org>
date:        Fri Oct 08 22:24:34 2010 +0200
summary:     merged
files:       

diff --git a/distutils2/index/simple.py b/distutils2/index/simple.py
--- a/distutils2/index/simple.py
+++ b/distutils2/index/simple.py
@@ -146,8 +146,12 @@
         Return a list of names.
         """
         index = self._open_url(self.index_url)
-        projectname = re.compile("""<a[^>]*>(.?[^<]*%s.?[^<]*)</a>""" % name,
-                                 flags=re.I)
+        if '*' in name:
+            name.replace('*', '.*')
+        else:
+            name = "%s%s%s" % ('*.?', name, '*.?')
+        name = name.replace('*', '[^<]*')  # avoid matching of the tag's end
+        projectname = re.compile("""<a[^>]*>(%s)</a>""" % name, flags=re.I)
         matching_projects = []
         for match in projectname.finditer(index.read()):
             project_name = match.group(1)
diff --git a/distutils2/tests/test_index_simple.py b/distutils2/tests/test_index_simple.py
--- a/distutils2/tests/test_index_simple.py
+++ b/distutils2/tests/test_index_simple.py
@@ -304,9 +304,13 @@
         # we can search the index for some projects, on their names
         # the case used no matters here
         crawler = self._get_simple_crawler(server)
-        projects = [p.name for p in crawler.search_projects("Foobar")]
-        self.assertListEqual(['FooBar-bar', 'Foobar-baz', 'Baz-FooBar'], 
-                             projects)
+        tests = (('Foobar', ['FooBar-bar', 'Foobar-baz', 'Baz-FooBar']), 
+                 ('foobar*', ['FooBar-bar', 'Foobar-baz']), 
+                 ('*foobar', ['Baz-FooBar',]))
+
+        for search, expected in tests:
+            projects = [p.name for p in crawler.search_projects(search)]
+            self.assertListEqual(expected, projects)
 
 def test_suite():
     return unittest.makeSuite(SimpleCrawlerTestCase)
diff --git a/docs/source/library/distutils2.index.simple.rst b/docs/source/library/distutils2.index.simple.rst
--- a/docs/source/library/distutils2.index.simple.rst
+++ b/docs/source/library/distutils2.index.simple.rst
@@ -124,8 +124,20 @@
 +++++++++++++++++++++++++++++
 
 It's possible to search for projects with specific names in the package index.
-Assuming you want to find all projects containing the "Grail" keyword::
+Assuming you want to find all projects containing the "pelican" keyword::
 
-    >>> client.search(name="grail")
-    ["holy grail", "unholy grail", "grail"]
+    >>> c.search_projects("distutils")
+    [<Project "collective.recipe.distutils">, <Project "Distutils">, <Project
+    "Distutils2">, <Project "distutilscross">, <Project "lpdistutils">, <Project
+    "taras.recipe.distutils">, <Project "zerokspot.recipe.distutils">]
 
+You can also search the projects starting with a specific text, or ending with
+that text, using a wildcard.::
+
+    >>> c.search_projects("distutils*")
+    [<Project "Distutils">, <Project "Distutils2">, <Project "distutilscross">]
+
+    >>> c.search_projects("*distutils")
+    [<Project "collective.recipe.distutils">, <Project "Distutils">, <Project
+    "lpdistutils">, <Project "taras.recipe.distutils">, <Project
+    "zerokspot.recipe.distutils">]

--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list