Module lexapi.lextypes
Type classes for the protobuf interface IdentityTookit uses
Expand source code
"""
Type classes for the protobuf interface IdentityTookit uses
"""
from dataclasses import dataclass
from pure_protobuf.dataclasses_ import field, message
from pure_protobuf.types import int32
@message
@dataclass
class SendVerificationCodeRequest:
phone_number: str = field(1, default='')
@message
@dataclass
class SendVerificationCodeResponse:
session_info: str = field(1, default='')
@message
@dataclass
class VerifyPhoneNumberRequest:
session_info: str = field(1, default='')
verify_code: str = field(3, default='')
@message
@dataclass
class VerifyPhoneNumberResponse:
id_token: str = field(1, default='')
refresh_token: str = field(2, default='')
expires_in: int32 = field(3, default=int32(0))
user_id: str = field(4, default='')
is_new_user: int32 = field(5, default=int32(0))
phone_number: str = field(9, default='')
@message
@dataclass
class RefreshTokenRequest:
grant_type: str = field(1, default='refresh_token')
refresh_token: str = field(3, default='')
@message
@dataclass
class RefreshTokenResponse:
access_token: str = field(1, default='')
expires_in: int32 = field(2, default='')
token_type: str = field(3, default='')
refresh_token: str = field(4, default='')
id_token: str = field(5, default='')
user_id: str = field(6, default='')
project_id: int32 = field(7, default='')
class TestTypes():
# the lengths here are encoded in the byte strings. I don't care enough
# to pull them out because it's not supposed to be an exhaustive test,
# just a litmus test
phone_number = '+000000000000'
verify_code = '000000'
session_info = 'A' * 247
id_token = 'A' * 893
unknown = 'A' * 226
user_id = 'A' * 28
expires_in = 3600
is_new_user = 0
@classmethod
def dotest(self):
"""Test the above functions"""
test = SendVerificationCodeRequest(self.phone_number).dumps()
expected = b'\n\r' + self.phone_number.encode()
assert test == expected
test = SendVerificationCodeResponse(self.session_info).dumps()
expected = b'\n\xf7\x01' + self.session_info.encode()
assert test == expected
test = VerifyPhoneNumberRequest(
session_info=self.session_info,
verify_code=self.verify_code
).dumps()
expected = b'\n\xf7\x01' + self.session_info.encode() \
+ b'\x1a\x06' + self.verify_code.encode()
assert test == expected
test = VerifyPhoneNumberResponse(
id_token=self.id_token,
unknown=self.unknown,
expires_in=self.expires_in,
user_id=self.user_id,
is_new_user=self.is_new_user,
phone_number=self.phone_number
).dumps()
expected = b'\n\xfd\x06' + self.id_token.encode() \
+ b'\x12\xe2\x01' + self.unknown.encode() \
+ b'\x18\x90\x1c"\x1c' + self.user_id.encode() \
+ b'(\x00J\r' + self.phone_number.encode()
assert test == expected
Classes
class RefreshTokenRequest (grant_type: str = 'refresh_token', refresh_token: str = '')
-
RefreshTokenRequest(grant_type: str = 'refresh_token', refresh_token: str = '')
Expand source code
class RefreshTokenRequest: grant_type: str = field(1, default='refresh_token') refresh_token: str = field(3, default='')
Class variables
var grant_type : str
var refresh_token : str
var serializer
var type_url
Static methods
def load(io: Union[BinaryIO, _io.BytesIO]) ‑> ~T
-
Deserializes a message from a file-like object.
Expand source code
def load(cls: Type[T], io: IO) -> T: """ Deserializes a message from a file-like object. """ return cls.serializer.load(io)
def loads(bytes_: bytes) ‑> ~T
-
Deserializes a message from a byte string.
Expand source code
def loads(cls: Type[T], bytes_: bytes) -> T: """ Deserializes a message from a byte string. """ with BytesIO(bytes_) as io: return load(cls, io)
Methods
def dump(self, io: Union[BinaryIO, _io.BytesIO])
-
Serializes a message into a file-like object.
Expand source code
def dump(self, io: IO): """ Serializes a message into a file-like object. """ self.validate() self.serializer.dump(self, io)
def dumps(self) ‑> bytes
-
Serializes a message into a byte string.
Expand source code
def dumps(self) -> bytes: """ Serializes a message into a byte string. """ with BytesIO() as io: self.dump(io) return io.getvalue()
def merge_from(self: ~T, other: ~T)
-
Merge another message into the current one, as if with the
Message::MergeFrom
method.Expand source code
def merge_from(self: T, other: T): """ Merge another message into the current one, as if with the ``Message::MergeFrom`` method. """ for field_ in self.__protobuf_fields__.values(): # type: Field setattr(self, field_.name, field_.merge( getattr(self, field_.name), getattr(other, field_.name), ))
def validate(self)
-
Expand source code
def validate(self): self.serializer.validate(self)
class RefreshTokenResponse (access_token: str = '', expires_in:
.new_type at 0x7f853d6035e0> = '', token_type: str = '', refresh_token: str = '', id_token: str = '', user_id: str = '', project_id: .new_type at 0x7f853d6035e0> = '') -
RefreshTokenResponse(access_token: str = '', expires_in:
.new_type at 0x7f853d6035e0> = '', token_type: str = '', refresh_token: str = '', id_token: str = '', user_id: str = '', project_id: .new_type at 0x7f853d6035e0> = '') Expand source code
class RefreshTokenResponse: access_token: str = field(1, default='') expires_in: int32 = field(2, default='') token_type: str = field(3, default='') refresh_token: str = field(4, default='') id_token: str = field(5, default='') user_id: str = field(6, default='') project_id: int32 = field(7, default='')
Class variables
var access_token : str
var expires_in :
.new_type at 0x7f853d6035e0> var id_token : str
var project_id :
.new_type at 0x7f853d6035e0> var refresh_token : str
var serializer
var token_type : str
var type_url
var user_id : str
Static methods
def load(io: Union[BinaryIO, _io.BytesIO]) ‑> ~T
-
Deserializes a message from a file-like object.
Expand source code
def load(cls: Type[T], io: IO) -> T: """ Deserializes a message from a file-like object. """ return cls.serializer.load(io)
def loads(bytes_: bytes) ‑> ~T
-
Deserializes a message from a byte string.
Expand source code
def loads(cls: Type[T], bytes_: bytes) -> T: """ Deserializes a message from a byte string. """ with BytesIO(bytes_) as io: return load(cls, io)
Methods
def dump(self, io: Union[BinaryIO, _io.BytesIO])
-
Serializes a message into a file-like object.
Expand source code
def dump(self, io: IO): """ Serializes a message into a file-like object. """ self.validate() self.serializer.dump(self, io)
def dumps(self) ‑> bytes
-
Serializes a message into a byte string.
Expand source code
def dumps(self) -> bytes: """ Serializes a message into a byte string. """ with BytesIO() as io: self.dump(io) return io.getvalue()
def merge_from(self: ~T, other: ~T)
-
Merge another message into the current one, as if with the
Message::MergeFrom
method.Expand source code
def merge_from(self: T, other: T): """ Merge another message into the current one, as if with the ``Message::MergeFrom`` method. """ for field_ in self.__protobuf_fields__.values(): # type: Field setattr(self, field_.name, field_.merge( getattr(self, field_.name), getattr(other, field_.name), ))
def validate(self)
-
Expand source code
def validate(self): self.serializer.validate(self)
class SendVerificationCodeRequest (phone_number: str = '')
-
SendVerificationCodeRequest(phone_number: str = '')
Expand source code
class SendVerificationCodeRequest: phone_number: str = field(1, default='')
Class variables
var phone_number : str
var serializer
var type_url
Static methods
def load(io: Union[BinaryIO, _io.BytesIO]) ‑> ~T
-
Deserializes a message from a file-like object.
Expand source code
def load(cls: Type[T], io: IO) -> T: """ Deserializes a message from a file-like object. """ return cls.serializer.load(io)
def loads(bytes_: bytes) ‑> ~T
-
Deserializes a message from a byte string.
Expand source code
def loads(cls: Type[T], bytes_: bytes) -> T: """ Deserializes a message from a byte string. """ with BytesIO(bytes_) as io: return load(cls, io)
Methods
def dump(self, io: Union[BinaryIO, _io.BytesIO])
-
Serializes a message into a file-like object.
Expand source code
def dump(self, io: IO): """ Serializes a message into a file-like object. """ self.validate() self.serializer.dump(self, io)
def dumps(self) ‑> bytes
-
Serializes a message into a byte string.
Expand source code
def dumps(self) -> bytes: """ Serializes a message into a byte string. """ with BytesIO() as io: self.dump(io) return io.getvalue()
def merge_from(self: ~T, other: ~T)
-
Merge another message into the current one, as if with the
Message::MergeFrom
method.Expand source code
def merge_from(self: T, other: T): """ Merge another message into the current one, as if with the ``Message::MergeFrom`` method. """ for field_ in self.__protobuf_fields__.values(): # type: Field setattr(self, field_.name, field_.merge( getattr(self, field_.name), getattr(other, field_.name), ))
def validate(self)
-
Expand source code
def validate(self): self.serializer.validate(self)
class SendVerificationCodeResponse (session_info: str = '')
-
SendVerificationCodeResponse(session_info: str = '')
Expand source code
class SendVerificationCodeResponse: session_info: str = field(1, default='')
Class variables
var serializer
var session_info : str
var type_url
Static methods
def load(io: Union[BinaryIO, _io.BytesIO]) ‑> ~T
-
Deserializes a message from a file-like object.
Expand source code
def load(cls: Type[T], io: IO) -> T: """ Deserializes a message from a file-like object. """ return cls.serializer.load(io)
def loads(bytes_: bytes) ‑> ~T
-
Deserializes a message from a byte string.
Expand source code
def loads(cls: Type[T], bytes_: bytes) -> T: """ Deserializes a message from a byte string. """ with BytesIO(bytes_) as io: return load(cls, io)
Methods
def dump(self, io: Union[BinaryIO, _io.BytesIO])
-
Serializes a message into a file-like object.
Expand source code
def dump(self, io: IO): """ Serializes a message into a file-like object. """ self.validate() self.serializer.dump(self, io)
def dumps(self) ‑> bytes
-
Serializes a message into a byte string.
Expand source code
def dumps(self) -> bytes: """ Serializes a message into a byte string. """ with BytesIO() as io: self.dump(io) return io.getvalue()
def merge_from(self: ~T, other: ~T)
-
Merge another message into the current one, as if with the
Message::MergeFrom
method.Expand source code
def merge_from(self: T, other: T): """ Merge another message into the current one, as if with the ``Message::MergeFrom`` method. """ for field_ in self.__protobuf_fields__.values(): # type: Field setattr(self, field_.name, field_.merge( getattr(self, field_.name), getattr(other, field_.name), ))
def validate(self)
-
Expand source code
def validate(self): self.serializer.validate(self)
class TestTypes
-
Expand source code
class TestTypes(): # the lengths here are encoded in the byte strings. I don't care enough # to pull them out because it's not supposed to be an exhaustive test, # just a litmus test phone_number = '+000000000000' verify_code = '000000' session_info = 'A' * 247 id_token = 'A' * 893 unknown = 'A' * 226 user_id = 'A' * 28 expires_in = 3600 is_new_user = 0 @classmethod def dotest(self): """Test the above functions""" test = SendVerificationCodeRequest(self.phone_number).dumps() expected = b'\n\r' + self.phone_number.encode() assert test == expected test = SendVerificationCodeResponse(self.session_info).dumps() expected = b'\n\xf7\x01' + self.session_info.encode() assert test == expected test = VerifyPhoneNumberRequest( session_info=self.session_info, verify_code=self.verify_code ).dumps() expected = b'\n\xf7\x01' + self.session_info.encode() \ + b'\x1a\x06' + self.verify_code.encode() assert test == expected test = VerifyPhoneNumberResponse( id_token=self.id_token, unknown=self.unknown, expires_in=self.expires_in, user_id=self.user_id, is_new_user=self.is_new_user, phone_number=self.phone_number ).dumps() expected = b'\n\xfd\x06' + self.id_token.encode() \ + b'\x12\xe2\x01' + self.unknown.encode() \ + b'\x18\x90\x1c"\x1c' + self.user_id.encode() \ + b'(\x00J\r' + self.phone_number.encode() assert test == expected
Class variables
var expires_in
var id_token
var is_new_user
var phone_number
var session_info
var unknown
var user_id
var verify_code
Static methods
def dotest()
-
Test the above functions
Expand source code
@classmethod def dotest(self): """Test the above functions""" test = SendVerificationCodeRequest(self.phone_number).dumps() expected = b'\n\r' + self.phone_number.encode() assert test == expected test = SendVerificationCodeResponse(self.session_info).dumps() expected = b'\n\xf7\x01' + self.session_info.encode() assert test == expected test = VerifyPhoneNumberRequest( session_info=self.session_info, verify_code=self.verify_code ).dumps() expected = b'\n\xf7\x01' + self.session_info.encode() \ + b'\x1a\x06' + self.verify_code.encode() assert test == expected test = VerifyPhoneNumberResponse( id_token=self.id_token, unknown=self.unknown, expires_in=self.expires_in, user_id=self.user_id, is_new_user=self.is_new_user, phone_number=self.phone_number ).dumps() expected = b'\n\xfd\x06' + self.id_token.encode() \ + b'\x12\xe2\x01' + self.unknown.encode() \ + b'\x18\x90\x1c"\x1c' + self.user_id.encode() \ + b'(\x00J\r' + self.phone_number.encode() assert test == expected
class VerifyPhoneNumberRequest (session_info: str = '', verify_code: str = '')
-
VerifyPhoneNumberRequest(session_info: str = '', verify_code: str = '')
Expand source code
class VerifyPhoneNumberRequest: session_info: str = field(1, default='') verify_code: str = field(3, default='')
Class variables
var serializer
var session_info : str
var type_url
var verify_code : str
Static methods
def load(io: Union[BinaryIO, _io.BytesIO]) ‑> ~T
-
Deserializes a message from a file-like object.
Expand source code
def load(cls: Type[T], io: IO) -> T: """ Deserializes a message from a file-like object. """ return cls.serializer.load(io)
def loads(bytes_: bytes) ‑> ~T
-
Deserializes a message from a byte string.
Expand source code
def loads(cls: Type[T], bytes_: bytes) -> T: """ Deserializes a message from a byte string. """ with BytesIO(bytes_) as io: return load(cls, io)
Methods
def dump(self, io: Union[BinaryIO, _io.BytesIO])
-
Serializes a message into a file-like object.
Expand source code
def dump(self, io: IO): """ Serializes a message into a file-like object. """ self.validate() self.serializer.dump(self, io)
def dumps(self) ‑> bytes
-
Serializes a message into a byte string.
Expand source code
def dumps(self) -> bytes: """ Serializes a message into a byte string. """ with BytesIO() as io: self.dump(io) return io.getvalue()
def merge_from(self: ~T, other: ~T)
-
Merge another message into the current one, as if with the
Message::MergeFrom
method.Expand source code
def merge_from(self: T, other: T): """ Merge another message into the current one, as if with the ``Message::MergeFrom`` method. """ for field_ in self.__protobuf_fields__.values(): # type: Field setattr(self, field_.name, field_.merge( getattr(self, field_.name), getattr(other, field_.name), ))
def validate(self)
-
Expand source code
def validate(self): self.serializer.validate(self)
class VerifyPhoneNumberResponse (id_token: str = '', refresh_token: str = '', expires_in:
.new_type at 0x7f853d6035e0> = 0, user_id: str = '', is_new_user: .new_type at 0x7f853d6035e0> = 0, phone_number: str = '') -
VerifyPhoneNumberResponse(id_token: str = '', refresh_token: str = '', expires_in:
.new_type at 0x7f853d6035e0> = 0, user_id: str = '', is_new_user: .new_type at 0x7f853d6035e0> = 0, phone_number: str = '') Expand source code
class VerifyPhoneNumberResponse: id_token: str = field(1, default='') refresh_token: str = field(2, default='') expires_in: int32 = field(3, default=int32(0)) user_id: str = field(4, default='') is_new_user: int32 = field(5, default=int32(0)) phone_number: str = field(9, default='')
Class variables
var expires_in :
.new_type at 0x7f853d6035e0> var id_token : str
var is_new_user :
.new_type at 0x7f853d6035e0> var phone_number : str
var refresh_token : str
var serializer
var type_url
var user_id : str
Static methods
def load(io: Union[BinaryIO, _io.BytesIO]) ‑> ~T
-
Deserializes a message from a file-like object.
Expand source code
def load(cls: Type[T], io: IO) -> T: """ Deserializes a message from a file-like object. """ return cls.serializer.load(io)
def loads(bytes_: bytes) ‑> ~T
-
Deserializes a message from a byte string.
Expand source code
def loads(cls: Type[T], bytes_: bytes) -> T: """ Deserializes a message from a byte string. """ with BytesIO(bytes_) as io: return load(cls, io)
Methods
def dump(self, io: Union[BinaryIO, _io.BytesIO])
-
Serializes a message into a file-like object.
Expand source code
def dump(self, io: IO): """ Serializes a message into a file-like object. """ self.validate() self.serializer.dump(self, io)
def dumps(self) ‑> bytes
-
Serializes a message into a byte string.
Expand source code
def dumps(self) -> bytes: """ Serializes a message into a byte string. """ with BytesIO() as io: self.dump(io) return io.getvalue()
def merge_from(self: ~T, other: ~T)
-
Merge another message into the current one, as if with the
Message::MergeFrom
method.Expand source code
def merge_from(self: T, other: T): """ Merge another message into the current one, as if with the ``Message::MergeFrom`` method. """ for field_ in self.__protobuf_fields__.values(): # type: Field setattr(self, field_.name, field_.merge( getattr(self, field_.name), getattr(other, field_.name), ))
def validate(self)
-
Expand source code
def validate(self): self.serializer.validate(self)