Skip to content

Commit

Permalink
Merge 6349efd into 0e8c29c
Browse files Browse the repository at this point in the history
  • Loading branch information
Yomguithereal committed Feb 19, 2021
2 parents 0e8c29c + 6349efd commit b6b041f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
4 changes: 4 additions & 0 deletions tests/test_sanity.py
Expand Up @@ -165,6 +165,10 @@ def test_picklability():
assert res == res2
assert res2[2] == 3

p = pickle.dumps(twitter11)
s = pickle.loads(p)
assert twitter11.domain == s.domain


def test_jsonifability():
res = TwitterDictResponse({'a': 'b'})
Expand Down
34 changes: 21 additions & 13 deletions twitter/api.py
Expand Up @@ -193,19 +193,27 @@ def __init__(
self.retry = retry

def __getattr__(self, k):
try:
return object.__getattr__(self, k)
except AttributeError:
def extend_call(arg):
return self.callable_cls(
auth=self.auth, format=self.format, domain=self.domain,
callable_cls=self.callable_cls, timeout=self.timeout,
secure=self.secure, gzip=self.gzip, retry=self.retry,
uriparts=self.uriparts + (arg,))
if k == "_":
return extend_call
else:
return extend_call(k)

# NOTE: we test this to avoid doing dangerous things when actually
# attempting to get magic methods this object does not have (such as
# __getstate__, for instance, which is important to pickling).
# NOTE: when this code is run, the desired magic method cannot exist
# on this object because we are using __getattr__ and not
# __getattribute__, hence if it existed, it would be accessed normally.
if k.startswith('__'):
raise AttributeError

def extend_call(arg):
return self.callable_cls(
auth=self.auth, format=self.format, domain=self.domain,
callable_cls=self.callable_cls, timeout=self.timeout,
secure=self.secure, gzip=self.gzip, retry=self.retry,
uriparts=self.uriparts + (arg,))

if k == "_":
return extend_call
else:
return extend_call(k)

def __call__(self, **kwargs):
kwargs = dict(kwargs)
Expand Down

0 comments on commit b6b041f

Please sign in to comment.