prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Verify if domain name has more than 50 chars
  fixes: #4976
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pulpcore/app/viewsets/upload.py`
  Content:
  ```
  1 import re
  2 from datetime import datetime
  3 
  4 from gettext import gettext as _
  5 from drf_yasg.utils import swagger_auto_schema
  6 from drf_yasg.openapi import Parameter
  7 from rest_framework import mixins, serializers
  8 from rest_framework.decorators import detail_route
  9 from rest_framework.response import Response
  10 
  11 from pulpcore.app.models import Upload
  12 from pulpcore.app.serializers import UploadChunkSerializer, UploadCommitSerializer, UploadSerializer
  13 from pulpcore.app.viewsets.base import NamedModelViewSet
  14 
  15 
  16 class UploadViewSet(NamedModelViewSet,
  17                     mixins.CreateModelMixin,
  18                     mixins.RetrieveModelMixin,
  19                     mixins.UpdateModelMixin,
  20                     mixins.ListModelMixin):
  21     """View for chunked uploads."""
  22     endpoint_name = 'uploads'
  23     queryset = Upload.objects.all()
  24     serializer_class = UploadSerializer
  25     http_method_names = ['get', 'post', 'head', 'put']
  26 
  27     content_range_pattern = r'^bytes (\d+)-(\d+)/(\d+|[*])$'
  28     content_range_parameter = \
  29         Parameter(name='Content-Range', in_='header', required=True, type='string',
  30                   pattern=content_range_pattern,
  31                   description='The Content-Range header specifies the location of the file chunk '
  32                               'within the file.')
  33 
  34     @swagger_auto_schema(operation_summary="Upload a file chunk",
  35                          request_body=UploadChunkSerializer,
  36                          manual_parameters=[content_range_parameter],
  37                          responses={200: UploadSerializer})
  38     def update(self, request, pk=None):
  39         """
  40         Upload a chunk for an upload.
  41         """
  42         upload = self.get_object()
  43 
  44         if upload.completed is not None:
  45             raise serializers.ValidationError(_("Cannot upload chunk for a completed upload."))
  46 
  47         try:
  48             chunk = request.data['file']
  49         except KeyError:
  50             raise serializers.ValidationError(_("Missing 'file' parameter."))
  51 
  52         content_range = request.META.get('HTTP_CONTENT_RANGE', '')
  53         match = re.compile(self.content_range_pattern).match(content_range)
  54         if not match:
  55             raise serializers.ValidationError(_("Invalid or missing content range header."))
  56         start = int(match[1])
  57         end = int(match[2])
  58 
  59         if (end - start + 1) != len(chunk):
  60             raise serializers.ValidationError(_("Chunk size does not match content range."))
  61 
  62         if end > upload.size - 1:
  63             raise serializers.ValidationError(_("End byte is greater than upload size."))
  64 
  65         upload.append(chunk, start)
  66 
  67         serializer = UploadSerializer(upload, context={'request': request})
  68         return Response(serializer.data)
  69 
  70     @swagger_auto_schema(operation_summary="Finish an Upload",
  71                          request_body=UploadCommitSerializer,
  72                          responses={200: UploadSerializer})
  73     @detail_route(methods=('put',))
  74     def commit(self, request, pk):
  75         """
  76         Commit the upload and mark it as completed.
  77         """
  78         upload = self.get_object()
  79 
  80         try:
  81             sha256 = request.data['sha256']
  82         except KeyError:
  83             raise serializers.ValidationError(_("Checksum not supplied."))
  84 
  85         if sha256 != upload.sha256:
  86             raise serializers.ValidationError(_("Checksum does not match upload."))
  87 
  88         if upload.completed is not None:
  89             raise serializers.ValidationError(_("Upload is already complete."))
  90 
  91         upload.completed = datetime.now()
  92         upload.save()
  93 
  94         serializer = UploadSerializer(upload, context={'request': request})
  95         return Response(serializer.data)
  96
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/pulpcore/app/viewsets/upload.py b/pulpcore/app/viewsets/upload.py
  --- a/pulpcore/app/viewsets/upload.py
  +++ b/pulpcore/app/viewsets/upload.py
  @@ -10,19 +10,33 @@
   
   from pulpcore.app.models import Upload
   from pulpcore.app.serializers import UploadChunkSerializer, UploadCommitSerializer, UploadSerializer
  -from pulpcore.app.viewsets.base import NamedModelViewSet
  +from pulpcore.app.viewsets import BaseFilterSet
  +from pulpcore.app.viewsets.base import DATETIME_FILTER_OPTIONS, NamedModelViewSet
  +from pulpcore.app.viewsets.custom_filters import IsoDateTimeFilter
  +
  +
  +class UploadFilter(BaseFilterSet):
  +    completed = IsoDateTimeFilter(field_name='completed')
  +
  +    class Meta:
  +        model = Upload
  +        fields = {
  +            'completed': DATETIME_FILTER_OPTIONS + ['isnull']
  +        }
   
   
   class UploadViewSet(NamedModelViewSet,
                       mixins.CreateModelMixin,
                       mixins.RetrieveModelMixin,
                       mixins.UpdateModelMixin,
  +                    mixins.DestroyModelMixin,
                       mixins.ListModelMixin):
       """View for chunked uploads."""
       endpoint_name = 'uploads'
       queryset = Upload.objects.all()
       serializer_class = UploadSerializer
  -    http_method_names = ['get', 'post', 'head', 'put']
  +    filterset_class = UploadFilter
  +    http_method_names = ['get', 'post', 'head', 'put', 'delete']  # remove PATCH
   
       content_range_pattern = r'^bytes (\d+)-(\d+)/(\d+|[*])$'
       content_range_parameter = \
  
verification_info: {"golden_diff": "diff --git a/pulpcore/app/viewsets/upload.py b/pulpcore/app/viewsets/upload.py\n--- a/pulpcore/app/viewsets/upload.py\n+++ b/pulpcore/app/viewsets/upload.py\n@@ -10,19 +10,33 @@\n \n from pulpcore.app.models import Upload\n from pulpcore.app.serializers import UploadChunkSerializer, UploadCommitSerializer, UploadSerializer\n-from pulpcore.app.viewsets.base import NamedModelViewSet\n+from pulpcore.app.viewsets import BaseFilterSet\n+from pulpcore.app.viewsets.base import DATETIME_FILTER_OPTIONS, NamedModelViewSet\n+from pulpcore.app.viewsets.custom_filters import IsoDateTimeFilter\n+\n+\n+class UploadFilter(BaseFilterSet):\n+    completed = IsoDateTimeFilter(field_name='completed')\n+\n+    class Meta:\n+        model = Upload\n+        fields = {\n+            'completed': DATETIME_FILTER_OPTIONS + ['isnull']\n+        }\n \n \n class UploadViewSet(NamedModelViewSet,\n                     mixins.CreateModelMixin,\n                     mixins.RetrieveModelMixin,\n                     mixins.UpdateModelMixin,\n+                    mixins.DestroyModelMixin,\n                     mixins.ListModelMixin):\n     \"\"\"View for chunked uploads.\"\"\"\n     endpoint_name = 'uploads'\n     queryset = Upload.objects.all()\n     serializer_class = UploadSerializer\n-    http_method_names = ['get', 'post', 'head', 'put']\n+    filterset_class = UploadFilter\n+    http_method_names = ['get', 'post', 'head', 'put', 'delete']  # remove PATCH\n \n     content_range_pattern = r'^bytes (\\d+)-(\\d+)/(\\d+|[*])$'\n     content_range_parameter = \\\n", "issue": "Verify if domain name has more than 50 chars\nfixes: #4976\n", "before_files": [{"content": "import re\nfrom datetime import datetime\n\nfrom gettext import gettext as _\nfrom drf_yasg.utils import swagger_auto_schema\nfrom drf_yasg.openapi import Parameter\nfrom rest_framework import mixins, serializers\nfrom rest_framework.decorators import detail_route\nfrom rest_framework.response import Response\n\nfrom pulpcore.app.models import Upload\nfrom pulpcore.app.serializers import UploadChunkSerializer, UploadCommitSerializer, UploadSerializer\nfrom pulpcore.app.viewsets.base import NamedModelViewSet\n\n\nclass UploadViewSet(NamedModelViewSet,\n                    mixins.CreateModelMixin,\n                    mixins.RetrieveModelMixin,\n                    mixins.UpdateModelMixin,\n                    mixins.ListModelMixin):\n    \"\"\"View for chunked uploads.\"\"\"\n    endpoint_name = 'uploads'\n    queryset = Upload.objects.all()\n    serializer_class = UploadSerializer\n    http_method_names = ['get', 'post', 'head', 'put']\n\n    content_range_pattern = r'^bytes (\\d+)-(\\d+)/(\\d+|[*])$'\n    content_range_parameter = \\\n        Parameter(name='Content-Range', in_='header', required=True, type='string',\n                  pattern=content_range_pattern,\n                  description='The Content-Range header specifies the location of the file chunk '\n                              'within the file.')\n\n    @swagger_auto_schema(operation_summary=\"Upload a file chunk\",\n                         request_body=UploadChunkSerializer,\n                         manual_parameters=[content_range_parameter],\n                         responses={200: UploadSerializer})\n    def update(self, request, pk=None):\n        \"\"\"\n        Upload a chunk for an upload.\n        \"\"\"\n        upload = self.get_object()\n\n        if upload.completed is not None:\n            raise serializers.ValidationError(_(\"Cannot upload chunk for a completed upload.\"))\n\n        try:\n            chunk = request.data['file']\n        except KeyError:\n            raise serializers.ValidationError(_(\"Missing 'file' parameter.\"))\n\n        content_range = request.META.get('HTTP_CONTENT_RANGE', '')\n        match = re.compile(self.content_range_pattern).match(content_range)\n        if not match:\n            raise serializers.ValidationError(_(\"Invalid or missing content range header.\"))\n        start = int(match[1])\n        end = int(match[2])\n\n        if (end - start + 1) != len(chunk):\n            raise serializers.ValidationError(_(\"Chunk size does not match content range.\"))\n\n        if end > upload.size - 1:\n            raise serializers.ValidationError(_(\"End byte is greater than upload size.\"))\n\n        upload.append(chunk, start)\n\n        serializer = UploadSerializer(upload, context={'request': request})\n        return Response(serializer.data)\n\n    @swagger_auto_schema(operation_summary=\"Finish an Upload\",\n                         request_body=UploadCommitSerializer,\n                         responses={200: UploadSerializer})\n    @detail_route(methods=('put',))\n    def commit(self, request, pk):\n        \"\"\"\n        Commit the upload and mark it as completed.\n        \"\"\"\n        upload = self.get_object()\n\n        try:\n            sha256 = request.data['sha256']\n        except KeyError:\n            raise serializers.ValidationError(_(\"Checksum not supplied.\"))\n\n        if sha256 != upload.sha256:\n            raise serializers.ValidationError(_(\"Checksum does not match upload.\"))\n\n        if upload.completed is not None:\n            raise serializers.ValidationError(_(\"Upload is already complete.\"))\n\n        upload.completed = datetime.now()\n        upload.save()\n\n        serializer = UploadSerializer(upload, context={'request': request})\n        return Response(serializer.data)\n", "path": "pulpcore/app/viewsets/upload.py"}], "after_files": [{"content": "import re\nfrom datetime import datetime\n\nfrom gettext import gettext as _\nfrom drf_yasg.utils import swagger_auto_schema\nfrom drf_yasg.openapi import Parameter\nfrom rest_framework import mixins, serializers\nfrom rest_framework.decorators import detail_route\nfrom rest_framework.response import Response\n\nfrom pulpcore.app.models import Upload\nfrom pulpcore.app.serializers import UploadChunkSerializer, UploadCommitSerializer, UploadSerializer\nfrom pulpcore.app.viewsets import BaseFilterSet\nfrom pulpcore.app.viewsets.base import DATETIME_FILTER_OPTIONS, NamedModelViewSet\nfrom pulpcore.app.viewsets.custom_filters import IsoDateTimeFilter\n\n\nclass UploadFilter(BaseFilterSet):\n    completed = IsoDateTimeFilter(field_name='completed')\n\n    class Meta:\n        model = Upload\n        fields = {\n            'completed': DATETIME_FILTER_OPTIONS + ['isnull']\n        }\n\n\nclass UploadViewSet(NamedModelViewSet,\n                    mixins.CreateModelMixin,\n                    mixins.RetrieveModelMixin,\n                    mixins.UpdateModelMixin,\n                    mixins.DestroyModelMixin,\n                    mixins.ListModelMixin):\n    \"\"\"View for chunked uploads.\"\"\"\n    endpoint_name = 'uploads'\n    queryset = Upload.objects.all()\n    serializer_class = UploadSerializer\n    filterset_class = UploadFilter\n    http_method_names = ['get', 'post', 'head', 'put', 'delete']  # remove PATCH\n\n    content_range_pattern = r'^bytes (\\d+)-(\\d+)/(\\d+|[*])$'\n    content_range_parameter = \\\n        Parameter(name='Content-Range', in_='header', required=True, type='string',\n                  pattern=content_range_pattern,\n                  description='The Content-Range header specifies the location of the file chunk '\n                              'within the file.')\n\n    @swagger_auto_schema(operation_summary=\"Upload a file chunk\",\n                         request_body=UploadChunkSerializer,\n                         manual_parameters=[content_range_parameter],\n                         responses={200: UploadSerializer})\n    def update(self, request, pk=None):\n        \"\"\"\n        Upload a chunk for an upload.\n        \"\"\"\n        upload = self.get_object()\n\n        if upload.completed is not None:\n            raise serializers.ValidationError(_(\"Cannot upload chunk for a completed upload.\"))\n\n        try:\n            chunk = request.data['file']\n        except KeyError:\n            raise serializers.ValidationError(_(\"Missing 'file' parameter.\"))\n\n        content_range = request.META.get('HTTP_CONTENT_RANGE', '')\n        match = re.compile(self.content_range_pattern).match(content_range)\n        if not match:\n            raise serializers.ValidationError(_(\"Invalid or missing content range header.\"))\n        start = int(match[1])\n        end = int(match[2])\n\n        if (end - start + 1) != len(chunk):\n            raise serializers.ValidationError(_(\"Chunk size does not match content range.\"))\n\n        if end > upload.size - 1:\n            raise serializers.ValidationError(_(\"End byte is greater than upload size.\"))\n\n        upload.append(chunk, start)\n\n        serializer = UploadSerializer(upload, context={'request': request})\n        return Response(serializer.data)\n\n    @swagger_auto_schema(operation_summary=\"Finish an Upload\",\n                         request_body=UploadCommitSerializer,\n                         responses={200: UploadSerializer})\n    @detail_route(methods=('put',))\n    def commit(self, request, pk):\n        \"\"\"\n        Commit the upload and mark it as completed.\n        \"\"\"\n        upload = self.get_object()\n\n        try:\n            sha256 = request.data['sha256']\n        except KeyError:\n            raise serializers.ValidationError(_(\"Checksum not supplied.\"))\n\n        if sha256 != upload.sha256:\n            raise serializers.ValidationError(_(\"Checksum does not match upload.\"))\n\n        if upload.completed is not None:\n            raise serializers.ValidationError(_(\"Upload is already complete.\"))\n\n        upload.completed = datetime.now()\n        upload.save()\n\n        serializer = UploadSerializer(upload, context={'request': request})\n        return Response(serializer.data)\n", "path": "pulpcore/app/viewsets/upload.py"}]}