<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import re <EOL> from slimta . util import pycompat <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> message_esc_pattern = re . compile ( r'<STR_LIT>' ) <EOL> esc_pattern = re . compile ( r'<STR_LIT>' ) <EOL> code_pattern = re . compile ( r'<STR_LIT>' ) <EOL> class Reply ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , code = None , message = None , command = None , address = None ) : <EOL> self . command = command <EOL> self . address = address <EOL> self . code = code <EOL> self . enhanced_status_code = None <EOL> self . message = message <EOL> self . newline_first = False <EOL> def __eq__ ( self , other ) : <EOL> if not hasattr ( other , '<STR_LIT:code>' ) or not hasattr ( other , '<STR_LIT:message>' ) : <EOL> return NotImplemented <EOL> return self . code == other . code and self . message == other . message <EOL> def __repr__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' . format ( self . code , <EOL> self . message ) <EOL> def __str__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' . format ( self . code , self . message ) <EOL> def __bytes__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return b'<STR_LIT:U+0020>' . join ( ( self . code . encode ( '<STR_LIT:ascii>' ) , <EOL> self . message . encode ( '<STR_LIT:utf-8>' ) ) ) <EOL> def __bool__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . code is not None <EOL> if pycompat . PY2 : <EOL> __nonzero__ = __bool__ <EOL> __unicode__ = __str__ <EOL> __str__ = __bytes__ <EOL> def copy ( self , reply ) : <EOL> """<STR_LIT>""" <EOL> self . _code = reply . _code <EOL> self . _message = reply . _message <EOL> self . _esc = reply . _esc <EOL> return self <EOL> def recv ( self , io ) : <EOL> """<STR_LIT>""" <EOL> self . code , self . message = io . recv_reply ( ) <EOL> self . address = io . address <EOL> def send ( self , io , flush = False ) : <EOL> """<STR_LIT>""" <EOL> if self . newline_first : <EOL> io . buffered_send ( b'<STR_LIT:\r\n>' ) <EOL> io . send_reply ( self ) <EOL> if flush : <EOL> io . flush_send ( ) <EOL> def is_error ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . code [ <NUM_LIT:0> ] in ( '<STR_LIT:4>' , '<STR_LIT:5>' ) <EOL> @ property <EOL> def code ( self ) : <EOL> return self . _code <EOL> @ code . setter <EOL> def code ( self , value ) : <EOL> if value : <EOL> match = code_pattern . match ( value ) <EOL> if match : <EOL> self . _code = value <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' , value ) <EOL> else : <EOL> self . _code = value <EOL> @ property <EOL> def message ( self ) : <EOL> esc = self . enhanced_status_code <EOL> msg = self . _message <EOL> if esc and msg : <EOL> return '<STR_LIT:U+0020>' . join ( ( esc , msg ) ) <EOL> else : <EOL> return msg <EOL> @ message . setter <EOL> def message ( self , value ) : <EOL> if value : <EOL> match = message_esc_pattern . match ( value ) <EOL> if match : <EOL> self . _message = value [ match . end ( <NUM_LIT:0> ) : ] <EOL> self . enhanced_status_code = match . group ( <NUM_LIT:1> ) <EOL> return <EOL> self . _message = value <EOL> if self . _esc : <EOL> self . _esc = None <EOL> @ property <EOL> def enhanced_status_code ( self ) : <EOL> code_0 = self . _code and self . _code [ <NUM_LIT:0> ] <EOL> if code_0 in ( '<STR_LIT:2>' , '<STR_LIT:4>' , '<STR_LIT:5>' ) : <EOL> if self . _esc : <EOL> return '<STR_LIT:.>' . join ( ( code_0 , self . _esc [ <NUM_LIT:1> ] , self . _esc [ <NUM_LIT:2> ] ) ) <EOL> elif self . _esc is False : <EOL> return None <EOL> else : <EOL> return '<STR_LIT:.>' . join ( ( code_0 , '<STR_LIT:0>' , '<STR_LIT:0>' ) ) <EOL> @ enhanced_status_code . setter <EOL> def enhanced_status_code ( self , value ) : <EOL> if value : <EOL> match = esc_pattern . match ( value ) <EOL> if match : <EOL> self . _esc = match . groups ( ) <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' , value ) <EOL> else : <EOL> self . _esc = value <EOL> @ property <EOL> def raw_message ( self ) : <EOL> return self . _message <EOL> unknown_command = Reply ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> unknown_parameter = Reply ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> bad_sequence = Reply ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> bad_arguments = Reply ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> unhandled_error = Reply ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> tls_failure = Reply ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> connection_failed = Reply ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> timed_out = Reply ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> timed_out . newline_first = True <EOL> invalid_credentials = Reply ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) </s>
