Mercurial > public > mercurial-scm > hg
comparison mercurial/pycompat.py @ 29566:075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
The BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer has been merged into
http.server in python 3. All of them has been merged as util.httpserver to use
in both python 2 and 3. This patch adds a regex to check-code to warn against
the use of BaseHTTPServer. Moreover this patch also includes updates to lower
part of test-check-py3-compat.t which used to remain unchanged.
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Wed, 13 Jul 2016 23:38:29 +0530 |
parents | 0c741fd6158a |
children | 06587edd1233 |
comparison
equal
deleted
inserted
replaced
29565:143d21a7343e | 29566:075146e85bb6 |
---|---|
74 try: | 74 try: |
75 setattr(alias, hgcase(item), getattr(origin, item)) | 75 setattr(alias, hgcase(item), getattr(origin, item)) |
76 except AttributeError: | 76 except AttributeError: |
77 pass | 77 pass |
78 | 78 |
79 httpserver = _pycompatstub() | |
79 urlreq = _pycompatstub() | 80 urlreq = _pycompatstub() |
80 urlerr = _pycompatstub() | 81 urlerr = _pycompatstub() |
81 try: | 82 try: |
83 import BaseHTTPServer | |
84 import CGIHTTPServer | |
85 import SimpleHTTPServer | |
82 import urllib2 | 86 import urllib2 |
83 import urllib | 87 import urllib |
84 _alias(urlreq, urllib, ( | 88 _alias(urlreq, urllib, ( |
85 "addclosehook", | 89 "addclosehook", |
86 "addinfourl", | 90 "addinfourl", |
114 )) | 118 )) |
115 _alias(urlerr, urllib2, ( | 119 _alias(urlerr, urllib2, ( |
116 "HTTPError", | 120 "HTTPError", |
117 "URLError", | 121 "URLError", |
118 )) | 122 )) |
123 _alias(httpserver, BaseHTTPServer, ( | |
124 "HTTPServer", | |
125 "BaseHTTPRequestHandler", | |
126 )) | |
127 _alias(httpserver, SimpleHTTPServer, ( | |
128 "SimpleHTTPRequestHandler", | |
129 )) | |
130 _alias(httpserver, CGIHTTPServer, ( | |
131 "CGIHTTPRequestHandler", | |
132 )) | |
119 | 133 |
120 except ImportError: | 134 except ImportError: |
121 import urllib.request | 135 import urllib.request |
122 _alias(urlreq, urllib.request, ( | 136 _alias(urlreq, urllib.request, ( |
123 "AbstractHTTPHandler", | 137 "AbstractHTTPHandler", |
149 import urllib.error | 163 import urllib.error |
150 _alias(urlerr, urllib.error, ( | 164 _alias(urlerr, urllib.error, ( |
151 "HTTPError", | 165 "HTTPError", |
152 "URLError", | 166 "URLError", |
153 )) | 167 )) |
168 import http.server | |
169 _alias(httpserver, http.server, ( | |
170 "HTTPServer", | |
171 "BaseHTTPRequestHandler", | |
172 "SimpleHTTPRequestHandler", | |
173 "CGIHTTPRequestHandler", | |
174 )) | |
154 | 175 |
155 try: | 176 try: |
156 xrange | 177 xrange |
157 except NameError: | 178 except NameError: |
158 import builtins | 179 import builtins |