+ uri += "/%s" % (id)
+
+ # If an _id kwarg is present, this is treated as id as a CGI
+ # param.
+ _id = kwargs.pop('_id', None)
+ if _id:
+ kwargs['id'] = _id
+
+ # If an _timeout is specified in kwargs, use it
+ _timeout = kwargs.pop('_timeout', None)
+
+ secure_str = ''
+ if self.secure:
+ secure_str = 's'
+ dot = ""
+ if self.format:
+ dot = "."
+ uriBase = "http%s://%s/%s%s%s" % (
+ secure_str, self.domain, uri, dot, self.format)
+
+ # Catch media arguments to handle oauth query differently for multipart
+ media = None
+ for arg in ['media[]', 'banner', 'image']:
+ if arg in kwargs:
+ media = kwargs.pop(arg)
+ # Check if argument tells whether img is already base64 encoded
+ b64_convert = True
+ if "_base64" in kwargs:
+ b64_convert = not kwargs.pop("_base64")
+ if b64_convert:
+ import base64
+ media = base64.b64encode(media)
+ mediafield = arg
+ break
+
+ headers = {'Accept-Encoding': 'gzip'} if self.gzip else dict()
+ body = None
+ arg_data = None
+ if self.auth:
+ headers.update(self.auth.generate_headers())
+ # Use urlencoded oauth args with no params when sending media
+ # via multipart and send it directly via uri even for post
+ arg_data = self.auth.encode_params(
+ uriBase, method, {} if media else kwargs)
+ if method == 'GET' or media:
+ uriBase += '?' + arg_data