<commit_before>#!/usr/bin/env python

import web, redis

urls = (
     '/(.*)', 'payment'
)

r = redis.Redis()

class payment(object):
    def GET(self, stuff):
        web.header("Content-type", "text/html")
        return "Hello there! " + stuff

if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()

# vim: set tabstop=4 shiftwidth=4 expandtab<commit_msg>process payment request from end-user web browser<commit_after>#!/usr/bin/env python

# TODO: Is there some way to limit this program's access to the database
# so that it cannot change any values, but can still publish pubsub
# messages?  That would make the security analysis of the system as a
# whole clearer.

import web, redis

urls = (
     '/(.*)', 'payment'
)

r = redis.Redis()

def hexdigit(s):
    return s in "0123456789abcdef"

class payment(object):
    def GET(self, session):
        web.header("Content-type", "text/html")
        if len(session) != 64 or not all(hexdigit(s) for s in session):
            return "Attempt to process payment for invalid session."
        if session not in r or r.hget(self.id, "live") != "True":
            return "Attempt to process payment for invalid session."
        if r.hget(session, "state") != "payment":
            return "Attempt to process payment for session not expecting it."
        r.publish("payments", session)
        return "<h1>Thank you!</h1> Processed a payment for session ID %s." % session

if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()

# vim: set tabstop=4 shiftwidth=4 expandtab
{'fraction_non_alphanumeric': 0.1265743073047859, 'fraction_numerical': 0.011335012594458438, 'mean_word_length': 3.1380208333333335, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2089860', 'n_tokens_mistral': 507, 'n_tokens_neox': 494, 'n_words': 173}