فهرست منبع

Use hidden metadata instead of custom serializer

Tulir Asokan 4 سال پیش
والد
کامیت
0b41156de3
2فایلهای تغییر یافته به همراه10 افزوده شده و 20 حذف شده
  1. 2 11
      mauigpapi/state/experiments.py
  2. 8 9
      mauigpapi/state/state.py

+ 2 - 11
mauigpapi/state/experiments.py

@@ -1,5 +1,5 @@
 # mautrix-instagram - A Matrix-Instagram puppeting bridge.
 # mautrix-instagram - A Matrix-Instagram puppeting bridge.
-# Copyright (C) 2020 Tulir Asokan
+# Copyright (C) 2021 Tulir Asokan
 #
 #
 # This program is free software: you can redistribute it and/or modify
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as published by
 # it under the terms of the GNU Affero General Public License as published by
@@ -15,12 +15,10 @@
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 from typing import Dict
 from typing import Dict
 
 
-from mautrix.types import Serializable, JSON
-from mautrix.types.util import no_value
 from ..types import AndroidExperiment, QeSyncResponse
 from ..types import AndroidExperiment, QeSyncResponse
 
 
 
 
-class AndroidExperiments(Serializable):
+class AndroidExperiments:
     experiments: Dict[str, AndroidExperiment]
     experiments: Dict[str, AndroidExperiment]
 
 
     def __init__(self) -> None:
     def __init__(self) -> None:
@@ -28,10 +26,3 @@ class AndroidExperiments(Serializable):
 
 
     def update(self, updated: QeSyncResponse) -> None:
     def update(self, updated: QeSyncResponse) -> None:
         self.experiments.update({item.name: item.parse() for item in updated.experiments})
         self.experiments.update({item.name: item.parse() for item in updated.experiments})
-
-    def serialize(self) -> no_value:
-        return no_value
-
-    @classmethod
-    def deserialize(cls, raw: JSON) -> 'AndroidExperiments':
-        return cls()

+ 8 - 9
mauigpapi/state/state.py

@@ -1,5 +1,5 @@
 # mautrix-instagram - A Matrix-Instagram puppeting bridge.
 # mautrix-instagram - A Matrix-Instagram puppeting bridge.
-# Copyright (C) 2020 Tulir Asokan
+# Copyright (C) 2021 Tulir Asokan
 #
 #
 # This program is free software: you can redistribute it and/or modify
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as published by
 # it under the terms of the GNU Affero General Public License as published by
@@ -19,9 +19,8 @@ import random
 import time
 import time
 
 
 from attr import dataclass
 from attr import dataclass
-import attr
 
 
-from mautrix.types import SerializableAttrs
+from mautrix.types import SerializableAttrs, field
 
 
 from ..errors import IGNoCheckpointError, IGCookieNotFoundError, IGUserIDNotFoundError
 from ..errors import IGNoCheckpointError, IGCookieNotFoundError, IGUserIDNotFoundError
 from ..types import ChallengeStateResponse
 from ..types import ChallengeStateResponse
@@ -34,15 +33,15 @@ from .cookies import Cookies
 
 
 @dataclass
 @dataclass
 class AndroidState(SerializableAttrs):
 class AndroidState(SerializableAttrs):
-    device: AndroidDevice = attr.ib(factory=lambda: AndroidDevice())
-    session: AndroidSession = attr.ib(factory=lambda: AndroidSession())
-    application: AndroidApplication = attr.ib(factory=lambda: AndroidApplication())
-    experiments: AndroidExperiments = attr.ib(factory=lambda: AndroidExperiments())
+    device: AndroidDevice = field(factory=lambda: AndroidDevice())
+    session: AndroidSession = field(factory=lambda: AndroidSession())
+    application: AndroidApplication = field(factory=lambda: AndroidApplication())
+    experiments: AndroidExperiments = field(factory=lambda: AndroidExperiments(), hidden=True)
     client_session_id_lifetime: int = 1_200_000
     client_session_id_lifetime: int = 1_200_000
     pigeon_session_id_lifetime: int = 1_200_000
     pigeon_session_id_lifetime: int = 1_200_000
     challenge: Optional[ChallengeStateResponse] = None
     challenge: Optional[ChallengeStateResponse] = None
-    _challenge_path: Optional[str] = attr.ib(default=None, metadata={"json": "challenge_path"})
-    cookies: Cookies = attr.ib(factory=lambda: Cookies())
+    _challenge_path: Optional[str] = field(default=None, json="challenge_path")
+    cookies: Cookies = field(factory=lambda: Cookies())
 
 
     def __attrs_post_init__(self) -> None:
     def __attrs_post_init__(self) -> None:
         if self.application.APP_VERSION_CODE != AndroidApplication().APP_VERSION_CODE:
         if self.application.APP_VERSION_CODE != AndroidApplication().APP_VERSION_CODE: