1414# CONDITIONS OF ANY KIND, either express or implied. See the License for the
1515# specific language governing permissions and limitations under the License.
1616
17- from ftplib import FTP
18- from mimetypes import MimeTypes
1917import os
2018import tempfile
19+ from ftplib import FTP
20+ from mimetypes import MimeTypes
2121from urllib .parse import urlparse
2222
2323import requests
@@ -40,19 +40,18 @@ def __init__(self, location, content_type, size, url):
4040
4141def fetch_http (url , location ):
4242 """
43- Return a `Response` object built from fetching the content at a HTTP/HTTPS based `url` URL string
44- saving the content in a file at `location`
43+ Return a `Response` object built from fetching the content at a HTTP/HTTPS based
44+ `url` URL string saving the content in a file at `location`
4545 """
4646 r = requests .get (url )
47- with open (location , 'wb' ) as f :
47+ with open (location , "wb" ) as f :
4848 f .write (r .content )
4949
50- content_type = r .headers .get (' content-type' )
51- size = r .headers .get (' content-length' )
50+ content_type = r .headers .get (" content-type" )
51+ size = r .headers .get (" content-length" )
5252 size = int (size ) if size else None
5353
54- resp = Response (location = location ,
55- content_type = content_type , size = size , url = url )
54+ resp = Response (location = location , content_type = content_type , size = size , url = url )
5655
5756 return resp
5857
@@ -80,19 +79,19 @@ def fetch_ftp(url, location):
8079 content_type = None
8180
8281 ftp .cwd (dir )
83- file = ' RETR {}' .format (file )
84- with open (location , 'wb' ) as f :
82+ file = " RETR {}" .format (file )
83+ with open (location , "wb" ) as f :
8584 ftp .retrbinary (file , f .write )
8685 ftp .close ()
8786
88- resp = Response (location = location ,
89- content_type = content_type , size = size , url = url )
87+ resp = Response (location = location , content_type = content_type , size = size , url = url )
9088 return resp
9189
9290
9391def fetch (url ):
9492 """
95- Return a `Response` object built from fetching the content at the `url` URL string and store content at a temporary file.
93+ Return a `Response` object built from fetching the content at the `url` URL string and
94+ store content at a temporary file.
9695 """
9796
9897 temp = tempfile .NamedTemporaryFile (delete = False )
@@ -101,9 +100,9 @@ def fetch(url):
101100 url_parts = urlparse (url )
102101 scheme = url_parts .scheme
103102
104- fetchers = {' ftp' : fetch_ftp , ' http' : fetch_http , ' https' : fetch_http }
103+ fetchers = {" ftp" : fetch_ftp , " http" : fetch_http , " https" : fetch_http }
105104
106105 if scheme in fetchers :
107106 return fetchers .get (scheme )(url , location )
108107
109- raise Exception (' Not a supported/known scheme.' )
108+ raise Exception (" Not a supported/known scheme." )
0 commit comments