From eb9f603707d932641b8c580bde91ddb7d54741e0 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 24 Aug 2012 07:22:39 -0400 Subject: storage:http: add agent argument to get_post_url. This allows us to set an appropriate user agent if we use this function in other places (e.g. upcoming Command._run_remote). --- libbe/storage/http.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'libbe/storage/http.py') diff --git a/libbe/storage/http.py b/libbe/storage/http.py index 877fc96..cfed7b7 100644 --- a/libbe/storage/http.py +++ b/libbe/storage/http.py @@ -79,7 +79,7 @@ class InvalidURL (Exception): return self.error.__str__() return self.msg -def get_post_url(url, get=True, data_dict=None, headers=[]): +def get_post_url(url, get=True, data_dict=None, headers=[], agent=None): """Execute a GET or POST transaction. Parameters @@ -95,6 +95,8 @@ def get_post_url(url, get=True, data_dict=None, headers=[]): """ if data_dict == None: data_dict = {} + if agent is None: + agent = USER_AGENT if get == True: if data_dict != {}: # encode get parameters in the url @@ -104,7 +106,7 @@ def get_post_url(url, get=True, data_dict=None, headers=[]): else: data = urllib.urlencode(data_dict) headers = dict(headers) - headers['User-Agent'] = USER_AGENT + headers['User-Agent'] = agent req = urllib2.Request(url, data=data, headers=headers) try: response = urllib2.urlopen(req) -- cgit