comparison mercurial/byterange.py @ 34466:1232f7fa00c3

cleanup: use urllibcompat for renamed methods on urllib request objects Differential Revision: https://phab.mercurial-scm.org/D891
author Augie Fackler <augie@google.com>
date Sun, 01 Oct 2017 12:14:21 -0400
parents 635553ca6eb9
children 6f62a1c3e11d
comparison
equal deleted inserted replaced
34465:80d4681150b9 34466:1232f7fa00c3
26 import re 26 import re
27 import socket 27 import socket
28 import stat 28 import stat
29 29
30 from . import ( 30 from . import (
31 urllibcompat,
31 util, 32 util,
32 ) 33 )
33 34
34 urlerr = util.urlerr 35 urlerr = util.urlerr
35 urlreq = util.urlreq 36 urlreq = util.urlreq
212 """FileHandler subclass that adds Range support. 213 """FileHandler subclass that adds Range support.
213 This class handles Range headers exactly like an HTTP 214 This class handles Range headers exactly like an HTTP
214 server would. 215 server would.
215 """ 216 """
216 def open_local_file(self, req): 217 def open_local_file(self, req):
217 host = req.get_host() 218 host = urllibcompat.gethost(req)
218 file = req.get_selector() 219 file = urllibcompat.getselector(req)
219 localfile = urlreq.url2pathname(file) 220 localfile = urlreq.url2pathname(file)
220 stats = os.stat(localfile) 221 stats = os.stat(localfile)
221 size = stats[stat.ST_SIZE] 222 size = stats[stat.ST_SIZE]
222 modified = email.Utils.formatdate(stats[stat.ST_MTIME]) 223 modified = email.Utils.formatdate(stats[stat.ST_MTIME])
223 mtype = mimetypes.guess_type(file)[0] 224 mtype = mimetypes.guess_type(file)[0]
250 # follows: 251 # follows:
251 # -- range support modifications start/end here 252 # -- range support modifications start/end here
252 253
253 class FTPRangeHandler(urlreq.ftphandler): 254 class FTPRangeHandler(urlreq.ftphandler):
254 def ftp_open(self, req): 255 def ftp_open(self, req):
255 host = req.get_host() 256 host = urllibcompat.gethost(req)
256 if not host: 257 if not host:
257 raise IOError('ftp error', 'no host given') 258 raise IOError('ftp error', 'no host given')
258 host, port = splitport(host) 259 host, port = splitport(host)
259 if port is None: 260 if port is None:
260 port = ftplib.FTP_PORT 261 port = ftplib.FTP_PORT