Add Session and Client __repr__ implementations

This commit is contained in:
Mads Marquart
2020-01-09 10:32:30 +01:00
parent a36ff5ee6e
commit cf24c7e8c2
2 changed files with 9 additions and 2 deletions

View File

@@ -70,6 +70,9 @@ class Client:
self._session = session self._session = session
self._uid = session.user_id self._uid = session.user_id
def __repr__(self):
return "Client(session={!r})".format(self._session)
""" """
INTERNAL REQUEST METHODS INTERNAL REQUEST METHODS
""" """

View File

@@ -5,7 +5,7 @@ import requests
import random import random
import urllib.parse import urllib.parse
from ._core import log, attrs_default from ._core import log, kw_only
from . import _graphql, _util, _exception from . import _graphql, _util, _exception
FB_DTSG_REGEX = re.compile(r'name="fb_dtsg" value="(.*?)"') FB_DTSG_REGEX = re.compile(r'name="fb_dtsg" value="(.*?)"')
@@ -98,7 +98,7 @@ def _2fa_helper(session, code, r):
return r return r
@attrs_default @attr.s(slots=True, kw_only=kw_only, repr=False)
class Session: class Session:
"""Stores and manages state required for most Facebook requests. """Stores and manages state required for most Facebook requests.
@@ -118,6 +118,10 @@ class Session:
"""The logged in user's ID.""" """The logged in user's ID."""
return self._user_id return self._user_id
def __repr__(self):
# An alternative repr, to illustrate that you can't create the class directly
return "<fbchat.Session user_id={}>".format(self._user_id)
def _get_params(self): def _get_params(self):
self._counter += 1 # TODO: Make this operation atomic / thread-safe self._counter += 1 # TODO: Make this operation atomic / thread-safe
return { return {