Module gpycat.session

Expand source code
import json

from requests import Session


class GfySession(Session):
    @staticmethod
    def _check_json_body(**kwargs):
        data = kwargs.get("data")
        if isinstance(data, dict):
            data = json.dumps(data)
            kwargs.update({"data": data})
        return kwargs

    def post(self, *args, **kwargs):
        kwargs = self._check_json_body(**kwargs)
        return super().post(*args, **kwargs)

    def put(self, *args, **kwargs):
        kwargs = self._check_json_body(**kwargs)
        return super().put(*args, **kwargs)

    def patch(self, *args, **kwargs):
        kwargs = self._check_json_body(**kwargs)
        return super().patch(*args, **kwargs)

Classes

class GfySession

A Requests session.

Provides cookie persistence, connection-pooling, and configuration.

Basic Usage::

import requests s = requests.Session() s.get('https://httpbin.org/get')

Or as a context manager::

with requests.Session() as s: … s.get('https://httpbin.org/get')

Expand source code
class GfySession(Session):
    @staticmethod
    def _check_json_body(**kwargs):
        data = kwargs.get("data")
        if isinstance(data, dict):
            data = json.dumps(data)
            kwargs.update({"data": data})
        return kwargs

    def post(self, *args, **kwargs):
        kwargs = self._check_json_body(**kwargs)
        return super().post(*args, **kwargs)

    def put(self, *args, **kwargs):
        kwargs = self._check_json_body(**kwargs)
        return super().put(*args, **kwargs)

    def patch(self, *args, **kwargs):
        kwargs = self._check_json_body(**kwargs)
        return super().patch(*args, **kwargs)

Ancestors

  • requests.sessions.Session
  • requests.sessions.SessionRedirectMixin

Methods

def patch(self, *args, **kwargs)

Sends a PATCH request. Returns :class:Response object.

:param url: URL for the new :class:Request object. :param data: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:Request. :param **kwargs: Optional arguments that request takes. :rtype: requests.Response

Expand source code
def patch(self, *args, **kwargs):
    kwargs = self._check_json_body(**kwargs)
    return super().patch(*args, **kwargs)
def post(self, *args, **kwargs)

Sends a POST request. Returns :class:Response object.

:param url: URL for the new :class:Request object. :param data: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:Request. :param json: (optional) json to send in the body of the :class:Request. :param **kwargs: Optional arguments that request takes. :rtype: requests.Response

Expand source code
def post(self, *args, **kwargs):
    kwargs = self._check_json_body(**kwargs)
    return super().post(*args, **kwargs)
def put(self, *args, **kwargs)

Sends a PUT request. Returns :class:Response object.

:param url: URL for the new :class:Request object. :param data: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:Request. :param **kwargs: Optional arguments that request takes. :rtype: requests.Response

Expand source code
def put(self, *args, **kwargs):
    kwargs = self._check_json_body(**kwargs)
    return super().put(*args, **kwargs)