예제 #1
0
 def test_case_showall(self):
     ns = root.__dict__
     tests = [
         ("a*", [
             "abbot",
             "abel",
             "active",
             "arna",
         ]),
         ("?b*.?o*", [
             "abbot.koppel",
             "abbot.loop",
             "abel.koppel",
             "abel.loop",
         ]),
         ("_a*", ["_apan"]),
         ("_*anka", [
             "__anka",
         ]),
         ("_*a*", [
             "__anka",
             "_apan",
         ]),
     ]
     for pat, res in tests:
         res.sort()
         a = wildcard.list_namespace(ns,
                                     "all",
                                     pat,
                                     ignore_case=False,
                                     show_all=True).keys()
         a.sort()
         self.assertEqual(a, res)
예제 #2
0
    def psearch(self,pattern,ns_table,ns_search=[],
                ignore_case=False,show_all=False):
        """Search namespaces with wildcards for objects.

        Arguments:

        - pattern: string containing shell-like wildcards to use in namespace
        searches and optionally a type specification to narrow the search to
        objects of that type.

        - ns_table: dict of name->namespaces for search.

        Optional arguments:
        
          - ns_search: list of namespace names to include in search.

          - ignore_case(False): make the search case-insensitive.

          - show_all(False): show all names, including those starting with
          underscores.
        """
        #print 'ps pattern:<%r>' % pattern # dbg
        
        # defaults
        type_pattern = 'all'
        filter = ''

        cmds = pattern.split()
        len_cmds  =  len(cmds)
        if len_cmds == 1:
            # Only filter pattern given
            filter = cmds[0]
        elif len_cmds == 2:
            # Both filter and type specified
            filter,type_pattern = cmds
        else:
            raise ValueError('invalid argument string for psearch: <%s>' %
                             pattern)

        # filter search namespaces
        for name in ns_search:
            if name not in ns_table:
                raise ValueError('invalid namespace <%s>. Valid names: %s' %
                                 (name,ns_table.keys()))

        #print 'type_pattern:',type_pattern # dbg
        search_result = []
        for ns_name in ns_search:
            ns = ns_table[ns_name]
            tmp_res = list(list_namespace(ns,type_pattern,filter,
                                          ignore_case=ignore_case,
                                          show_all=show_all))
            search_result.extend(tmp_res)
        search_result.sort()

        page('\n'.join(search_result))
예제 #3
0
 def test_nocase_showall(self):
     ns=root.__dict__
     tests=[
      ("a*",     ["abbot","abel","ABEL","active","arna",]),
      ("?b*.?o*",["abbot.koppel","abbot.loop","abel.koppel","abel.loop","ABEL.koppel","ABEL.loop",]),
      ("_a*",    ["_apan","_APAN"]),
      ("_*anka", ["__anka","__ANKA",]),
      ("_*a*",   ["__anka","__ANKA","_apan","_APAN"]),
     ]
     for pat,res in tests:
         res.sort()
         a=wildcard.list_namespace(ns,"all",pat,ignore_case=True,show_all=True).keys()
         a.sort()
         self.assertEqual(a,res)
예제 #4
0
 def test_case(self):
     ns=root.__dict__
     tests=[
      ("a*",     ["abbot","abel","active","arna",]),
      ("?b*.?o*",["abbot.koppel","abbot.loop","abel.koppel","abel.loop",]),
      ("_a*",    []),
      ("_*anka", ["__anka",]),
      ("_*a*",   ["__anka",]),
     ]
     for pat,res in tests:
         res.sort()
         a=wildcard.list_namespace(ns,"all",pat,ignore_case=False,show_all=False).keys()
         a.sort()
         self.assertEqual(a,res)