On Wed, Mar 30, 2011 at 05:55:09PM +0200, Michael Hanselmann wrote: > The intent of this function is to be able to provide a globbing operator > or query filters. One should be able to say, for example, something to > the effect of “gnt-instance shutdown '*.site'”. > > Also rename a variable in MatchNameComponent.
LGTM. What was wrong with the name MatchObject (->mo) ? ;-) > Signed-off-by: Michael Hanselmann <[email protected]> > --- > Hopefully I got the semantics right. Please have a look at the unittest for > examples. I believe so. Not sure about a couple of them: > +class TestDnsNameGlobPattern(unittest.TestCase): > + def setUp(self): > + self.names = [ > + "node1.example.com", > + "node2-0.example.com", > + "node2-1.example.com", > + "node1.example.net", > + "web1.example.com", > + "web2.example.com", > + "sub.site.example.com", > + ] > + > + def _Test(self, pattern): > + re_pat = utils.DnsNameGlobPattern(pattern) > + > + return filter(re.compile(re_pat).match, self.names) > + > + def test(self): > + for pattern in ["xyz", "node", " ", "example.net", "x*.example.*", > + "x*.example.com"]: > + self.assertEqual(self._Test(pattern), []) > + > + for pattern in ["*", "???*"]: > + self.assertEqual(self._Test(pattern), self.names) So is '*' designed to match everything then? > + self.assertEqual(self._Test("node1.*.net"), ["node1.example.net"]) > + self.assertEqual(self._Test("*.example.net"), ["node1.example.net"]) > + self.assertEqual(self._Test("web1.example.com"), ["web1.example.com"]) > + > + for pattern in ["*.*.*.*", "???", "*.site"]: > + self.assertEqual(self._Test(pattern), ["sub.site.example.com"]) > + > + self.assertEqual(self._Test("node1"), [ > + "node1.example.com", > + "node1.example.net", > + ]) OK, this is permitted by the DNS globbing, with the idea to still be prevented by the MatchNameComponent? > + self.assertEqual(self._Test("node?*.example.*"), [ > + "node1.example.com", > + "node2-0.example.com", > + "node2-1.example.com", > + "node1.example.net", > + ]) > + self.assertEqual(self._Test("*-?"), [ > + "node2-0.example.com", > + "node2-1.example.com", > + ]) > + self.assertEqual(self._Test("node2-?.example.com"), [ > + "node2-0.example.com", > + "node2-1.example.com", > + ]) Rest look good, thanks. iustin
