@@ -178,7 +178,7 @@ def _d(x: Optional[str], do_split: bool = True) -> Tuple[Optional[str], Optional
178178
179179 return x , None
180180
181- log .debug (request )
181+ log .debug (f'Processing request: { request } ' )
182182
183183 if request .matchdict is None :
184184 raise exc .exception_response (400 )
@@ -190,18 +190,18 @@ def _d(x: Optional[str], do_split: bool = True) -> Tuple[Optional[str], Optional
190190 pass
191191
192192 entry = request .matchdict .get ('entry' , 'request' )
193- path = list (request .matchdict .get ('path' , []))
193+ path_elem = list (request .matchdict .get ('path' , []))
194194 match = request .params .get ('q' , request .params .get ('query' , None ))
195195
196196 # Enable matching on scope.
197197 match = match .split ('@' ).pop () if match and not match .endswith ('@' ) else match
198198 log .debug ("match={}" .format (match ))
199199
200- if 0 == len ( path ) :
201- path = ['entities' ]
200+ if not path_elem :
201+ path_elem = ['entities' ]
202202
203- alias = path .pop (0 )
204- path = '/' .join (path )
203+ alias = path_elem .pop (0 )
204+ path = '/' .join (path_elem )
205205
206206 # Ugly workaround bc WSGI drops double-slashes.
207207 path = path .replace (':/' , '://' )
@@ -234,23 +234,31 @@ def _d(x: Optional[str], do_split: bool = True) -> Tuple[Optional[str], Optional
234234 accept = str (request .accept ).split (',' )[0 ]
235235 valid_accept = accept and not ('application/*' in accept or 'text/*' in accept or '*/*' in accept )
236236
237- path_no_extension , extension = _d (path , True )
238- accept_from_extension = _ctypes .get (extension , accept )
237+ new_path : Optional [str ] = path
238+ path_no_extension , extension = _d (new_path , True )
239+ accept_from_extension = accept
240+ if extension :
241+ accept_from_extension = _ctypes .get (extension , accept )
239242
240243 if policy == 'extension' :
241- path = path_no_extension
244+ new_path = path_no_extension
242245 if not valid_accept :
243246 accept = accept_from_extension
244247 elif policy == 'adaptive' :
245248 if not valid_accept :
246- path = path_no_extension
249+ new_path = path_no_extension
247250 accept = accept_from_extension
248251
249- if pfx and path :
250- q = "{%s}%s" % (pfx , path )
251- path = "/%s/%s" % (alias , path )
252+ if not accept :
253+ log .warning ('Could not determine accepted response type' )
254+ raise exc .exception_response (400 )
255+
256+ q : Optional [str ]
257+ if pfx and new_path :
258+ q = f'{{{ pfx } }}{ new_path } '
259+ new_path = f'/{ alias } /{ new_path } '
252260 else :
253- q = path
261+ q = new_path
254262
255263 try :
256264 accepter = MediaAccept (accept )
@@ -262,18 +270,19 @@ def _d(x: Optional[str], do_split: bool = True) -> Tuple[Optional[str], Optional
262270 'url' : request .current_route_url (),
263271 'select' : q ,
264272 'match' : match .lower () if match else match ,
265- 'path' : path ,
273+ 'path' : new_path ,
266274 'stats' : {},
267275 }
268276
269277 r = p .process (request .registry .md , state = state , raise_exceptions = True , scheduler = request .registry .scheduler )
270- log .debug (r )
278+ log .debug (f'Plumbing process result: { r } ' )
271279 if r is None :
272280 r = []
273281
274282 response = Response ()
275- response .headers .update (state .get ('headers' , {}))
276- ctype = state .get ('headers' ).get ('Content-Type' , None )
283+ _headers = state .get ('headers' , {})
284+ response .headers .update (_headers )
285+ ctype = _headers .get ('Content-Type' , None )
277286 if not ctype :
278287 r , t = _fmt (r , accepter )
279288 ctype = t
@@ -288,13 +297,13 @@ def _d(x: Optional[str], do_split: bool = True) -> Tuple[Optional[str], Optional
288297 import traceback
289298
290299 log .debug (traceback .format_exc ())
291- log .warning (ex )
300+ log .warning (f'Exception from processing pipeline: { ex } ' )
292301 raise exc .exception_response (409 )
293302 except BaseException as ex :
294303 import traceback
295304
296305 log .debug (traceback .format_exc ())
297- log .error (ex )
306+ log .error (f'Exception from processing pipeline: { ex } ' )
298307 raise exc .exception_response (500 )
299308
300309 if request .method == 'GET' :
@@ -332,7 +341,7 @@ def webfinger_handler(request: Request) -> Response:
332341 "subject": "http://reep.refeds.org:8080"
333342 }
334343
335- Depending on which version of pyFF your 're running and the configuration you
344+ Depending on which version of pyFF you 're running and the configuration you
336345 may also see downstream metadata listed using the 'role' attribute to the link
337346 elements.
338347 """
@@ -344,7 +353,7 @@ def webfinger_handler(request: Request) -> Response:
344353 resource = request .host_url
345354
346355 jrd : Dict [str , Any ] = dict ()
347- dt = datetime .now () + duration2timedelta ( "PT1H" )
356+ dt = datetime .now () + timedelta ( hours = 1 )
348357 jrd ['expires' ] = dt .isoformat ()
349358 jrd ['subject' ] = request .host_url
350359 links : List [Dict [str , Any ]] = list ()
@@ -509,7 +518,9 @@ def mkapp(*args: Any, **kwargs: Any) -> Any:
509518 for mn in config .modules :
510519 importlib .import_module (mn )
511520
512- pipeline = args or None
521+ pipeline = None
522+ if args :
523+ pipeline = list (args )
513524 if pipeline is None and config .pipeline :
514525 pipeline = [config .pipeline ]
515526
0 commit comments