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

Method add_field

aiohttp/helpers.py:78–111  ·  view source on GitHub ↗
(self, name, value, *, content_type=None, filename=None,
                  content_transfer_encoding=None)

Source from the content-addressed store, hash-verified

76 return 'application/x-www-form-urlencoded'
77
78 def add_field(self, name, value, *, content_type=None, filename=None,
79 content_transfer_encoding=None):
80
81 if isinstance(value, io.IOBase):
82 self._is_multipart = True
83 elif isinstance(value, (bytes, bytearray, memoryview)):
84 if filename is None and content_transfer_encoding is None:
85 filename = name
86
87 type_options = multidict.MultiDict({'name': name})
88 if filename is not None and not isinstance(filename, str):
89 raise TypeError('filename must be an instance of str. '
90 'Got: %s' % filename)
91 if filename is None and isinstance(value, io.IOBase):
92 filename = guess_filename(value, name)
93 if filename is not None:
94 type_options['filename'] = filename
95 self._is_multipart = True
96
97 headers = {}
98 if content_type is not None:
99 if not isinstance(content_type, str):
100 raise TypeError('content_type must be an instance of str. '
101 'Got: %s' % content_type)
102 headers[hdrs.CONTENT_TYPE] = content_type
103 self._is_multipart = True
104 if content_transfer_encoding is not None:
105 if not isinstance(content_transfer_encoding, str):
106 raise TypeError('content_transfer_encoding must be an instance'
107 ' of str. Got: %s' % content_transfer_encoding)
108 headers[hdrs.CONTENT_TRANSFER_ENCODING] = content_transfer_encoding
109 self._is_multipart = True
110
111 self._fields.append((type_options, headers, value))
112
113 def add_fields(self, *fields):
114 to_add = list(fields)

Calls 2

guess_filenameFunction · 0.85
appendMethod · 0.80