[PATCH 4 of 7] byterange: use absolute_import
Gregory Szorc
gregory.szorc at gmail.com
Tue Dec 22 18:31:47 CST 2015
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1450762934 28800
# Mon Dec 21 21:42:14 2015 -0800
# Node ID b2b3e0f020a6f11c742cbf8fc76f702a92124818
# Parent b1e8174e8a360db3f5e5340ea555c9ef0a1f43e7
byterange: use absolute_import
There were a lot of imports scattered around this file. They have been
consolidated at the top of the file where they belong.
diff --git a/mercurial/byterange.py b/mercurial/byterange.py
--- a/mercurial/byterange.py
+++ b/mercurial/byterange.py
@@ -16,13 +16,27 @@
# Copyright 2002-2004 Michael D. Stenner, Ryan Tomayko
# $Id: byterange.py,v 1.9 2005/02/14 21:55:07 mstenner Exp $
+from __future__ import absolute_import
+
+import email
+import ftplib
+import mimetypes
import os
+import re
+import socket
import stat
import urllib
import urllib2
-import email.Utils
+
+addclosehook = urllib.addclosehook
+addinfourl = urllib.addinfourl
+splitattr = urllib.splitattr
+splitpasswd = urllib.splitpasswd
+splitport = urllib.splitport
+splituser = urllib.splituser
+unquote = urllib.unquote
class RangeError(IOError):
"""Error raised when an unsatisfiable range is requested."""
pass
@@ -195,10 +209,8 @@ class FileRangeHandler(urllib2.FileHandl
This class handles Range headers exactly like an HTTP
server would.
"""
def open_local_file(self, req):
- import mimetypes
- import email
host = req.get_host()
file = req.get_selector()
localfile = urllib.url2pathname(file)
stats = os.stat(localfile)
@@ -233,15 +245,8 @@ class FileRangeHandler(urllib2.FileHandl
# Code modifications for range support have been commented as
# follows:
# -- range support modifications start/end here
-from urllib import splitport, splituser, splitpasswd, splitattr, \
- unquote, addclosehook, addinfourl
-import ftplib
-import socket
-import mimetypes
-import email
-
class FTPRangeHandler(urllib2.FTPHandler):
def ftp_open(self, req):
host = req.get_host()
if not host:
@@ -405,9 +410,8 @@ def range_header_to_tuple(range_header):
global _rangere
if range_header is None:
return None
if _rangere is None:
- import re
_rangere = re.compile(r'^bytes=(\d{1,})-(\d*)')
match = _rangere.match(range_header)
if match:
tup = range_tuple_normalize(match.group(1, 2))
diff --git a/tests/test-check-py3-compat.t b/tests/test-check-py3-compat.t
--- a/tests/test-check-py3-compat.t
+++ b/tests/test-check-py3-compat.t
@@ -97,9 +97,8 @@
hgext/zeroconf/Zeroconf.py requires print_function
hgext/zeroconf/__init__.py not using absolute_import
i18n/check-translation.py not using absolute_import
i18n/polib.py not using absolute_import
- mercurial/byterange.py not using absolute_import
mercurial/cmdutil.py not using absolute_import
mercurial/commands.py not using absolute_import
mercurial/context.py not using absolute_import
mercurial/dispatch.py requires print_function
More information about the Mercurial-devel
mailing list