@vercel/python 4.5.0 → 4.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/vc_init.py +21 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/python",
3
- "version": "4.5.0",
3
+ "version": "4.5.1",
4
4
  "main": "./dist/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/python",
package/vc_init.py CHANGED
@@ -319,21 +319,23 @@ if 'VERCEL_IPC_FD' in os.environ:
319
319
  'raw_path': url.path.encode(),
320
320
  }
321
321
 
322
+ if 'content-length' in self.headers:
323
+ content_length = int(self.headers['content-length'])
324
+ body = self.rfile.read(content_length)
325
+ else:
326
+ body = b''
327
+
328
+ if _use_legacy_asyncio:
329
+ loop = asyncio.new_event_loop()
330
+ app_queue = asyncio.Queue(loop=loop)
331
+ else:
332
+ app_queue = asyncio.Queue()
333
+ app_queue.put_nowait({'type': 'http.request', 'body': body, 'more_body': False})
334
+
322
335
  # Prepare ASGI receive function
323
336
  async def receive():
324
- if 'content-length' in self.headers:
325
- content_length = int(self.headers['content-length'])
326
- body = self.rfile.read(content_length)
327
- return {
328
- 'type': 'http.request',
329
- 'body': body,
330
- 'more_body': False,
331
- }
332
- return {
333
- 'type': 'http.request',
334
- 'body': b'',
335
- 'more_body': False,
336
- }
337
+ message = await app_queue.get()
338
+ return message
337
339
 
338
340
  # Prepare ASGI send function
339
341
  response_started = False
@@ -352,7 +354,12 @@ if 'VERCEL_IPC_FD' in os.environ:
352
354
  self.wfile.flush()
353
355
 
354
356
  # Run the ASGI application
355
- asyncio.run(app(scope, receive, send))
357
+ asgi_instance = app(scope, receive, send)
358
+ if _use_legacy_asyncio:
359
+ asgi_task = loop.create_task(asgi_instance)
360
+ loop.run_until_complete(asgi_task)
361
+ else:
362
+ asyncio.run(asgi_instance)
356
363
 
357
364
  if 'Handler' in locals():
358
365
  server = ThreadingHTTPServer(('127.0.0.1', 0), Handler)