chore: renamed "as_dict" into "serialize"
This commit is contained in:
parent
b7b8ab0bce
commit
d7107619b7
6 changed files with 8 additions and 8 deletions
|
@ -52,7 +52,7 @@ class AuthInterface:
|
||||||
json={
|
json={
|
||||||
"serverId": server_id,
|
"serverId": server_id,
|
||||||
"accessToken": self.accessToken,
|
"accessToken": self.accessToken,
|
||||||
"selectedProfile": self.selectedProfile.as_dict()
|
"selectedProfile": self.selectedProfile.serialize()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ class MicrosoftAuthenticator(AuthInterface):
|
||||||
return {
|
return {
|
||||||
'accessToken': self.accessToken,
|
'accessToken': self.accessToken,
|
||||||
'refreshToken': self.refreshToken,
|
'refreshToken': self.refreshToken,
|
||||||
'selectedProfile': self.selectedProfile.as_dict(),
|
'selectedProfile': self.selectedProfile.serialize(),
|
||||||
}
|
}
|
||||||
|
|
||||||
def deserialize(self, data:Dict[str, Any]):
|
def deserialize(self, data:Dict[str, Any]):
|
||||||
|
|
|
@ -53,7 +53,7 @@ class MojangAuthenticator(AuthInterface):
|
||||||
"username":self.username,
|
"username":self.username,
|
||||||
"accessToken":self.accessToken,
|
"accessToken":self.accessToken,
|
||||||
"clientToken":self.clientToken,
|
"clientToken":self.clientToken,
|
||||||
"selectedProfile": self.selectedProfile.as_dict(),
|
"selectedProfile": self.selectedProfile.serialize(),
|
||||||
}
|
}
|
||||||
|
|
||||||
def deserialize(self, data:Dict[str, Any]) -> AuthInterface:
|
def deserialize(self, data:Dict[str, Any]) -> AuthInterface:
|
||||||
|
|
|
@ -36,12 +36,12 @@ class GameProfile:
|
||||||
name : str
|
name : str
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return json.dumps(self.as_dict(), indent=2)
|
return json.dumps(self.serialize(), indent=2)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"GameProfile(id='{self.id}', name='{self.name}')"
|
return f"GameProfile(id='{self.id}', name='{self.name}')"
|
||||||
|
|
||||||
def as_dict(self):
|
def serialize(self):
|
||||||
return {
|
return {
|
||||||
"id": self.id,
|
"id": self.id,
|
||||||
"name": self.name
|
"name": self.name
|
||||||
|
|
|
@ -38,7 +38,7 @@ class Packet:
|
||||||
ctx = Context(_proto=proto)
|
ctx = Context(_proto=proto)
|
||||||
for k, t in cls._definitions[proto]:
|
for k, t in cls._definitions[proto]:
|
||||||
setattr(ctx, k, t.read(buffer, ctx=ctx))
|
setattr(ctx, k, t.read(buffer, ctx=ctx))
|
||||||
return cls(proto, **ctx.as_dict())
|
return cls(proto, **ctx.serialize())
|
||||||
# return cls(proto, **{ name : t.read(buffer) for (name, t) in cls._definitions[proto] })
|
# return cls(proto, **{ name : t.read(buffer) for (name, t) in cls._definitions[proto] })
|
||||||
|
|
||||||
def serialize(self) -> io.BytesIO:
|
def serialize(self) -> io.BytesIO:
|
||||||
|
|
|
@ -16,14 +16,14 @@ class Context(object):
|
||||||
for k, v in kwargs.items():
|
for k, v in kwargs.items():
|
||||||
setattr(self, k, v)
|
setattr(self, k, v)
|
||||||
|
|
||||||
def as_dict(self) -> dict:
|
def serialize(self) -> dict:
|
||||||
return vars(self) # is this reliable?
|
return vars(self) # is this reliable?
|
||||||
|
|
||||||
def __getattr__(self, name) -> Any:
|
def __getattr__(self, name) -> Any:
|
||||||
return None # return None rather than raising an exc
|
return None # return None rather than raising an exc
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return json.dumps(self.as_dict(), indent=2, default=str, sort_keys=True)
|
return json.dumps(self.serialize(), indent=2, default=str, sort_keys=True)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
values = ( f"{k}={repr(v)}" for k,v in vars(self).items() )
|
values = ( f"{k}={repr(v)}" for k,v in vars(self).items() )
|
||||||
|
|
Loading…
Reference in a new issue