Beispiel #1
0
 def _sendPhoto(self, chat_id, photo, **args):
     content_type, body = encode_multipart_formdata([('chat_id', str(chat_id))], [('photo', 'screen.png', photo)])
     self.client.fetch(self.base_url + "/sendPhoto",
         method = 'POST',
         headers = {'content-length': str(len(body)), 'content-type': content_type},
         body = body,
         callback = lambda x: x)
Beispiel #2
0
 def upload(self, filename, data, mimetype=None):
     content_type, data = encode_multipart_formdata([], [("file", filename, data)], mimetype)
     r = self.connection.get_json(
         path=self.id + "/files",
         method="POST",
         headers={"Content-type": content_type, "Content-length": str(len(data))},
         data=data,
     )
     return LiveProxyObject(self.connection, r[u"id"])
Beispiel #3
0
    def _request(self, url, method='GET', headers={}, data=None, timeout=None):
        """Make a http request to `url`, with `headers`. If data is
        not None, make it a POST request. Returns a file-like object.

        """
        headers = dict(headers)
        headers['User-Agent'] = self.user_agent
        if data:
            data, content_type = encode_multipart_formdata(data)
            headers["Content-type"] = content_type

        log.debug(repr((method, url, data, headers),))

        self.http.request(method, url, data, headers)
        return self.http.getresponse()