当前位置: 首页>>代码示例>>Python>>正文


Python pytrie.StringTrie类代码示例

本文整理汇总了Python中pytrie.StringTrie的典型用法代码示例。如果您正苦于以下问题:Python StringTrie类的具体用法?Python StringTrie怎么用?Python StringTrie使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了StringTrie类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_empty_tree

 def test_empty_tree(self):
     """
     Test trie ctor, and that is doesn't match on "any" prefix.
     """
     t = StringTrie()
     for key in [u'', u'f', u'foo', u'foobar']:
         with self.assertRaises(KeyError):
             t.longest_prefix_value(key)
开发者ID:FirefighterBlu3,项目名称:crossbar,代码行数:8,代码来源:test_pytrie.py

示例2: test_longest_prefix_1

 def test_longest_prefix_1(self):
     """
     Test that keys are detected as prefix of themselfes.
     """
     t = StringTrie()
     test_keys = [u'f', u'foo', u'foobar', u'baz']
     for key in test_keys:
         t[key] = key
     for key in test_keys:
         self.assertEqual(t.longest_prefix_value(key), key)
开发者ID:FirefighterBlu3,项目名称:crossbar,代码行数:10,代码来源:test_pytrie.py

示例3: test_longest_prefix_3

    def test_longest_prefix_3(self):
        """
        Test non-matching prefix lookups.
        """
        t = StringTrie()

        for key in [u'x', u'fop', u'foobar']:
            t[key] = key

        for key in [u'y', u'yfoo', u'fox', u'fooba']:
            with self.assertRaises(KeyError):
                t.longest_prefix_value(key)
开发者ID:FirefighterBlu3,项目名称:crossbar,代码行数:12,代码来源:test_pytrie.py

示例4: __init__

    def __init__(self, router, uri, permissions=None, default_permissions=None):
        """

        :param router: The router this role is defined on.
        :type router: obj
        :param uri: The URI of the role.
        :type uri: unicode
        :param permissions: A permissions configuration, e.g. a list
           of permission dicts like `{'uri': 'com.example.*', 'call': True}`
        :type permissions: list of dict
        :param default_permissions: The default permissions to apply when no other
            configured permission matches. The default permissions when not explicitly
            set is to deny all actions on all URIs!
        :type default_permissions: dict
        """
        RouterRole.__init__(self, router, uri)
        assert(permissions is None or isinstance(permissions, list))
        if permissions:
            for p in permissions:
                assert(isinstance(p, dict))
        assert(default_permissions is None or isinstance(default_permissions, dict))

        # default permissions (used when nothing else is matching)
        # note: default permissions have their matching URI and match policy set to None!
        if default_permissions:
            self._default = RouterPermissions.from_dict(default_permissions)
        else:
            self._default = RouterPermissions(None, None,
                                              call=False,
                                              register=False,
                                              publish=False,
                                              subscribe=False,
                                              disclose_caller=False,
                                              disclose_publisher=False,
                                              cache=True)

        # Trie of explicitly configured permissions
        self._permissions = StringTrie()
        self._wild_permissions = StringTrie()

        # for "wildcard" URIs, there will be a ".." in them somewhere,
        # and so we want to match on the biggest prefix
        # (i.e. everything to the left of the first "..")
        for obj in permissions or []:
            perms = RouterPermissions.from_dict(obj)
            if '..' in perms.uri:
                trunc = perms.uri[:perms.uri.index('..')]
                self._wild_permissions[trunc] = perms
            else:
                self._permissions[perms.uri] = perms
开发者ID:crossbario,项目名称:crossbar,代码行数:50,代码来源:role.py

示例5: test_longest_prefix_4

    def test_longest_prefix_4(self):
        """
        Test that a trie with an empty string as a key contained
        matches a non-empty prefix matching lookup.
        """
        self.skip = True
        # stored_key = u'x'  # this works (and of course it should!)
        stored_key = u''  # this blows up! (and it _should_ work)
        test_key = u'xyz'

        t = StringTrie()
        t[stored_key] = stored_key
        self.assertTrue(stored_key in t)
        self.assertTrue(test_key.startswith(stored_key))
        self.assertEqual(t.longest_prefix_value(test_key), stored_key)
开发者ID:FirefighterBlu3,项目名称:crossbar,代码行数:15,代码来源:test_pytrie.py

示例6: __init__

    def __init__(self, router, uri, permissions=None, default_permissions=None):
        """
        Ctor.

        :param uri: The URI of the role.
        :type uri: str
        :param permissions: A permissions configuration, e.g. a list
           of permission dicts like `{'uri': 'com.example.*', 'call': True}`
        :type permissions: list
        """
        RouterRole.__init__(self, router, uri)
        self.permissions = permissions or []

        self._urimap = StringTrie()
        self._default = default_permissions or RouterPermissions('', True, False, False, False, False)

        for p in self.permissions:
            uri = p['uri']

            if len(uri) > 0 and uri[-1] == '*':
                match_by_prefix = True
                uri = uri[:-1]
            else:
                match_by_prefix = False

            perms = RouterPermissions(uri, match_by_prefix,
                                      call=p.get('call', False),
                                      register=p.get('register', False),
                                      publish=p.get('publish', False),
                                      subscribe=p.get('subscribe', False))

            if len(uri) > 0:
                self._urimap[uri] = perms
            else:
                self._default = perms
开发者ID:RaitoBezarius,项目名称:crossbar,代码行数:35,代码来源:role.py

示例7: __init__

class FIB:
    def __init__(self):
        self.fib = StringTrie()
        self.fib["/mbandeira"] = "int1"
        self.fib["/cdrummond"] = "int2"

    def getIface(self, contentName):
        return self.fib.longest_prefix_value(contentName)
开发者ID:carlosmscabral,项目名称:ibf,代码行数:8,代码来源:routerStructures.py

示例8: __init__

 def __init__(self, router_session_factory, config, reactor):
     self._router_session_factory = router_session_factory
     self._router_factory = router_session_factory._routerFactory
     self._options = config.get(u'options', {})
     self._realm = self._options.get(u'realm', None)
     self._reactor = reactor
     self._payload_mapping = StringTrie()
     for topic, pmap in self._options.get(u'payload_mapping', {}).items():
         self._set_payload_format(topic, pmap)
开发者ID:NinjaMSP,项目名称:crossbar,代码行数:9,代码来源:wamp.py

示例9: filter_argv

def filter_argv(argv, option_strings, *blacklist):
    ptree = StringTrie({v: i for i, v in enumerate(blacklist)})
    filtered = []
    boolean_args = set(option_strings)
    i = -1
    while i + 1 < len(argv):
        i += 1
        arg = argv[i]
        has_value = arg.startswith("-") and \
            not any(arg.startswith(b) for b in boolean_args) \
            and '=' not in arg and arg != "-"
        if ptree.longest_prefix(arg, None) is None:
            filtered.append(arg)
            if has_value:
                i += 1
                filtered.append(argv[i])
        elif has_value:
            i += 1
    return filtered
开发者ID:AngryDevelopersLLC,项目名称:res-core,代码行数:19,代码来源:utils.py

示例10: __init__

        def __init__(self, default_key=None):
            """

            Create a new key ring to hold public and private keys mapped from an URI space.
            """
            assert(default_key is None or isinstance(default_key, Key) or type(default_key == six.text_type))
            self._uri_to_key = StringTrie()
            if type(default_key) == six.text_type:
                default_key = Key(originator_priv=default_key, responder_priv=default_key)
            self._default_key = default_key
开发者ID:potens1,项目名称:autobahn-python,代码行数:10,代码来源:cryptobox.py

示例11: test_longest_prefix_2

    def test_longest_prefix_2(self):
        """
        Test matching prefix lookups.
        """
        t = StringTrie()
        test_keys = [u'f', u'foo', u'foobar']
        for key in test_keys:
            t[key] = key

        test_keys = {
            u'foobarbaz': u'foobar',
            u'foobaz': u'foo',
            u'fool': u'foo',
            u'foo': u'foo',
            u'fob': u'f',
            u'fo': u'f',
            u'fx': u'f',
            u'f': u'f',
        }
        for key in test_keys:
            self.assertEqual(t.longest_prefix_value(key), test_keys[key])
开发者ID:FirefighterBlu3,项目名称:crossbar,代码行数:21,代码来源:test_pytrie.py

示例12: Suggester

class Suggester(object):
    def __init__(self):
        self.trie = None

    def update_trie(self, word_list):
        self.trie = StringTrie()
        for word in word_list:
            word = word.lower()
            self.trie[word] = word

    def search_prefix(self, prefix):
        return self.trie.values(prefix=prefix)
开发者ID:skimmilk8888,项目名称:SearchSuggestion,代码行数:12,代码来源:suggester.py

示例13: __init__

    def __init__(self, ordered=False):
        # flag indicating whether observers should be maintained in a SortedSet
        # or a regular set (unordered)
        self._ordered = ordered

        # map: URI => ExactUriObservation
        self._observations_exact = {}

        # map: URI => PrefixUriObservation
        self._observations_prefix = StringTrie()

        # map: URI => WildcardUriObservation
        self._observations_wildcard = WildcardTrieMatcher()

        # map: observation ID => UriObservation
        self._observation_id_to_observation = {}
开发者ID:abhimanyu-siwach,项目名称:crossbar,代码行数:16,代码来源:observation.py

示例14: __init__

    def __init__(self, router, uri, permissions=None, default_permissions=None):
        """

        :param router: The router this role is defined on.
        :type router: obj
        :param uri: The URI of the role.
        :type uri: unicode
        :param permissions: A permissions configuration, e.g. a list
           of permission dicts like `{'uri': 'com.example.*', 'call': True}`
        :type permissions: list of dict
        :param default_permissions: The default permissions to apply when no other
            configured permission matches. The default permissions when not explicitly
            set is to deny all actions on all URIs!
        :type default_permissions: dict
        """
        RouterRole.__init__(self, router, uri)
        assert(permissions is None or type(permissions) == list)
        if permissions:
            for p in permissions:
                assert(type(p) == dict)
        assert(default_permissions is None or type(default_permissions) == dict)

        # default permissions (used when nothing else is matching)
        # note: default permissions have their matching URI and match policy set to None!
        if default_permissions:
            self._default = RouterPermissions.from_dict(default_permissions)
        else:
            self._default = RouterPermissions(None, None,
                                              call=False,
                                              register=False,
                                              publish=False,
                                              subscribe=False,
                                              disclose_caller=False,
                                              disclose_publisher=False,
                                              cache=True)

        # Trie of explicitly configured permissions
        self._permissions = StringTrie()

        for obj in permissions or []:
            perms = RouterPermissions.from_dict(obj)
            self._permissions[perms.uri] = perms
开发者ID:schoonc,项目名称:crossbar,代码行数:42,代码来源:role.py

示例15: __init__

    def __init__(self, ordered=False):
        # flag indicating whether observers should be maintained in a SortedSet
        # or a regular set (unordered)
        self._ordered = ordered

        # map: URI => ExactUriObservation
        self._observations_exact = {}

        # map: URI => PrefixUriObservation
        self._observations_prefix = StringTrie()

        # map: URI => WildcardUriObservation
        if True:
            # use a Trie-based implementation (supposed to be faster, but
            # otherwise compatible to the naive implementation below)
            self._observations_wildcard = WildcardTrieMatcher()
        else:
            self._observations_wildcard = WildcardMatcher()

        # map: observation ID => UriObservation
        self._observation_id_to_observation = {}
开发者ID:Paranaix,项目名称:crossbar,代码行数:21,代码来源:observation.py


注:本文中的pytrie.StringTrie类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。