MCPcopy
hub / github.com/aio-libs/aiohttp / post

Method post

aiohttp/web_reqrep.py:338–396  ·  view source on GitHub ↗

Return POST parameters.

(self)

Source from the content-addressed store, hash-verified

336
337 @asyncio.coroutine
338 def post(self):
339 """Return POST parameters."""
340 if self._post is not None:
341 return self._post
342 if self.method not in self.POST_METHODS:
343 self._post = MultiDictProxy(MultiDict())
344 return self._post
345
346 content_type = self.content_type
347 if (content_type not in ('',
348 'application/x-www-form-urlencoded',
349 'multipart/form-data')):
350 self._post = MultiDictProxy(MultiDict())
351 return self._post
352
353 body = yield from self.read()
354 content_charset = self.charset or 'utf-8'
355
356 environ = {'REQUEST_METHOD': self.method,
357 'CONTENT_LENGTH': str(len(body)),
358 'QUERY_STRING': '',
359 'CONTENT_TYPE': self.headers.get(hdrs.CONTENT_TYPE)}
360
361 fs = cgi.FieldStorage(fp=io.BytesIO(body),
362 environ=environ,
363 keep_blank_values=True,
364 encoding=content_charset)
365
366 supported_transfer_encoding = {
367 'base64': binascii.a2b_base64,
368 'quoted-printable': binascii.a2b_qp
369 }
370
371 out = MultiDict()
372 _count = 1
373 for field in fs.list or ():
374 transfer_encoding = field.headers.get(
375 hdrs.CONTENT_TRANSFER_ENCODING, None)
376 if field.filename:
377 ff = FileField(field.name,
378 field.filename,
379 field.file, # N.B. file closed error
380 field.type)
381 if self._post_files_cache is None:
382 self._post_files_cache = {}
383 self._post_files_cache[field.name+str(_count)] = field
384 _count += 1
385 out.add(field.name, ff)
386 else:
387 value = field.value
388 if transfer_encoding in supported_transfer_encoding:
389 # binascii accepts bytes
390 value = value.encode('utf-8')
391 value = supported_transfer_encoding[
392 transfer_encoding](value)
393 out.add(field.name, value)
394
395 self._post = MultiDictProxy(out)

Callers

nothing calls this directly

Calls 3

readMethod · 0.95
encodeMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected