<s> """<STR_LIT>""" <EOL> __docformat__ = '<STR_LIT>' <EOL> import humanize <EOL> from . . utils import auto_repr <EOL> _COUNTS = ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> _LISTS = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> _FORMATTERS = { <EOL> '<STR_LIT>' : humanize . naturalsize , <EOL> '<STR_LIT>' : lambda merges : "<STR_LIT:U+002CU+0020>" . join ( '<STR_LIT>' . join ( merge ) for merge in merges ) , <EOL> '<STR_LIT>' : lambda versions : '<STR_LIT:U+002CU+0020>' . join ( versions ) <EOL> } <EOL> class ActivityStats ( object ) : <EOL> """<STR_LIT>""" <EOL> __metrics__ = _COUNTS + _LISTS <EOL> __slots__ = __metrics__ + ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , ** vals ) : <EOL> self . _current = { } <EOL> self . _total = { } <EOL> self . reset ( full = True , vals = vals ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . __class__ . __name__ , <EOL> "<STR_LIT:U+002CU+0020>" . join ( [ "<STR_LIT>" % ( k , v ) for k , v in self . _current . items ( ) if v ] ) ) <EOL> def __eq__ ( self , other ) : <EOL> return ( self . _current == other . _current ) <EOL> def __ne__ ( self , other ) : <EOL> return ( self . _current != other . _current ) <EOL> def __iadd__ ( self , other ) : <EOL> for m in other . __metrics__ : <EOL> self . _current [ m ] = self . _current [ m ] + other . _current [ m ] <EOL> self . _total [ m ] = self . _total [ m ] + other . _total [ m ] <EOL> return self <EOL> def __add__ ( self , other ) : <EOL> out = ActivityStats ( ** self . _current ) <EOL> out . _total = self . _total . copy ( ) <EOL> out += other <EOL> return out <EOL> def __setattr__ ( self , key , value ) : <EOL> if key in self . __metrics__ : <EOL> self . _current [ key ] = value <EOL> else : <EOL> return super ( ActivityStats , self ) . __setattr__ ( key , value ) <EOL> def __getattribute__ ( self , key ) : <EOL> if ( not key . startswith ( '<STR_LIT:_>' ) ) and key in self . __metrics__ : <EOL> return self . _current [ key ] <EOL> else : <EOL> return super ( ActivityStats , self ) . __getattribute__ ( key ) <EOL> def _get_updated_total ( self ) : <EOL> """<STR_LIT>""" <EOL> out = self . _total . copy ( ) <EOL> for k , v in self . _current . items ( ) : <EOL> out [ k ] = out [ k ] + v <EOL> return out <EOL> def increment ( self , k , v = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> self . _current [ k ] += v <EOL> def _reset_values ( self , d , vals = { } ) : <EOL> for c in _COUNTS : <EOL> d [ c ] = vals . get ( c , <NUM_LIT:0> ) <EOL> for l in _LISTS : <EOL> d [ l ] = vals . get ( l , [ ] ) <EOL> def reset ( self , full = False , vals = { } ) : <EOL> if not full : <EOL> self . _total = self . _get_updated_total ( ) <EOL> self . _reset_values ( self . _current , vals = vals ) <EOL> if full : <EOL> self . _reset_values ( self . _total , vals = vals ) <EOL> def get_total ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __class__ ( ** self . _get_updated_total ( ) ) <EOL> def as_dict ( self ) : <EOL> return self . _current . copy ( ) <EOL> def as_str ( self , mode = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> entries = self . as_dict ( ) <EOL> entries . update ( { <EOL> k : ( _FORMATTERS [ k ] ( entries [ k ] ) if entries [ k ] else '<STR_LIT>' ) <EOL> for k in _FORMATTERS <EOL> } ) <EOL> out_formats = [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> ] <EOL> out = [ "<STR_LIT>" % s + str ( entries [ m ] ) for s , m in out_formats if entries [ m ] ] <EOL> if mode == '<STR_LIT>' : <EOL> return '<STR_LIT:\n>' . join ( out ) <EOL> elif mode == '<STR_LIT>' : <EOL> for i in range ( len ( out ) ) : <EOL> if out [ i ] [ <NUM_LIT:0> ] != '<STR_LIT:U+0020>' : <EOL> out [ i ] = '<STR_LIT:U+0020>' + out [ i ] <EOL> return '<STR_LIT:U+002C>' . join ( out ) . lstrip ( ) <EOL> return "<STR_LIT>" "<STR_LIT>" . format ( <EOL> ** entries ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" % mode ) </s>
