1515#
1616from typing import Optional , Tuple
1717
18- from pygridgain .datatypes import Byte , Int , Short , String
18+ from pygridgain .datatypes import Byte , ByteArrayObject , Int , MapObject , Short , String
1919from pygridgain .datatypes .internal import Struct
2020
2121OP_HANDSHAKE = 1
2222
23+ USER_ATTR_TIMEZONE = 'client.timezone'
24+
2325
2426class HandshakeRequest :
2527 """ Handshake request. """
2628 handshake_struct = None
2729 username = None
2830 password = None
2931 protocol_version = None
32+ timezone = None
3033
3134 def __init__ (
3235 self , protocol_version : Tuple [int , int , int ],
33- username : Optional [str ] = None , password : Optional [str ] = None
36+ username : Optional [str ] = None , password : Optional [str ] = None , timezone : str = None ,
3437 ):
3538 fields = [
3639 ('length' , Int ),
@@ -41,6 +44,15 @@ def __init__(
4144 ('client_code' , Byte ),
4245 ]
4346 self .protocol_version = protocol_version
47+ self .timezone = timezone
48+ if protocol_version >= (1 , 7 , 0 ):
49+ fields .extend ([
50+ ('features' , ByteArrayObject ),
51+ ])
52+ if protocol_version >= (1 , 7 , 1 ):
53+ fields .extend ([
54+ ('user_attributes' , MapObject ),
55+ ])
4456 if username and password :
4557 self .username = username
4658 self .password = password
@@ -59,6 +71,21 @@ def from_python(self, stream):
5971 'version_patch' : self .protocol_version [2 ],
6072 'client_code' : 2 , # fixed value defined by protocol
6173 }
74+ if self .protocol_version >= (1 , 7 , 0 ):
75+ handshake_data .update ({
76+ 'features' : None ,
77+ })
78+ handshake_data ['length' ] += 1
79+ if self .protocol_version >= (1 , 7 , 1 ):
80+ user_attributes = (
81+ MapObject .HASH_MAP , {
82+ USER_ATTR_TIMEZONE : self .timezone
83+ })
84+
85+ handshake_data .update ({
86+ 'user_attributes' : user_attributes ,
87+ })
88+ handshake_data ['length' ] += 6 + 5 + len (USER_ATTR_TIMEZONE ) + 5 + len (self .timezone )
6289 if self .username and self .password :
6390 handshake_data .update ({
6491 'username' : self .username ,
@@ -69,5 +96,4 @@ def from_python(self, stream):
6996 len (self .username ),
7097 len (self .password ),
7198 ])
72-
7399 self .handshake_struct .from_python (stream , handshake_data )
0 commit comments