|
17 | 17 |
|
18 | 18 | from datetime import datetime |
19 | 19 | from M2Crypto import X509, RSA, EVP, BIO |
| 20 | +from fts3 import __version__ as CLIENT_VERSION |
| 21 | + |
20 | 22 | try: |
21 | 23 | from M2Crypto.ASN1 import UTC |
22 | 24 | except: |
@@ -145,11 +147,18 @@ def _validate_endpoint(self): |
145 | 147 | raise BadEndpoint("%s (%s)" % (self.endpoint, str(e))), None, sys.exc_info()[2] |
146 | 148 | return endpoint_info |
147 | 149 |
|
| 150 | + def _set_user_agent(self, user_agent=None): |
| 151 | + if user_agent is None: |
| 152 | + self.user_agent = 'fts-python-bindings/' + CLIENT_VERSION |
| 153 | + else: |
| 154 | + self.user_agent = user_agent |
| 155 | + |
148 | 156 | def __init__(self, endpoint, ucert=None, ukey=None, verify=True, access_token=None, no_creds=False, capath=None, |
149 | | - request_class=PycurlRequest, connectTimeout=30, timeout=30): |
| 157 | + request_class=PycurlRequest, connectTimeout=30, timeout=30, user_agent=None): |
150 | 158 | self.passwd = None |
151 | 159 | self.access_method = None |
152 | 160 |
|
| 161 | + self._set_user_agent(user_agent) |
153 | 162 | self._set_endpoint(endpoint) |
154 | 163 | if no_creds: |
155 | 164 | self.ucert = self.ukey = self.access_token = None |
@@ -180,21 +189,24 @@ def get(self, path, args=None): |
180 | 189 | query = '&'.join(map(lambda (k, v): "%s=%s" % (k, urllib.quote(v)), args.iteritems())) |
181 | 190 | path += '?' + query |
182 | 191 | return self._requester.method('GET', |
183 | | - "%s/%s" % (self.endpoint, path)) |
| 192 | + "%s/%s" % (self.endpoint, path), |
| 193 | + headers = {'User-Agent': self.user_agent}) |
184 | 194 |
|
185 | 195 | def put(self, path, body): |
186 | 196 | return self._requester.method('PUT', |
187 | 197 | "%s/%s" % (self.endpoint, path), |
188 | | - body) |
| 198 | + body = body, headers = {'User-Agent': self.user_agent}) |
189 | 199 |
|
190 | 200 | def delete(self, path): |
191 | 201 | return self._requester.method('DELETE', |
192 | | - "%s/%s" % (self.endpoint, path)) |
| 202 | + "%s/%s" % (self.endpoint, path), |
| 203 | + headers = {'User-Agent': self.user_agent}) |
193 | 204 |
|
194 | 205 | def post_json(self, path, body): |
195 | 206 | if not isinstance(body, str) and not isinstance(body, unicode): |
196 | 207 | body = json.dumps(body) |
| 208 | + headers = {'Content-Type': 'application/json', 'User-Agent': self.user_agent} |
197 | 209 | return self._requester.method('POST', |
198 | 210 | "%s/%s" % (self.endpoint, path), |
199 | | - body, |
200 | | - headers={'Content-Type': 'application/json'}) |
| 211 | + body = body, |
| 212 | + headers = headers) |
0 commit comments