Пример #1
0
async def put(url: str,
              log_404=True,
              json=None,
              data=None,
              **kwargs: Any) -> Optional[ClientResponse]:
    if HTTP_PREFIX is None:
        raise OpenhabConnectionNotSetUpError()

    if IS_READ_ONLY or not IS_ONLINE:
        return None

    assert not url.startswith('/'), url
    url = f'{HTTP_PREFIX}/rest/{url}/'

    mgr = _RequestContextManager(
        HTTP_SESSION._request(METH_PUT,
                              url,
                              allow_redirects=HTTP_ALLOW_REDIRECTS,
                              data=data,
                              json=json,
                              **kwargs))

    if data is None:
        data = json
    return await check_response(mgr, log_404=log_404, sent_data=data)
Пример #2
0
 def _request(self,
              method: str,
              url: StrOrURL,
              *args,
              allow_retries: bool = False,
              max_retries: int = 5,
              allow_redirects: bool = True,
              **kwargs: Any) -> "aiohttp.client._RequestContextManager":
     uri = self._full_url(url)
     if allow_retries:
         resp = _RequestContextManager(
             self._retry_requests(lambda: self.session.request(
                 method,
                 uri,
                 *args,
                 allow_redirects=allow_redirects,
                 **kwargs),
                                  max_retries=max_retries))
     else:
         resp = self.session.request(method,
                                     uri,
                                     *args,
                                     allow_redirects=allow_redirects,
                                     **kwargs)
     return resp
Пример #3
0
async def put(url: str,
              log_404=True,
              json=None,
              data=None,
              **kwargs: Any) -> Optional[ClientResponse]:
    if HTTP_PREFIX is None:
        raise OpenhabConnectionNotSetUpError()

    if IS_READ_ONLY or not IS_ONLINE:
        return None

    assert not url.startswith('/'), url
    url = f'{HTTP_PREFIX}/rest/{url}/'

    # todo: remove this workaround once there is a fix in aiohttp
    headers = None
    if data is not None:
        headers = {'Content-Type': 'text/plain; charset=utf-8'}

    mgr = _RequestContextManager(
        HTTP_SESSION._request(METH_PUT,
                              url,
                              allow_redirects=HTTP_ALLOW_REDIRECTS,
                              headers=headers,
                              data=data,
                              json=json,
                              **kwargs))

    if data is None:
        data = json
    return await check_response(mgr, log_404=log_404, sent_data=data)
Пример #4
0
    def request(self, method: str, path: str, **kwargs: Any) -> _RequestContextManager:
        """Routes a request to tested http server.

        The interface is identical to aiohttp.ClientSession.request,
        except the loop kwarg is overridden by the instance used by the
        test server.

        """
        return _RequestContextManager(self._request(method, path, **kwargs))
Пример #5
0
async def get(url: str, log_404=True, **kwargs: Any) -> ClientResponse:
    if HTTP_PREFIX is None:
        raise OpenhabConnectionNotSetUpError()

    assert not url.startswith('/'), url
    url = f'{HTTP_PREFIX}/rest/{url}/'

    mgr = _RequestContextManager(
        HTTP_SESSION._request(METH_GET,
                              url,
                              allow_redirects=HTTP_ALLOW_REDIRECTS,
                              **kwargs))
    return await check_response(mgr, log_404=log_404)
 def delete(self, url, *args, **kwargs):
     updated_kwargs = self._update_headers(kwargs)
     self.calls.append(call.delete(url, *args, **updated_kwargs))
     return _RequestContextManager(self._get_stored_value(url, 'delete'))
Пример #7
0
 def delete(self, path, *args, **kwargs):
     """Perform an HTTP PATCH request."""
     return _RequestContextManager(
         self.request(hdrs.METH_DELETE, path, *args, **kwargs)
     )
Пример #8
0
 def patch(self, path, *args, **kwargs):
     """Perform an HTTP PATCH request."""
     return _RequestContextManager(
         self.request(hdrs.METH_PATCH, path, *args, **kwargs)
     )
Пример #9
0
 def patch(self, path, *args, **kwargs):
     """Perform an HTTP PATCH request."""
     return _RequestContextManager(
         self.request(hdrs.METH_PATCH, path, *args, **kwargs))
Пример #10
0
 def post(self, url, *args, **kwargs):
     updated_kwargs = self._update_headers(kwargs)
     self.calls.append(call.post(url, *args, **updated_kwargs))
     return _RequestContextManager(self._get_stored_value(url, "post"))
Пример #11
0
 def head(self, path: str, **kwargs: Any) -> _RequestContextManager:
     """Perform an HTTP HEAD request."""
     return _RequestContextManager(self._request(hdrs.METH_HEAD, path, **kwargs))
Пример #12
0
 def post(self, path: str, **kwargs: Any) -> _RequestContextManager:
     """Perform an HTTP POST request."""
     return _RequestContextManager(
         self.request(hdrs.METH_POST, path, **kwargs)
     )
Пример #13
0
 def get(self, path: str, **kwargs: Any) -> _RequestContextManager:
     """Perform an HTTP GET request."""
     return _RequestContextManager(
         self.request(hdrs.METH_GET, path, **kwargs))
Пример #14
0
 def request(self, method, url, *args, **kwargs):
     return _RequestContextManager(self._request(
         method, url, *args, **kwargs
     ))
Пример #15
0
 def post(self, url, **kwargs):
     """POST request."""
     return _RequestContextManager(self.request(HTTP_POST, url, **kwargs))
Пример #16
0
 def get(self, url, **kwargs):
     """GET Request."""
     return _RequestContextManager(self.request(HTTP_GET, url, **kwargs))
Пример #17
0
 def delete(self, path: str, **kwargs: Any) -> _RequestContextManager:
     """Perform an HTTP PATCH request."""
     return _RequestContextManager(self._request(hdrs.METH_DELETE, path, **kwargs))
Пример #18
0
 def options(self, path: str, **kwargs: Any) -> _RequestContextManager:
     """Perform an HTTP OPTIONS request."""
     return _RequestContextManager(self._request(hdrs.METH_OPTIONS, path, **kwargs))
Пример #19
0
 def head(self, path, *args, **kwargs):
     """Perform an HTTP HEAD request."""
     return _RequestContextManager(
         self.request(hdrs.METH_HEAD, path, *args, **kwargs))
Пример #20
0
 def put(self, path: str, **kwargs: Any) -> _RequestContextManager:
     """Perform an HTTP PUT request."""
     return _RequestContextManager(self._request(hdrs.METH_PUT, path, **kwargs))
Пример #21
0
 def request(self, method, url, **kwargs):
     return _RequestContextManager(self._request(method, url, **kwargs))
Пример #22
0
 def options(self, path, *args, **kwargs):
     """Perform an HTTP OPTIONS request."""
     return _RequestContextManager(
         self.request(hdrs.METH_OPTIONS, path, *args, **kwargs))
Пример #23
0
 def options(self, path, *args, **kwargs):
     """Perform an HTTP OPTIONS request."""
     return _RequestContextManager(
         self.request(hdrs.METH_OPTIONS, path, *args, **kwargs)
     )
Пример #24
0
 def put(self, path, *args, **kwargs):
     """Perform an HTTP PUT request."""
     return _RequestContextManager(
         self.request(hdrs.METH_PUT, path, *args, **kwargs))
Пример #25
0
 def head(self, path, *args, **kwargs):
     """Perform an HTTP HEAD request."""
     return _RequestContextManager(
         self.request(hdrs.METH_HEAD, path, *args, **kwargs)
     )
Пример #26
0
 def delete(self, path, *args, **kwargs):
     """Perform an HTTP PATCH request."""
     return _RequestContextManager(
         self.request(hdrs.METH_DELETE, path, *args, **kwargs))
Пример #27
0
 def put(self, path, *args, **kwargs):
     """Perform an HTTP PUT request."""
     return _RequestContextManager(
         self.request(hdrs.METH_PUT, path, *args, **kwargs)
     )