Dialect soup session handler
| 8 | |
| 9 | |
| 10 | class Session(Soup.Session): |
| 11 | """ |
| 12 | Dialect soup session handler |
| 13 | """ |
| 14 | |
| 15 | instance = None |
| 16 | errors = {} |
| 17 | |
| 18 | def __init__(self, *args): |
| 19 | super().__init__(*args) |
| 20 | |
| 21 | @staticmethod |
| 22 | def new() -> Session: |
| 23 | """Create a new instance of Session.""" |
| 24 | s_session = Session() |
| 25 | return s_session |
| 26 | |
| 27 | @staticmethod |
| 28 | def get() -> Session: |
| 29 | """Return an active instance of Session.""" |
| 30 | if Session.instance is None: |
| 31 | Session.instance = Session.new() |
| 32 | return Session.instance |
| 33 | |
| 34 | @staticmethod |
| 35 | def get_response(session: Session, result: Gio.AsyncResult): |
| 36 | try: |
| 37 | response = session.send_and_read_finish(result) |
| 38 | data = response.get_data() |
| 39 | |
| 40 | return data |
| 41 | except GLib.Error as exc: |
| 42 | raise ResponseError(exc.message) from exc |
| 43 | |
| 44 | |
| 45 | class ResponseError(Exception): |