<s> from __future__ import absolute_import , division , unicode_literals <EOL> from datrie import Trie as DATrie <EOL> from pip . _vendor . six import text_type <EOL> from . _base import Trie as ABCTrie <EOL> class Trie ( ABCTrie ) : <EOL> def __init__ ( self , data ) : <EOL> chars = set ( ) <EOL> for key in data . keys ( ) : <EOL> if not isinstance ( key , text_type ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> for char in key : <EOL> chars . add ( char ) <EOL> self . _data = DATrie ( "<STR_LIT>" . join ( chars ) ) <EOL> for key , value in data . items ( ) : <EOL> self . _data [ key ] = value <EOL> def __contains__ ( self , key ) : <EOL> return key in self . _data <EOL> def __len__ ( self ) : <EOL> return len ( self . _data ) <EOL> def __iter__ ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def __getitem__ ( self , key ) : <EOL> return self . _data [ key ] <EOL> def keys ( self , prefix = None ) : <EOL> return self . _data . keys ( prefix ) <EOL> def has_keys_with_prefix ( self , prefix ) : <EOL> return self . _data . has_keys_with_prefix ( prefix ) <EOL> def longest_prefix ( self , prefix ) : <EOL> return self . _data . longest_prefix ( prefix ) <EOL> def longest_prefix_item ( self , prefix ) : <EOL> return self . _data . longest_prefix_item ( prefix ) </s>
