from django.contrib.sites.shortcuts import get_current_site
from django.urls import reverse
from django.core.signing import TimestampSigner


class BaseEngine:
    def __init__(self):
        self.signer = TimestampSigner()

    def get_webhook_url(self):
        return "{}://{}{}?token={}".format(
            "https",
            get_current_site(None).domain,
            reverse("virus_scan:webhook"),
            self.signer.sign(self.name),
        )

    def send_scan(self, this_file, filename):
        raise NotImplementedError(
            "Provide 'send' in {name}".format(name=self.__class__.__name__)
        )

    def receive_scan(self, engine_id):
        raise NotImplementedError(
            "Provide 'receive_scan' in {name}".format(name=self.__class__.__name__)
        )

import urllib.parse

from django.contrib.sites.shortcuts import get_current_site
from django.urls import reverse
from django.core.signing import TimestampSigner


class BaseEngine:
    def __init__(self):
        self.signer = TimestampSigner()

    def get_webhook_url(self):
        return "{}://{}{}?token={}".format(
            "https",
            get_current_site(None).domain,
            reverse("virus_scan:webhook"),
            urllib.parse.quote(self.signer.sign(self.name)),
        )

    def send_scan(self, this_file, filename):
        raise NotImplementedError(
            "Provide 'send' in {name}".format(name=self.__class__.__name__)
        )

    def receive_scan(self, engine_id):
        raise NotImplementedError(
            "Provide 'receive_scan' in {name}".format(name=self.__class__.__name__)
        )

Fix urlencode in webhook url
Fix urlencode in webhook url
+ import urllib.parse
+ 
  from django.contrib.sites.shortcuts import get_current_site
  from django.urls import reverse
  from django.core.signing import TimestampSigner
  
  
  class BaseEngine:
      def __init__(self):
          self.signer = TimestampSigner()
  
      def get_webhook_url(self):
          return "{}://{}{}?token={}".format(
              "https",
              get_current_site(None).domain,
              reverse("virus_scan:webhook"),
-             self.signer.sign(self.name),
+             urllib.parse.quote(self.signer.sign(self.name)),
          )
  
      def send_scan(self, this_file, filename):
          raise NotImplementedError(
              "Provide 'send' in {name}".format(name=self.__class__.__name__)
          )
  
      def receive_scan(self, engine_id):
          raise NotImplementedError(
              "Provide 'receive_scan' in {name}".format(name=self.__class__.__name__)
          )
  
Fix urlencode in webhook url
## Code Before:
from django.contrib.sites.shortcuts import get_current_site
from django.urls import reverse
from django.core.signing import TimestampSigner


class BaseEngine:
    def __init__(self):
        self.signer = TimestampSigner()

    def get_webhook_url(self):
        return "{}://{}{}?token={}".format(
            "https",
            get_current_site(None).domain,
            reverse("virus_scan:webhook"),
            self.signer.sign(self.name),
        )

    def send_scan(self, this_file, filename):
        raise NotImplementedError(
            "Provide 'send' in {name}".format(name=self.__class__.__name__)
        )

    def receive_scan(self, engine_id):
        raise NotImplementedError(
            "Provide 'receive_scan' in {name}".format(name=self.__class__.__name__)
        )

## Instruction:
Fix urlencode in webhook url
## Code After:
import urllib.parse

from django.contrib.sites.shortcuts import get_current_site
from django.urls import reverse
from django.core.signing import TimestampSigner


class BaseEngine:
    def __init__(self):
        self.signer = TimestampSigner()

    def get_webhook_url(self):
        return "{}://{}{}?token={}".format(
            "https",
            get_current_site(None).domain,
            reverse("virus_scan:webhook"),
            urllib.parse.quote(self.signer.sign(self.name)),
        )

    def send_scan(self, this_file, filename):
        raise NotImplementedError(
            "Provide 'send' in {name}".format(name=self.__class__.__name__)
        )

    def receive_scan(self, engine_id):
        raise NotImplementedError(
            "Provide 'receive_scan' in {name}".format(name=self.__class__.__name__)
        )
