Plex plugin to to play various online streams (mostly Latvian).

api.py 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. # -*- coding: utf-8 -*-
  2. """
  3. requests.api
  4. ~~~~~~~~~~~~
  5. This module implements the Requests API.
  6. :copyright: (c) 2012 by Kenneth Reitz.
  7. :license: Apache2, see LICENSE for more details.
  8. """
  9. from . import sessions
  10. def request(method, url, **kwargs):
  11. """Constructs and sends a :class:`Request <Request>`.
  12. :param method: method for the new :class:`Request` object.
  13. :param url: URL for the new :class:`Request` object.
  14. :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.
  15. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
  16. :param json: (optional) json data to send in the body of the :class:`Request`.
  17. :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
  18. :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.
  19. :param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload.
  20. ``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')``
  21. or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string
  22. defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers
  23. to add for the file.
  24. :param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.
  25. :param timeout: (optional) How long to wait for the server to send data
  26. before giving up, as a float, or a :ref:`(connect timeout, read
  27. timeout) <timeouts>` tuple.
  28. :type timeout: float or tuple
  29. :param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.
  30. :type allow_redirects: bool
  31. :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
  32. :param verify: (optional) whether the SSL cert will be verified. A CA_BUNDLE path can also be provided. Defaults to ``True``.
  33. :param stream: (optional) if ``False``, the response content will be immediately downloaded.
  34. :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.
  35. :return: :class:`Response <Response>` object
  36. :rtype: requests.Response
  37. Usage::
  38. >>> import requests
  39. >>> req = requests.request('GET', 'http://httpbin.org/get')
  40. <Response [200]>
  41. """
  42. # By using the 'with' statement we are sure the session is closed, thus we
  43. # avoid leaving sockets open which can trigger a ResourceWarning in some
  44. # cases, and look like a memory leak in others.
  45. with sessions.Session() as session:
  46. return session.request(method=method, url=url, **kwargs)
  47. def get(url, params=None, **kwargs):
  48. """Sends a GET request.
  49. :param url: URL for the new :class:`Request` object.
  50. :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.
  51. :param \*\*kwargs: Optional arguments that ``request`` takes.
  52. :return: :class:`Response <Response>` object
  53. :rtype: requests.Response
  54. """
  55. kwargs.setdefault('allow_redirects', True)
  56. return request('get', url, params=params, **kwargs)
  57. def options(url, **kwargs):
  58. """Sends a OPTIONS request.
  59. :param url: URL for the new :class:`Request` object.
  60. :param \*\*kwargs: Optional arguments that ``request`` takes.
  61. :return: :class:`Response <Response>` object
  62. :rtype: requests.Response
  63. """
  64. kwargs.setdefault('allow_redirects', True)
  65. return request('options', url, **kwargs)
  66. def head(url, **kwargs):
  67. """Sends a HEAD request.
  68. :param url: URL for the new :class:`Request` object.
  69. :param \*\*kwargs: Optional arguments that ``request`` takes.
  70. :return: :class:`Response <Response>` object
  71. :rtype: requests.Response
  72. """
  73. kwargs.setdefault('allow_redirects', False)
  74. return request('head', url, **kwargs)
  75. def post(url, data=None, json=None, **kwargs):
  76. """Sends a POST request.
  77. :param url: URL for the new :class:`Request` object.
  78. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
  79. :param json: (optional) json data to send in the body of the :class:`Request`.
  80. :param \*\*kwargs: Optional arguments that ``request`` takes.
  81. :return: :class:`Response <Response>` object
  82. :rtype: requests.Response
  83. """
  84. return request('post', url, data=data, json=json, **kwargs)
  85. def put(url, data=None, **kwargs):
  86. """Sends a PUT request.
  87. :param url: URL for the new :class:`Request` object.
  88. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
  89. :param \*\*kwargs: Optional arguments that ``request`` takes.
  90. :return: :class:`Response <Response>` object
  91. :rtype: requests.Response
  92. """
  93. return request('put', url, data=data, **kwargs)
  94. def patch(url, data=None, **kwargs):
  95. """Sends a PATCH request.
  96. :param url: URL for the new :class:`Request` object.
  97. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
  98. :param \*\*kwargs: Optional arguments that ``request`` takes.
  99. :return: :class:`Response <Response>` object
  100. :rtype: requests.Response
  101. """
  102. return request('patch', url, data=data, **kwargs)
  103. def delete(url, **kwargs):
  104. """Sends a DELETE request.
  105. :param url: URL for the new :class:`Request` object.
  106. :param \*\*kwargs: Optional arguments that ``request`` takes.
  107. :return: :class:`Response <Response>` object
  108. :rtype: requests.Response
  109. """
  110. return request('delete', url, **kwargs)