<s> from copy import copy <EOL> from datetime import datetime <EOL> from . base import MessageBase <EOL> from . outgoing import OutgoingMessage <EOL> from . error import ErrorMessage <EOL> class IncomingMessage ( MessageBase ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , connection , text , received_at = None , sent_at = None ) : <EOL> MessageBase . __init__ ( self , connection , text ) <EOL> self . sent_at = sent_at <EOL> self . received_at = received_at or datetime . now ( ) <EOL> self . responses = [ ] <EOL> self . _raw_text = copy ( self . text ) <EOL> self . processed = False <EOL> self . _handled = False <EOL> @ property <EOL> def raw_text ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _raw_text <EOL> @ property <EOL> def date ( self ) : <EOL> return self . received_at <EOL> def __get_handled ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _handled or len ( self . responses ) > <NUM_LIT:0> <EOL> def __set_handled ( self , val ) : <EOL> self . _handled = val <EOL> handled = property ( __get_handled , __set_handled ) <EOL> def flush_responses ( self ) : <EOL> """<STR_LIT>""" <EOL> while self . responses : <EOL> self . responses . pop ( <NUM_LIT:0> ) . send ( ) <EOL> def respond ( self , template = None , cls = OutgoingMessage , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> msg = cls ( self . connection , template , ** kwargs ) <EOL> self . responses . append ( msg ) <EOL> return msg <EOL> def error ( self , text , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . respond ( text , ErrorMessage , ** kwargs ) </s>
