You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by pq...@apache.org on 2010/01/08 23:41:33 UTC
svn commit: r897343 - /incubator/libcloud/trunk/libcloud/base.py
Author: pquerna
Date: Fri Jan 8 22:41:33 2010
New Revision: 897343
URL: http://svn.apache.org/viewvc?rev=897343&view=rev
Log:
Make an easier way to extend the user agent string.
Using this format, you end up with something like this:
User-Agent: libcloud/0.1.1-dev (Linode) (MyCompany.com)
Where Linode is the NodeDriver.name.
Modified:
incubator/libcloud/trunk/libcloud/base.py
Modified: incubator/libcloud/trunk/libcloud/base.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/base.py?rev=897343&r1=897342&r2=897343&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/base.py (original)
+++ incubator/libcloud/trunk/libcloud/base.py Fri Jan 8 22:41:33 2010
@@ -288,6 +288,7 @@
"""
self.key = key
self.secure = secure and 1 or 0
+ self.ua = []
def connect(self, host=None, port=None):
"""
@@ -307,6 +308,15 @@
connection = self.conn_classes[self.secure](host, port)
self.connection = connection
+ def _user_agent(self):
+ return 'libcloud/%s (%s)%s' % (
+ libcloud.__version__,
+ self.driver.name,
+ "".join([" (%s)" % x for x in self.ua]))
+
+ def user_agent_append(self, s):
+ self.ua.append(s)
+
def request(self, action, params=None, data='', headers=None, method='GET'):
"""
Request a given `action`.
@@ -343,7 +353,7 @@
headers = self.add_default_headers(headers)
# We always send a content length and user-agent header
headers.update({'Content-Length': len(data)})
- headers.update({'User-Agent': 'libcloud/%s (%s)' % (libcloud.__version__, self.driver.name)})
+ headers.update({'User-Agent': self._user_agent()})
headers.update({'Host': self.host})
# Encode data if necessary
if data != '':