Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 4c3c63b

Browse files
committed
Refining dump/load implementation.
1 parent 4a7a408 commit 4c3c63b

28 files changed

+2063
-2005
lines changed

.travis.yml

-9
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,3 @@ after_success:
2525
- codecov
2626
notifications:
2727
email: false
28-
deploy:
29-
provider: pypi
30-
on:
31-
tags: true
32-
distributions: bdist_wheel
33-
skip_existing: true
34-
user: __token__
35-
password:
36-
secure: AH3jGGXVjV/oOlg4cOnsN7pURlZ7JMcd3Prr69Q++rxfsrmFpxCPtQLpO0LUNPisfyctoImpY64auNMHh20AHdlnvXQu8k/YFZCVcyK6N2d66wgJbO9AOT21N6IkFGyW11K3lYIHzURv9RsTEhzSkOhKmPUack5UhSJ+yAUTZXpt6iZqXBvmxMNzNiCLQdUmTMj4HxxkUVPabpef8PLqyDXvAxJxOCss+QcJVZuWFs85Niw0scTkU4SWz2lhOxeqQNg8s+CEgje2KaIoRy2kETywK53G3RFkSp5ytIJPp8RQK039laeal5yjMsWP4KlbDhHrywyNN7yS69FwPuLC41ppde5G054WcuJTm60Y2uckGu6L3oTBMHsAtSfZuEym/qfDngxYADA+xrATJQF5XSrCz13IiBnoz8Y9zI7t9s66PZSBHg99L85jM45M2kJYCDKxNPffJ/JzCnAMTP0yiBMEQ/UfguMDfJMw+6oSPzGcZHuQVzjLO5mUni71X528Psd/iEYCyN+Vi1QbvDZjbNo/oOLtvegOcnu/H1tGWkH4uEXsg2giqkld2hrZi6K3KfcpPtltuP66Z6ohMqcLegqGUNr8mPMP2I58p7if/6xLEu1e7MNZuoV459bnWepoNMMug2NLq/WIPCiGLNCyV4tdbzqcZQLNwjc5ruFLoz8=

src/oidcmsg/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
__author__ = 'Roland Hedberg'
2-
__version__ = '1.2.1'
1+
__author__ = "Roland Hedberg"
2+
__version__ = "1.3.0"
33

44
import os
55

6-
VERIFIED_CLAIM_PREFIX = '__verified'
6+
VERIFIED_CLAIM_PREFIX = "__verified"
77

88

99
def verified_claim_name(claim):
10-
return '{}_{}'.format(VERIFIED_CLAIM_PREFIX, claim)
10+
return "{}_{}".format(VERIFIED_CLAIM_PREFIX, claim)
1111

1212

1313
def proper_path(path):

src/oidcmsg/context.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,41 @@
1111
def add_issuer(conf, issuer):
1212
res = {}
1313
for key, val in conf.items():
14-
if key == 'abstract_storage_cls':
14+
if key == "abstract_storage_cls":
1515
res[key] = val
1616
else:
1717
_val = copy.copy(val)
18-
_val['issuer'] = quote_plus(issuer)
18+
_val["issuer"] = quote_plus(issuer)
1919
res[key] = _val
2020
return res
2121

2222

2323
class OidcContext(ImpExp):
2424
parameter = {"keyjar": KeyJar, "issuer": None}
2525

26-
def __init__(self, config=None, keyjar=None, entity_id=''):
26+
def __init__(self, config=None, keyjar=None, entity_id=""):
2727
ImpExp.__init__(self)
2828
if config is None:
2929
config = {}
3030

3131
self.issuer = entity_id
3232
self.keyjar = self._keyjar(keyjar, conf=config, entity_id=entity_id)
3333

34-
def _keyjar(self, keyjar=None, conf=None, entity_id=''):
34+
def _keyjar(self, keyjar=None, conf=None, entity_id=""):
3535
if keyjar is None:
36-
if 'keys' in conf:
36+
if "keys" in conf:
3737
args = {k: v for k, v in conf["keys"].items() if k != "uri_path"}
3838
_keyjar = init_key_jar(**args)
3939
else:
4040
_keyjar = KeyJar()
41-
if 'jwks' in conf:
42-
_keyjar.import_jwks(conf['jwks'], '')
41+
if "jwks" in conf:
42+
_keyjar.import_jwks(conf["jwks"], "")
4343

44-
if '' in _keyjar and entity_id:
44+
if "" in _keyjar and entity_id:
4545
# make sure I have the keys under my own name too (if I know it)
46-
_keyjar.import_jwks_as_json(_keyjar.export_jwks_as_json(True, ''), entity_id)
46+
_keyjar.import_jwks_as_json(_keyjar.export_jwks_as_json(True, ""), entity_id)
4747

48-
_httpc_params = conf.get('httpc_params')
48+
_httpc_params = conf.get("httpc_params")
4949
if _httpc_params:
5050
_keyjar.httpc_params = _httpc_params
5151

src/oidcmsg/exception.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__author__ = 'Roland Hedberg'
1+
__author__ = "Roland Hedberg"
22

33

44
class OidcMsgError(Exception):

src/oidcmsg/impexp.py

+19-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import List
33
from typing import Optional
44

5+
from cryptojwt.utils import as_bytes
56
from cryptojwt.utils import importer
67
from cryptojwt.utils import qualified_name
78

@@ -17,8 +18,11 @@ def __init__(self):
1718
pass
1819

1920
def dump_attr(self, cls, item, exclude_attributes: Optional[List[str]] = None) -> dict:
20-
if cls in [None, 0, "", [], {}, bool]:
21-
val = item
21+
if cls in [None, 0, "", [], {}, bool, b'']:
22+
if cls == b'':
23+
val = as_bytes(item)
24+
else:
25+
val = item
2226
elif isinstance(item, Message):
2327
val = {qualified_name(item.__class__): item.to_dict()}
2428
elif cls == object:
@@ -53,11 +57,13 @@ def dump(self, exclude_attributes: Optional[List[str]] = None) -> dict:
5357
def local_load_adjustments(self, **kwargs):
5458
pass
5559

56-
def load_attr(self,
57-
cls: Any,
58-
item: dict,
59-
init_args: Optional[dict] = None,
60-
load_args: Optional[dict] = None) -> Any:
60+
def load_attr(
61+
self,
62+
cls: Any,
63+
item: dict,
64+
init_args: Optional[dict] = None,
65+
load_args: Optional[dict] = None,
66+
) -> Any:
6167
if load_args:
6268
_kwargs = {"load_args": load_args}
6369
_load_args = load_args
@@ -68,8 +74,11 @@ def load_attr(self,
6874
if init_args:
6975
_kwargs["init_args"] = init_args
7076

71-
if cls in [None, 0, "", [], {}, bool]:
72-
val = item
77+
if cls in [None, 0, "", [], {}, bool, b'']:
78+
if cls == b'':
79+
val = as_bytes(item)
80+
else:
81+
val = item
7382
elif cls == object:
7483
val = importer(item)
7584
elif isinstance(cls, list):
@@ -98,9 +107,7 @@ def load_attr(self,
98107

99108
return val
100109

101-
def load(self, item: dict,
102-
init_args: Optional[dict] = None,
103-
load_args: Optional[dict] = None):
110+
def load(self, item: dict, init_args: Optional[dict] = None, load_args: Optional[dict] = None):
104111

105112
if load_args:
106113
_kwargs = {"load_args": load_args}

src/oidcmsg/item.py

+13-18
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99

1010
class DLDict(ImpExp):
11-
parameter = {
12-
"db": {}
13-
}
11+
parameter = {"db": {}}
1412

1513
def __init__(self, **kwargs):
1614
ImpExp.__init__(self)
@@ -22,7 +20,7 @@ def __setitem__(self, key: str, val):
2220
def __getitem__(self, key: str):
2321
return self.db[key]
2422

25-
def __delitem__(self, key:str):
23+
def __delitem__(self, key: str):
2624
del self.db[key]
2725

2826
def dump(self, exclude_attributes: Optional[List[str]] = None) -> dict:
@@ -34,12 +32,11 @@ def dump(self, exclude_attributes: Optional[List[str]] = None) -> dict:
3432

3533
return res
3634

37-
def load(self, spec: dict,
38-
init_args: Optional[dict] = None,
39-
load_args: Optional[dict] = None
40-
) -> "DLDict":
35+
def load(
36+
self, spec: dict, init_args: Optional[dict] = None, load_args: Optional[dict] = None
37+
) -> "DLDict":
4138
if load_args:
42-
_kwargs= {"load_args": load_args}
39+
_kwargs = {"load_args": load_args}
4340
_load_args = {}
4441
else:
4542
_load_args = {}
@@ -96,10 +93,9 @@ def dump_dldict(item, exclude_attributes: Optional[List[str]] = None) -> dict:
9693
return res
9794

9895

99-
def load_dldict(spec: dict,
100-
init_args: Optional[dict] = None,
101-
load_args: Optional[dict] = None
102-
) -> dict:
96+
def load_dldict(
97+
spec: dict, init_args: Optional[dict] = None, load_args: Optional[dict] = None
98+
) -> dict:
10399
db = {}
104100

105101
for attr, (_item_cls, _item) in spec.items():
@@ -127,11 +123,10 @@ def dump_class_map(item, exclude_attributes: Optional[List[str]] = None) -> dict
127123
return _dump
128124

129125

130-
def load_class_map(spec: dict,
131-
init_args: Optional[dict] = None,
132-
load_args: Optional[dict] = None
133-
) -> dict:
126+
def load_class_map(
127+
spec: dict, init_args: Optional[dict] = None, load_args: Optional[dict] = None
128+
) -> dict:
134129
_item = {}
135130
for key, val in spec.items():
136-
_item[key] = importer(val)
131+
_item[key] = importer(val)
137132
return _item

0 commit comments

Comments
 (0)