<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> __all__ = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> class LayoutDimension ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , min = None , max = None , weight = <NUM_LIT:1> , preferred = None ) : <EOL> assert isinstance ( weight , int ) and weight > <NUM_LIT:0> <EOL> self . min_specified = min is not None <EOL> self . max_specified = max is not None <EOL> self . preferred_specified = preferred is not None <EOL> if min is None : <EOL> min = <NUM_LIT:0> <EOL> if max is None : <EOL> max = <NUM_LIT:1000> ** <NUM_LIT:10> <EOL> if preferred is None : <EOL> preferred = min <EOL> self . min = min <EOL> self . max = max <EOL> self . preferred = preferred <EOL> self . weight = weight <EOL> if self . preferred < self . min : <EOL> self . preferred = self . min <EOL> if self . preferred > self . max : <EOL> self . preferred = self . max <EOL> @ classmethod <EOL> def exact ( cls , amount ) : <EOL> """<STR_LIT>""" <EOL> return cls ( min = amount , max = amount , preferred = amount ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . min , self . max , self . preferred , self . weight ) <EOL> def __add__ ( self , other ) : <EOL> return sum_layout_dimensions ( [ self , other ] ) <EOL> def sum_layout_dimensions ( dimensions ) : <EOL> """<STR_LIT>""" <EOL> min = sum ( [ d . min for d in dimensions if d . min is not None ] ) <EOL> max = sum ( [ d . max for d in dimensions if d . max is not None ] ) <EOL> preferred = sum ( [ d . preferred for d in dimensions ] ) <EOL> return LayoutDimension ( min = min , max = max , preferred = preferred ) <EOL> def max_layout_dimensions ( dimensions ) : <EOL> """<STR_LIT>""" <EOL> min_ = max ( [ d . min for d in dimensions if d . min is not None ] ) <EOL> max_ = max ( [ d . max for d in dimensions if d . max is not None ] ) <EOL> preferred = max ( [ d . preferred for d in dimensions ] ) <EOL> return LayoutDimension ( min = min_ , max = max_ , preferred = preferred ) </s>
