<s> import os <EOL> from lazy import LazyMixin <EOL> import blob <EOL> class Tree ( LazyMixin ) : <EOL> def __init__ ( self , repo , id , mode = None , name = None ) : <EOL> LazyMixin . __init__ ( self ) <EOL> self . repo = repo <EOL> self . id = id <EOL> self . mode = mode <EOL> self . name = name <EOL> self . _contents = None <EOL> def __bake__ ( self ) : <EOL> treeish = self . id <EOL> if not treeish . endswith ( '<STR_LIT::>' ) : <EOL> treeish = treeish + '<STR_LIT::>' <EOL> self . _contents = { } <EOL> for line in self . repo . git . ls_tree ( self . id ) . splitlines ( ) : <EOL> obj = self . content_from_string ( self . repo , line ) <EOL> if obj is not None : <EOL> self . _contents [ obj . name ] = obj <EOL> @ staticmethod <EOL> def content_from_string ( repo , text ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> mode , typ , id , name = text . expandtabs ( <NUM_LIT:1> ) . split ( "<STR_LIT:U+0020>" , <NUM_LIT:3> ) <EOL> except : <EOL> return None <EOL> if typ == "<STR_LIT>" : <EOL> return Tree ( repo , id = id , mode = mode , name = name ) <EOL> elif typ == "<STR_LIT>" : <EOL> return blob . Blob ( repo , id = id , mode = mode , name = name ) <EOL> elif typ == "<STR_LIT>" : <EOL> return None <EOL> else : <EOL> raise ( TypeError , "<STR_LIT>" % typ ) <EOL> def __div__ ( self , file ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( file ) <EOL> @ property <EOL> def basename ( self ) : <EOL> os . path . basename ( self . name ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . id <EOL> def __getitem__ ( self , key ) : <EOL> return self . _contents [ key ] <EOL> def __iter__ ( self ) : <EOL> return iter ( self . _contents ) <EOL> def __len__ ( self ) : <EOL> return len ( self . _contents ) <EOL> def __contains__ ( self , key ) : <EOL> return key in self . _contents <EOL> def get ( self , key ) : <EOL> return self . _contents . get ( key ) <EOL> def items ( self ) : <EOL> return self . _contents . items ( ) <EOL> def keys ( self ) : <EOL> return self . _contents . keys ( ) <EOL> def values ( self ) : <EOL> return self . _contents . values ( ) </s>
