11import asyncio
22import logging
33from functools import partial
4- from gettext import gettext as _
5- from urllib .parse import urljoin
4+ from urllib .parse import urljoin , urlparse
65
76from aiohttp import ClientError , ClientResponseError
87from bandersnatch .configuration import BandersnatchConfig
1211from packaging .requirements import Requirement
1312from pypi_attestations import Provenance
1413from pypi_simple import IndexPage
15- from rest_framework import serializers
1614
1715from pulpcore .plugin .download import HttpDownloader
16+ from pulpcore .plugin .exceptions import SyncError
1817from pulpcore .plugin .models import Artifact , ProgressReport , Remote , Repository
1918from pulpcore .plugin .stages import (
2019 DeclarativeArtifact ,
2322 Stage ,
2423)
2524
25+ from pulp_python .app .exceptions import UnsupportedProtocolError
2626from pulp_python .app .models import (
2727 PackageProvenance ,
2828 PythonPackageContent ,
@@ -45,14 +45,14 @@ def sync(remote_pk, repository_pk, mirror):
4545 mirror (boolean): True for mirror mode, False for additive mode.
4646
4747 Raises:
48- serializers: ValidationError
48+ SyncError
4949
5050 """
5151 remote = PythonRemote .objects .get (pk = remote_pk )
5252 repository = Repository .objects .get (pk = repository_pk )
5353
5454 if not remote .url :
55- raise serializers . ValidationError ( detail = _ ( "A remote must have a url attribute to sync." ) )
55+ raise SyncError ( "A remote must have a url attribute to sync." )
5656
5757 first_stage = PythonBanderStage (remote )
5858 DeclarativeVersion (first_stage , repository , mirror ).create ()
@@ -115,7 +115,8 @@ async def run(self):
115115 url = self .remote .url .rstrip ("/" )
116116 downloader = self .remote .get_downloader (url = url )
117117 if not isinstance (downloader , HttpDownloader ):
118- raise ValueError ("Only HTTP(S) is supported for python syncing" )
118+ scheme = urlparse (url ).scheme
119+ raise UnsupportedProtocolError (scheme )
119120
120121 async with Master (url , allow_non_https = True ) as master :
121122 # Replace the session with the remote's downloader session
0 commit comments