Ejemplo n.º 1
0
  async def scan_file_async(self, file, wait_for_completion=False):
    """Like :func:`scan_file` but returns a coroutine."""

    # The snippet below could be replaced with this simpler code:
    #
    # form_data = aiohttp.FormData()
    # form_data.add_field('file', file)
    #
    # However, aiohttp.FormData assumes that the server supports RFC 5987 and
    # send a Content-Disposition like:
    #
    # 'form-data; name="file"; filename="foobar"; filename*=UTF-8''foobar
    #
    # AppEngine's upload handler doesn't like the filename*=UTF-8''foobar field
    # and fails with this Content-Disposition header.

    part = aiohttp.get_payload(file)
    filename = file.name if hasattr(file, 'name') else 'unknown'
    disposition = 'form-data; name="file"; filename="{}"'.format(filename)
    part.headers['Content-Disposition'] = disposition
    form_data = aiohttp.MultipartWriter('form-data')
    form_data.append_payload(part)

    upload_url = await self.get_data_async('/files/upload_url')
    response = ClientResponse(
        await self._get_session().post(upload_url, data=form_data))

    analysis = await self._response_to_object(response)

    if wait_for_completion:
      analysis = await self._wait_for_analysis_completion(analysis)

    return analysis
Ejemplo n.º 2
0
 def function146(arg1002):
     var251 = aiohttp.get_payload(function614.open('rb'))
     var251.set_content_disposition('inline', filename='test.txt')
     return web.Response(body=var251,
                         headers={
                             'content-type': 'text/binary',
                         })
Ejemplo n.º 3
0
 async def handler(request):
     pl = aiohttp.get_payload(fname.open('rb'))
     pl.set_content_disposition('inline', filename='test.txt')
     return web.Response(
         body=pl, headers={'content-type': 'text/binary'})
Ejemplo n.º 4
0
 def handler(request):
     pl = aiohttp.get_payload(fname.open('rb'))
     pl.set_content_disposition('inline', filename='test.txt')
     return web.Response(
         body=pl, headers={'content-type': 'text/binary'})