Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
My rather lame approach to setting parameter storage class. It also demonstrates how to write an IPN handler with Flask, as that was my use case where form argument order mattered (most annoying). End result is uglier than just setting the storage class inside your function, but does make it easier to see when that special case is being used.
#demonstration of hack to declaratively set param_storage_class declaratively using a decorator
#also demonstrates how to write an IPN handler with Flask
from flask import Flask, make_response
from itertools import chain
app = Flask(__name__)
#Normally this parameter would come from a config
IPN_VERIFY_EXTRA_PARAMS = (('cmd', '_notify-validate'),)
def ordered_storage(f):
import werkzeug.datastructures
import flask
def decorator(*args, **kwargs):
flask.request.parameter_storage_class = werkzeug.datastructures.ImmutableOrderedMultiDict
return f(*args, **kwargs)
return decorator
@app.route('/webhooks/paypal', methods=['POST'])
def paypal_webhook():
#probably should have a sanity check here on the size of the form data to guard against DoS attacks
verify_args = chain(request.form.iteritems(), IPN_VERIFY_EXTRA_PARAMS)
verify_string = '&'.join(('%s=%s' % (param, value) for param, value in verify_args))
with closing(urlopen(IPN_URLSTRING, data=verify_string)) as paypal_verify_request:
response_string =
if response_string != 'VERIFIED':
raise ValueError('Did not receive expected IPN confirmation from PayPal')
return make_response('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.