Skip to content

Commit fd99fc4

Browse files
committed
[abfile] must remove references to removed files.
[listfile] must have a read write persistent storage [util] content-type may contain more info about charset which should be weeded out.
1 parent 78bd655 commit fd99fc4

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

src/idpyoidc/client/oauth2/add_on/par.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from cryptojwt.utils import importer
44

55
from idpyoidc.client.client_auth import CLIENT_AUTHN_METHOD
6+
from idpyoidc.client.service import Service
67
from idpyoidc.message import Message
78
from idpyoidc.message.oauth2 import JWTSecuredAuthorizationRequest
89
from idpyoidc.server.util import execute
@@ -13,7 +14,7 @@
1314
HTTP_METHOD = "POST"
1415

1516

16-
def push_authorization(request_args, service, **kwargs):
17+
def push_authorization(request_args: Message, service: Service, **kwargs):
1718
"""
1819
:param request_args: All the request arguments as a AuthorizationRequest instance
1920
:param service: The service to which this post construct method is applied.

src/idpyoidc/client/util.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ def get_deserialization_method(reqresp):
271271
return "jwt"
272272
except Exception:
273273
return "urlencoded" # reasonable default ??
274+
elif ';' in _ctype:
275+
for _typ in _ctype.split(";"):
276+
if _typ.startswith("application") or _typ.startswith("text"):
277+
_ctype = _typ
278+
break
274279

275280
if match_to_("application/json", _ctype) or match_to_("application/jrd+json", _ctype):
276281
deser_method = "json"

src/idpyoidc/storage/abfile.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,14 @@ def synch(self):
239239
else:
240240
self.fmtime[f] = mtime
241241

242+
_keys = self.storage.keys()
243+
for f in _keys:
244+
fname = os.path.join(self.fdir, f)
245+
if os.path.isfile(fname):
246+
pass
247+
else:
248+
del self.storage[f]
249+
242250
def items(self):
243251
"""
244252
Implements the dict.items() method

src/idpyoidc/storage/listfile.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,43 @@ def _read_info(self, fname):
137137

138138
def __call__(self):
139139
return self._read_info(self.file_name)
140+
141+
class ReadWriteListFile(object):
142+
143+
def __init__(self, file_name):
144+
self.file_name = file_name
145+
146+
if not os.path.exists(file_name):
147+
fp = open(file_name, "x")
148+
fp.close()
149+
150+
def __contains__(self, item):
151+
_lst = self._read_info(self.file_name)
152+
return item in _lst
153+
154+
def __len__(self):
155+
_lst = self._read_info(self.file_name)
156+
if _lst is None or _lst == []:
157+
return 0
158+
159+
return len(_lst)
160+
161+
def _read_info(self, fname):
162+
if os.path.isfile(fname):
163+
try:
164+
lock = FileLock(f"{fname}.lock")
165+
with lock:
166+
fp = open(fname, "r")
167+
info = [x.strip() for x in fp.readlines()]
168+
lock.release()
169+
return info or None
170+
except Exception as err:
171+
logger.error(err)
172+
raise
173+
else:
174+
_msg = f"No such file: '{fname}'"
175+
logger.error(_msg)
176+
return None
177+
178+
def __call__(self):
179+
return self._read_info(self.file_name)

0 commit comments

Comments
 (0)