You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.5 KiB
61 lines
1.5 KiB
import pprint |
|
|
|
from collections import OrderedDict |
|
from pyramid.config import Configurator |
|
from pyramid.response import Response |
|
from pyramid.view import view_config |
|
|
|
|
|
class RootResource: |
|
''' A simple 'catch all' resource ''' |
|
|
|
def __init__(self, request): |
|
''' initialization ''' |
|
pass |
|
|
|
def __getitem__(self, key): |
|
''' no child resource lookup, only one view used''' |
|
return self |
|
|
|
|
|
def _dict_helper(dict_like): |
|
return [f' {k}: {v}' for k, v in dict_like.items()] |
|
|
|
|
|
@view_config(context=RootResource) |
|
def the_view(context, request): |
|
|
|
body = [ |
|
'Someone Wanted Some Sweet Honey', |
|
'-------------------------------', |
|
'', |
|
f'requested url: {request.url}', |
|
f'request method: {request.method}', |
|
f'client ip address: {request.client_addr}', |
|
f'remote ip address: {request.remote_addr}', |
|
'', |
|
f'request.authorization: {request.authorization}', |
|
f'request.remote_user: {request.remote_user}', |
|
'', |
|
'headers:' |
|
] |
|
|
|
body.extend(_dict_helper(request.headers)) |
|
|
|
body.extend(['', 'cookies:']) |
|
if request.cookies: |
|
body.extend(_dict_helper(request.cookies)) |
|
else: |
|
body.append(' (no cookies)') |
|
|
|
return Response(body='\n'.join(body), content_type='text/plain') |
|
|
|
|
|
|
|
def main(global_config, **settings): |
|
""" This function returns a Pyramid WSGI application. |
|
""" |
|
config = Configurator(settings=settings) |
|
config.set_root_factory(RootResource) |
|
config.scan() |
|
return config.make_wsgi_app()
|
|
|