( data,
handler,
method,
timeout = _READ_TIMEOUT_SEC,
payload = None )
| 151 | # up; see Requests docs for details (we just pass the param along). |
| 152 | @staticmethod |
| 153 | def _TalkToHandlerAsync( data, |
| 154 | handler, |
| 155 | method, |
| 156 | timeout = _READ_TIMEOUT_SEC, |
| 157 | payload = None ): |
| 158 | def _MakeRequest( data, handler, method, timeout, payload ): |
| 159 | request_uri = _BuildUri( handler ) |
| 160 | |
| 161 | if method == 'POST': |
| 162 | sent_data = _ToUtf8Json( data ) |
| 163 | headers = BaseRequest._ExtraHeaders( method, |
| 164 | request_uri, |
| 165 | sent_data ) |
| 166 | _logger.debug( 'POST %s\n%s\n%s', request_uri, headers, sent_data ) |
| 167 | else: |
| 168 | headers = BaseRequest._ExtraHeaders( method, request_uri ) |
| 169 | if payload: |
| 170 | request_uri += ToBytes( f'?{ urlencode( payload ) }' ) |
| 171 | |
| 172 | _logger.debug( 'GET %s (%s)\n%s', request_uri, payload, headers ) |
| 173 | return urlopen( |
| 174 | Request( |
| 175 | ToUnicode( request_uri ), |
| 176 | data = sent_data if data else None, |
| 177 | headers = headers, |
| 178 | method = method ), |
| 179 | timeout = max( _CONNECT_TIMEOUT_SEC, timeout ) ) |
| 180 | |
| 181 | |
| 182 | return BaseRequest.Executor().submit( |
| 183 | _MakeRequest, |
| 184 | data, |
| 185 | handler, |
| 186 | method, |
| 187 | timeout, |
| 188 | payload ) |
| 189 | |
| 190 | |
| 191 | @staticmethod |
no test coverage detected