-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop': v1.3.0. Safe kwargs for all AliceObjects
+ store raw json in models
- Loading branch information
Showing
24 changed files
with
133 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ name: Python tests | |
on: [push] | ||
|
||
jobs: | ||
build: | ||
unit-tests: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,4 @@ | |
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) | ||
|
||
|
||
__version__ = '1.2.5' | ||
__version__ = '1.3.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
from attr import attrs, asdict | ||
from attr import attrs, attrib, asdict | ||
|
||
|
||
@attrs | ||
class AliceObject(object): | ||
class AliceObject: | ||
"""AliceObject is base class for all Alice requests related objects""" | ||
|
||
_raw_kwargs = attrib(factory=dict, init=False) | ||
""" | ||
here the raw JSON (dict) will be stored | ||
for using with compatible API | ||
""" | ||
|
||
def to_json(self): | ||
return asdict(self) | ||
data = asdict(self, filter=filter_to_json) | ||
return data | ||
|
||
|
||
def filter_to_json(attr, value) -> bool: | ||
return attr.name != '_raw_kwargs' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,5 +21,5 @@ def base(self): | |
return BaseSession( | ||
self.session_id, | ||
self.message_id, | ||
self.user_id | ||
self.user_id, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
try: | ||
import rapidjson as json | ||
import simplejson as json | ||
except ImportError: | ||
try: | ||
import ujson as json | ||
import rapidjson as json | ||
except ImportError: | ||
import json | ||
try: | ||
import ujson as json | ||
except ImportError: | ||
import json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
# https://gist.github.com/surik00/a6c2804a2d18a2ab75630bb5d93693c8 | ||
""" | ||
https://gist.github.com/mahenzon/a6c2804a2d18a2ab75630bb5d93693c8 | ||
""" | ||
|
||
import inspect | ||
import functools | ||
from inspect import isclass, getfullargspec | ||
|
||
|
||
def safe_kwargs(func_or_class): | ||
spec = inspect.getfullargspec(func_or_class) | ||
from ..types.base import AliceObject | ||
|
||
spec = getfullargspec(func_or_class) | ||
all_args = spec.args | ||
|
||
save_raw_kwargs = isclass(func_or_class) and issubclass(func_or_class, AliceObject) | ||
|
||
@functools.wraps(func_or_class) | ||
def wrap(*args, **kwargs): | ||
accepted_kwargs = {k: v for k, v in kwargs.items() if k in all_args} | ||
return func_or_class(*args, **accepted_kwargs) | ||
res = func_or_class(*args, **accepted_kwargs) | ||
|
||
if save_raw_kwargs: | ||
# saving all kwargs for access to unexpected attrs | ||
res._raw_kwargs.update(kwargs) | ||
|
||
return res | ||
|
||
return wrap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
# remove old builds | ||
rm ./dist/* | ||
|
||
# build | ||
python setup.py sdist | ||
python setup.py bdist_wheel | ||
|
||
# upload to PYPI | ||
twine upload dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
wheel>=0.33.4 | ||
twine>=1.13.0 | ||
pytest==5.3.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters