<s> from datetime import date <EOL> from google . appengine . ext import ndb <EOL> class LongIntegerProperty ( ndb . StringProperty ) : <EOL> def _validate ( self , value ) : <EOL> if not isinstance ( value , ( int , long ) ) : <EOL> raise TypeError ( '<STR_LIT>' % repr ( value ) ) <EOL> def _to_base_type ( self , value ) : <EOL> return str ( value ) <EOL> def _from_base_type ( self , value ) : <EOL> return long ( value ) <EOL> class BoundedLongIntegerProperty ( ndb . StringProperty ) : <EOL> def __init__ ( self , bits , ** kwds ) : <EOL> assert isinstance ( bits , int ) <EOL> assert bits > <NUM_LIT:0> and bits % <NUM_LIT:4> == <NUM_LIT:0> <EOL> super ( BoundedLongIntegerProperty , self ) . __init__ ( ** kwds ) <EOL> self . _bits = bits <EOL> def _validate ( self , value ) : <EOL> assert - ( <NUM_LIT:2> ** ( self . _bits - <NUM_LIT:1> ) ) <= value < <NUM_LIT:2> ** ( self . _bits - <NUM_LIT:1> ) <EOL> def _to_base_type ( self , value ) : <EOL> if value < <NUM_LIT:0> : <EOL> value += <NUM_LIT:2> ** self . _bits <EOL> assert <NUM_LIT:0> <= value < <NUM_LIT:2> ** self . _bits <EOL> return '<STR_LIT>' % ( self . _bits // <NUM_LIT:4> , value ) <EOL> def _from_base_type ( self , value ) : <EOL> value = int ( value , <NUM_LIT:16> ) <EOL> if value >= <NUM_LIT:2> ** ( self . _bits - <NUM_LIT:1> ) : <EOL> value -= <NUM_LIT:2> ** self . _bits <EOL> return value <EOL> class MyModel ( ndb . Model ) : <EOL> name = ndb . StringProperty ( ) <EOL> abc = LongIntegerProperty ( default = <NUM_LIT:0> ) <EOL> xyz = LongIntegerProperty ( repeated = True ) <EOL> class FuzzyDate ( object ) : <EOL> def __init__ ( self , first , last = None ) : <EOL> assert isinstance ( first , date ) <EOL> assert last is None or isinstance ( last , date ) <EOL> self . first = first <EOL> self . last = last or first <EOL> class FuzzyDateModel ( ndb . Model ) : <EOL> first = ndb . DateProperty ( ) <EOL> last = ndb . DateProperty ( ) <EOL> class FuzzyDateProperty ( ndb . StructuredProperty ) : <EOL> def __init__ ( self , ** kwds ) : <EOL> super ( FuzzyDateProperty , self ) . __init__ ( FuzzyDateModel , ** kwds ) <EOL> def _validate ( self , value ) : <EOL> assert isinstance ( value , FuzzyDate ) <EOL> def _to_base_type ( self , value ) : <EOL> return FuzzyDateModel ( first = value . first , last = value . last ) <EOL> def _from_base_type ( self , value ) : <EOL> return FuzzyDate ( value . first , value . last ) <EOL> class MaybeFuzzyDateProperty ( FuzzyDateProperty ) : <EOL> def _validate ( self , value ) : <EOL> if isinstance ( value , date ) : <EOL> return FuzzyDate ( value ) <EOL> class HistoricPerson ( ndb . Model ) : <EOL> name = ndb . StringProperty ( ) <EOL> birth = FuzzyDateProperty ( ) <EOL> death = FuzzyDateProperty ( ) <EOL> event_dates = FuzzyDateProperty ( repeated = True ) <EOL> event_names = ndb . StringProperty ( repeated = True ) </s>
