__init__.py000064400000000441147205606360006665 0ustar00from __future__ import absolute_import, division, unicode_literals from .py import Trie as PyTrie Trie = PyTrie # pylint:disable=wrong-import-position try: from .datrie import Trie as DATrie except ImportError: pass else: Trie = DATrie # pylint:enable=wrong-import-position __init__.pyc000064400000000672147205606360007036 0ustar00 abc@`sdddlmZmZmZddlmZeZyddlmZWne k rYnXeZdS(i(tabsolute_importtdivisiontunicode_literalsi(tTrieN( t __future__RRRtpyRtPyTrietdatrietDATriet ImportError(((sG/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/__init__.pyts __init__.pyo000064400000000672147205606360007052 0ustar00 abc@`sdddlmZmZmZddlmZeZyddlmZWne k rYnXeZdS(i(tabsolute_importtdivisiontunicode_literalsi(tTrieN( t __future__RRRtpyRtPyTrietdatrietDATriet ImportError(((sG/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/__init__.pyts _base.py000064400000001723147205606360006203 0ustar00from __future__ import absolute_import, division, unicode_literals from collections import Mapping class Trie(Mapping): """Abstract base class for tries""" def keys(self, prefix=None): # pylint:disable=arguments-differ keys = super(Trie, self).keys() if prefix is None: return set(keys) # Python 2.6: no set comprehensions return set([x for x in keys if x.startswith(prefix)]) def has_keys_with_prefix(self, prefix): for key in self.keys(): if key.startswith(prefix): return True return False def longest_prefix(self, prefix): if prefix in self: return prefix for i in range(1, len(prefix) + 1): if prefix[:-i] in self: return prefix[:-i] raise KeyError(prefix) def longest_prefix_item(self, prefix): lprefix = self.longest_prefix(prefix) return (lprefix, self[lprefix]) _base.pyc000064400000003342147205606360006345 0ustar00 abc@`sFddlmZmZmZddlmZdefdYZdS(i(tabsolute_importtdivisiontunicode_literals(tMappingtTriecB`s5eZdZddZdZdZdZRS(uAbstract base class for triescC`sWtt|j}|dkr+t|Stg|D]}|j|r5|^q5S(N(tsuperRtkeystNonetsett startswith(tselftprefixRtx((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/_base.pyR s  cC`s.x'|jD]}|j|r tSq WtS(N(RR tTruetFalse(R R tkey((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/_base.pythas_keys_with_prefixscC`s^||kr|Sx;tdt|dD] }|| |kr*|| Sq*Wt|dS(Ni(trangetlentKeyError(R R ti((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/_base.pytlongest_prefixs    cC`s|j|}|||fS(N(R(R R tlprefix((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/_base.pytlongest_prefix_item$sN(t__name__t __module__t__doc__RRRRR(((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/_base.pyRs   N(t __future__RRRt collectionsRR(((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/_base.pyts_base.pyo000064400000003342147205606360006361 0ustar00 abc@`sFddlmZmZmZddlmZdefdYZdS(i(tabsolute_importtdivisiontunicode_literals(tMappingtTriecB`s5eZdZddZdZdZdZRS(uAbstract base class for triescC`sWtt|j}|dkr+t|Stg|D]}|j|r5|^q5S(N(tsuperRtkeystNonetsett startswith(tselftprefixRtx((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/_base.pyR s  cC`s.x'|jD]}|j|r tSq WtS(N(RR tTruetFalse(R R tkey((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/_base.pythas_keys_with_prefixscC`s^||kr|Sx;tdt|dD] }|| |kr*|| Sq*Wt|dS(Ni(trangetlentKeyError(R R ti((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/_base.pytlongest_prefixs    cC`s|j|}|||fS(N(R(R R tlprefix((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/_base.pytlongest_prefix_item$sN(t__name__t __module__t__doc__RRRRR(((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/_base.pyRs   N(t __future__RRRt collectionsRR(((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/_base.pytsdatrie.py000064400000002232147205606360006376 0ustar00from __future__ import absolute_import, division, unicode_literals from datrie import Trie as DATrie from pip._vendor.six import text_type from ._base import Trie as ABCTrie class Trie(ABCTrie): def __init__(self, data): chars = set() for key in data.keys(): if not isinstance(key, text_type): raise TypeError("All keys must be strings") for char in key: chars.add(char) self._data = DATrie("".join(chars)) for key, value in data.items(): self._data[key] = value def __contains__(self, key): return key in self._data def __len__(self): return len(self._data) def __iter__(self): raise NotImplementedError() def __getitem__(self, key): return self._data[key] def keys(self, prefix=None): return self._data.keys(prefix) def has_keys_with_prefix(self, prefix): return self._data.has_keys_with_prefix(prefix) def longest_prefix(self, prefix): return self._data.longest_prefix(prefix) def longest_prefix_item(self, prefix): return self._data.longest_prefix_item(prefix) datrie.pyc000064400000005333147205606360006546 0ustar00 abc@`sfddlmZmZmZddlmZddlmZddl mZ de fdYZdS(i(tabsolute_importtdivisiontunicode_literals(tTrie(t text_typeiRcB`s\eZdZdZdZdZdZd dZdZ dZ dZ RS( cC`st}xP|jD]B}t|ts:tdnx|D]}|j|qAWqWtdj||_x'|j D]\}}||j|sdatrie.pyo000064400000005333147205606360006562 0ustar00 abc@`sfddlmZmZmZddlmZddlmZddl mZ de fdYZdS(i(tabsolute_importtdivisiontunicode_literals(tTrie(t text_typeiRcB`s\eZdZdZdZdZdZd dZdZ dZ dZ RS( cC`st}xP|jD]B}t|ts:tdnx|D]}|j|qAWqWtdj||_x'|j D]\}}||j|spy.py000064400000003357147205606360005567 0ustar00from __future__ import absolute_import, division, unicode_literals from pip._vendor.six import text_type from bisect import bisect_left from ._base import Trie as ABCTrie class Trie(ABCTrie): def __init__(self, data): if not all(isinstance(x, text_type) for x in data.keys()): raise TypeError("All keys must be strings") self._data = data self._keys = sorted(data.keys()) self._cachestr = "" self._cachepoints = (0, len(data)) def __contains__(self, key): return key in self._data def __len__(self): return len(self._data) def __iter__(self): return iter(self._data) def __getitem__(self, key): return self._data[key] def keys(self, prefix=None): if prefix is None or prefix == "" or not self._keys: return set(self._keys) if prefix.startswith(self._cachestr): lo, hi = self._cachepoints start = i = bisect_left(self._keys, prefix, lo, hi) else: start = i = bisect_left(self._keys, prefix) keys = set() if start == len(self._keys): return keys while self._keys[i].startswith(prefix): keys.add(self._keys[i]) i += 1 self._cachestr = prefix self._cachepoints = (start, i) return keys def has_keys_with_prefix(self, prefix): if prefix in self._data: return True if prefix.startswith(self._cachestr): lo, hi = self._cachepoints i = bisect_left(self._keys, prefix, lo, hi) else: i = bisect_left(self._keys, prefix) if i == len(self._keys): return False return self._keys[i].startswith(prefix) py.pyc000064400000005713147205606360005730 0ustar00 abc@`sfddlmZmZmZddlmZddlmZddlm Z de fdYZ dS( i(tabsolute_importtdivisiontunicode_literals(t text_type(t bisect_lefti(tTrieRcB`sJeZdZdZdZdZdZddZdZ RS(cC`sktd|jDs+tdn||_t|j|_d|_dt|f|_dS(Ncs`s|]}t|tVqdS(N(t isinstanceR(t.0tx((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pys suAll keys must be stringsui( talltkeyst TypeErrort_datatsortedt_keyst _cachestrtlent _cachepoints(tselftdata((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pyt__init__ s   cC`s ||jkS(N(R (Rtkey((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pyt __contains__scC`s t|jS(N(RR (R((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pyt__len__scC`s t|jS(N(titerR (R((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pyt__iter__scC`s |j|S(N(R (RR((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pyt __getitem__scC`s|dks"|dks"|j r/t|jS|j|jro|j\}}t|j|||}}nt|j|}}t}|t|jkr|Sx8|j|j|r|j|j||d7}qW||_||f|_|S(Nui( tNoneRtsett startswithRRRRtadd(RtprefixtlothitstarttiR ((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pyR s"   cC`s||jkrtS|j|jrO|j\}}t|j|||}nt|j|}|t|jkrztS|j|j|S(N( R tTrueRRRRRRtFalse(RRR R!R#((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pythas_keys_with_prefix6sN( t__name__t __module__RRRRRRR R&(((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pyR s     N( t __future__RRRtpip._vendor.sixRtbisectRt_baseRtABCTrie(((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pytspy.pyo000064400000005713147205606360005744 0ustar00 abc@`sfddlmZmZmZddlmZddlmZddlm Z de fdYZ dS( i(tabsolute_importtdivisiontunicode_literals(t text_type(t bisect_lefti(tTrieRcB`sJeZdZdZdZdZdZddZdZ RS(cC`sktd|jDs+tdn||_t|j|_d|_dt|f|_dS(Ncs`s|]}t|tVqdS(N(t isinstanceR(t.0tx((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pys suAll keys must be stringsui( talltkeyst TypeErrort_datatsortedt_keyst _cachestrtlent _cachepoints(tselftdata((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pyt__init__ s   cC`s ||jkS(N(R (Rtkey((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pyt __contains__scC`s t|jS(N(RR (R((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pyt__len__scC`s t|jS(N(titerR (R((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pyt__iter__scC`s |j|S(N(R (RR((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pyt __getitem__scC`s|dks"|dks"|j r/t|jS|j|jro|j\}}t|j|||}}nt|j|}}t}|t|jkr|Sx8|j|j|r|j|j||d7}qW||_||f|_|S(Nui( tNoneRtsett startswithRRRRtadd(RtprefixtlothitstarttiR ((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pyR s"   cC`s||jkrtS|j|jrO|j\}}t|j|||}nt|j|}|t|jkrztS|j|j|S(N( R tTrueRRRRRRtFalse(RRR R!R#((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pythas_keys_with_prefix6sN( t__name__t __module__RRRRRRR R&(((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pyR s     N( t __future__RRRtpip._vendor.sixRtbisectRt_baseRtABCTrie(((sA/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_trie/py.pyts