Commit 0e397235 authored by Devon Kearns's avatar Devon Kearns

Imported Upstream version 1.1

parent 30a4910d
......@@ -210,9 +210,9 @@ When you load a config file either via command line or the user interface, the s
Sometimes you need to do something really crazy. Maybe do you need to encrypt the values going into a field before sending the request or maybe you need to triple URL encode. Regardless, these situations make other tools impossible to use. BBQSQL allows you to define "hook" functions that the tool will call at various points throughout the request. For example, you can specify a `pre_request` function that takes the request as its argument, does whatever mutations are necessary, and returns the modified request to be sent on to the server.
To implement this, create a Python file and specify hook functions. The available function names are listed bellow. In your hooks file, you can define as few or as many of these hooks functions as you would like. Then, in the bbqsql_options section of the menue, you can specify the location of your hooks_file. BBQSQL will suck in this file and use whatever hooks you defined.
To implement this, just create a file named `` in your current working directory. Here you can define your callback functions for the hooks. Then, at the bottom of this file, add a dict named `hooks` whose format is `{'hook_name':hook_function}`.
It is important that the hooks functions you specify have the exact names specified bellow or else BBQSQL won't know which hook to call when. The `args` function receives one parameter that contains all the arguments that are being used to create the HTTP request. The `pre_request` function receives the request object before it is sent. The `post_request` function receives the request object after it has been sent. The `response` function receives the response object before it is returned to BBQSQL.
When you run BBQSQL, it will look in your current directory (as well as your normal Python path) for file named `` and will import from it the dict named `hooks`.
The following hooks are made available:
......@@ -227,20 +227,22 @@ The following hooks are made available:
For more information on how these hooks work and on how your `hooks` dictionary should look, check out the [requests library documentation on its hooks](
An example hooks file might look like this:
An example `` file might look like this:
# file:
# file:
import time
def pre_request(req):
def my_pre_hook(req):
this hook replaces a placeholder with the current time
expecting the url to look like this:
req.url = req.url.replace('PLACEHOLDER',str(time.time()))
return req
hooks = {'pre_request':my_pre_hook}
## Found a Bug? ##
......@@ -22,7 +22,7 @@ b::::::b b::::::b S:::::SSSSSS::::::S Q
__title__ = 'bbqsql'
__version__ = '1.1'
__version__ = '1.0'
__author__ = 'Ben Toews (mastahyeti)'
__license__ = 'MIT'
__copyright__ = 'Copyright 2012 Ben Toews (mastahyeti)'
......@@ -74,7 +74,7 @@ class Requester(object):
# if they defined pre_request hook, we wrap it with ours
if 'pre_request' in kwargs['hooks']:
orig_pre = kwargs['hooks']['pre_request']
wrapped_pre = lambda request:orig_pre(requests_pre_hook(request))
wrapped_pre = lambda request:requests_pre_hook(orig_pre(request))
kwargs['hooks']['pre_request'] = wrapped_pre
# otherwise, we just stick with our own hook
......@@ -84,7 +84,7 @@ class Requester(object):
# same for post_request hooks
if 'post_request' in kwargs['hooks']:
orig_post = kwargs['hooks']['post_request']
wrapped_post = lambda request:orig_post(requests_post_hook(request))
wrapped_post = lambda request:requests_post_hook(orig_post(request))
kwargs['hooks']['post_request'] = wrapped_post
......@@ -133,10 +133,6 @@ class Requester(object):
new_request_kwargs = copy(self.request_kwargs)
# keep track of which keys were dynamic so we know which ones to print after we make the request.
# we do this so hooks can process the requests before we print them for debugging...
keys_to_debug = []
#iterate over the request_kwargs and compile any elements that are query objects.
for k in [e for e in new_request_kwargs if isinstance(new_request_kwargs[e],Query)]:
opts = new_request_kwargs[k].get_options()
......@@ -144,16 +140,12 @@ class Requester(object):
opts[opt] = value
new_request_kwargs[k] = new_request_kwargs[k].render()
if debug:
print "Injecting into '%s' parameter" % k
print "It looks like this: %s" % new_request_kwargs[k]
response = self.session.request(**new_request_kwargs)
if debug:
for k in keys_to_debug:
print "Injecting into '%s' parameter" % k
print "It looks like this: %s" % getattr(response.request,k)
#glet = grequests.send(new_request)
#if not glet.get() and type(new_request.response.error) is requests.exceptions.ConnectionError:
......@@ -4,7 +4,7 @@ from bbqsql import *
import argparse
parser = argparse.ArgumentParser(prog='bbqsql')
parser.add_argument('-V', '--version', action='version', version='%(prog)s 1.1')
parser.add_argument('-V', '--version', action='version', version='%(prog)s 0.9')
parser.add_argument('-c', metavar='config', nargs='+', help='import config file', default=None)
results = parser.parse_args()
......@@ -3,7 +3,7 @@
from setuptools import setup
author='Ben Toews (mastahyeti)',
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment