<s> __author__ = '<STR_LIT>' <EOL> from . . exceptions import PyOrientBadMethodCallException <EOL> from . base import BaseMessage <EOL> from . . constants import CONNECT_OP , FIELD_BYTE , FIELD_INT , FIELD_SHORT , FIELD_STRINGS , FIELD_BOOLEAN , FIELD_STRING , NAME , SUPPORTED_PROTOCOL , VERSION , SHUTDOWN_OP <EOL> from . . utils import need_connected <EOL> from . . serializations import OrientSerialization <EOL> class ConnectMessage ( BaseMessage ) : <EOL> def __init__ ( self , _orient_socket ) : <EOL> super ( ConnectMessage , self ) . __init__ ( _orient_socket ) <EOL> self . _user = '<STR_LIT>' <EOL> self . _pass = '<STR_LIT>' <EOL> self . _client_id = '<STR_LIT>' <EOL> self . _serialization_type = OrientSerialization . CSV <EOL> self . _need_token = False <EOL> self . _append ( ( FIELD_BYTE , CONNECT_OP ) ) <EOL> def prepare ( self , params = None ) : <EOL> if isinstance ( params , tuple ) or isinstance ( params , list ) : <EOL> try : <EOL> self . _user = params [ <NUM_LIT:0> ] <EOL> self . _pass = params [ <NUM_LIT:1> ] <EOL> self . _client_id = params [ <NUM_LIT:2> ] <EOL> except IndexError : <EOL> pass <EOL> self . _append ( ( FIELD_STRINGS , [ NAME , VERSION ] ) ) <EOL> self . _append ( ( FIELD_SHORT , SUPPORTED_PROTOCOL ) ) <EOL> self . _append ( ( FIELD_STRING , self . _client_id ) ) <EOL> self . _orientSocket . serialization_type = self . _serialization_type <EOL> if self . get_protocol ( ) > <NUM_LIT> : <EOL> self . _append ( ( FIELD_STRING , self . _serialization_type ) ) <EOL> if self . get_protocol ( ) > <NUM_LIT> : <EOL> self . _append ( ( FIELD_BOOLEAN , self . _request_token ) ) <EOL> self . _append ( ( FIELD_STRING , self . _user ) ) <EOL> self . _append ( ( FIELD_STRING , self . _pass ) ) <EOL> return super ( ConnectMessage , self ) . prepare ( ) <EOL> def fetch_response ( self ) : <EOL> self . _append ( FIELD_INT ) <EOL> if self . get_protocol ( ) > <NUM_LIT> : <EOL> self . _append ( FIELD_STRING ) <EOL> result = super ( ConnectMessage , self ) . fetch_response ( ) <EOL> self . _session_id = result [ <NUM_LIT:0> ] <EOL> self . _update_socket_id ( ) <EOL> if self . get_protocol ( ) > <NUM_LIT> : <EOL> if result [ <NUM_LIT:1> ] is None : <EOL> self . set_session_token ( False ) <EOL> self . _auth_token = result [ <NUM_LIT:1> ] <EOL> self . _update_socket_token ( ) <EOL> return self . _session_id <EOL> def set_user ( self , _user ) : <EOL> self . _user = _user <EOL> return self <EOL> def set_pass ( self , _pass ) : <EOL> self . _pass = _pass <EOL> return self <EOL> def set_client_id ( self , _cid ) : <EOL> self . _client_id = _cid <EOL> return self <EOL> class ShutdownMessage ( BaseMessage ) : <EOL> def __init__ ( self , _orient_socket ) : <EOL> super ( ShutdownMessage , self ) . __init__ ( _orient_socket ) <EOL> self . _user = '<STR_LIT>' <EOL> self . _pass = '<STR_LIT>' <EOL> self . _append ( ( FIELD_BYTE , SHUTDOWN_OP ) ) <EOL> @ need_connected <EOL> def prepare ( self , params = None ) : <EOL> if isinstance ( params , tuple ) or isinstance ( params , list ) : <EOL> try : <EOL> self . _user = params [ <NUM_LIT:0> ] <EOL> self . _pass = params [ <NUM_LIT:1> ] <EOL> except IndexError : <EOL> pass <EOL> self . _append ( ( FIELD_STRINGS , [ self . _user , self . _pass ] ) ) <EOL> return super ( ShutdownMessage , self ) . prepare ( ) <EOL> def fetch_response ( self ) : <EOL> return super ( ShutdownMessage , self ) . fetch_response ( ) <EOL> def set_user ( self , _user ) : <EOL> self . _user = _user <EOL> return self <EOL> def set_pass ( self , _pass ) : <EOL> self . _pass = _pass <EOL> return self </s>
