<s> import pytz <EOL> import dateutil . parser <EOL> import warnings <EOL> import json <EOL> from . tools import lazy_property <EOL> def _to_datetime ( value ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> d = dateutil . parser . parse ( value ) <EOL> except ValueError as e : <EOL> value , timezone = value . rsplit ( '<STR_LIT:U+0020>' , <NUM_LIT:1> ) <EOL> try : <EOL> d = dateutil . parser . parse ( value + '<STR_LIT>' ) <EOL> except ValueError : <EOL> raise e <EOL> d = d . replace ( tzinfo = pytz . timezone ( timezone ) ) <EOL> return d <EOL> def _to_bool ( data ) : <EOL> assert data in ( '<STR_LIT:true>' , '<STR_LIT:false>' ) , ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( data ) ) <EOL> return json . loads ( data ) <EOL> class ObjectMapper ( object ) : <EOL> """<STR_LIT>""" <EOL> __WHITELIST__ = [ ] <EOL> __EXPORT_FILTERS__ = { } <EOL> def __init__ ( self , data ) : <EOL> self . _ = data <EOL> def __repr__ ( self ) : <EOL> return u'<STR_LIT>' . format ( self . __class__ . __name__ , self . _ ) <EOL> def __getitem__ ( self , item ) : <EOL> return self . _ [ item ] <EOL> def __getattr__ ( self , item ) : <EOL> try : <EOL> return super ( ObjectMapper , self ) . __getattr__ ( item ) <EOL> except AttributeError : <EOL> if item . startswith ( '<STR_LIT:_>' ) : <EOL> key = item [ <NUM_LIT:1> : ] <EOL> if key not in self . __WHITELIST__ : <EOL> warnings . warn ( '<STR_LIT>' . format ( key ) ) <EOL> return self . _ [ key ] <EOL> if item in self . __EXPORT_FILTERS__ : <EOL> filter = self . __EXPORT_FILTERS__ [ item ] <EOL> return filter ( self . _ [ item ] ) <EOL> if item in self . __WHITELIST__ : <EOL> return self . _ [ item ] <EOL> return super ( ObjectMapper , self ) . __getattribute__ ( item ) <EOL> class Response ( ObjectMapper ) : <EOL> """<STR_LIT>""" <EOL> __WHITELIST__ = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> __EXPORT_FILTERS__ = { '<STR_LIT:status>' : int } <EOL> @ lazy_property <EOL> def receipt ( self ) : <EOL> return Receipt ( self . _receipt ) <EOL> @ lazy_property <EOL> def latest_receipt ( self ) : <EOL> return Receipt ( self . _latest_receipt ) <EOL> class Receipt ( ObjectMapper ) : <EOL> __WHITELIST__ = [ '<STR_LIT>' ] <EOL> __EXPORT_FILTERS__ = { } <EOL> @ lazy_property <EOL> def in_app ( self ) : <EOL> if '<STR_LIT>' in self . _ : <EOL> return list ( map ( InApp , self . _in_app ) ) <EOL> else : <EOL> return [ InApp ( self . _ ) ] <EOL> @ property <EOL> def last_in_app ( self ) : <EOL> return self . in_app [ - <NUM_LIT:1> ] <EOL> class InApp ( ObjectMapper ) : <EOL> __WHITELIST__ = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> __EXPORT_FILTERS__ = { <EOL> '<STR_LIT>' : int , <EOL> '<STR_LIT>' : _to_bool , <EOL> '<STR_LIT>' : _to_datetime , <EOL> '<STR_LIT>' : _to_datetime , <EOL> '<STR_LIT>' : _to_datetime , <EOL> '<STR_LIT>' : _to_datetime , <EOL> '<STR_LIT>' : int , <EOL> '<STR_LIT>' : int , <EOL> '<STR_LIT>' : int , <EOL> '<STR_LIT>' : int , <EOL> } </s>
