##// END OF EJS Templates
chgserver: document why we don't merge mtimehash and confighash...
chgserver: document why we don't merge mtimehash and confighash People may get confused about chg's mtimehash and confighash design: why two hashes instead of just one. This patch adds text addressing the concern.

File last commit:

r29455:0c741fd6 default
r29462:71ed5a3e default
Show More
pycompat.py
159 lines | 3.3 KiB | text/x-python | PythonLexer
timeless
pycompat: add empty and queue to handle py3 divergence...
r28818 # pycompat.py - portability shim for python 3
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
"""Mercurial portability shim for python 3.
This contains aliases to hide python version-specific details from the core.
"""
from __future__ import absolute_import
try:
Pulkit Goyal
py3: conditionalize cPickle import by adding in util...
r29324 import cPickle as pickle
pickle.dumps
except ImportError:
import pickle
Pierre-Yves David
pyflakes: use pycompat.pickles to prevent error...
r29405 pickle.dumps # silence pyflakes
Pulkit Goyal
py3: conditionalize cPickle import by adding in util...
r29324
try:
Pulkit Goyal
py3: conditionalize httplib import...
r29455 import httplib
httplib.HTTPException
except ImportError:
import http.client as httplib
httplib.HTTPException
try:
Pulkit Goyal
py3: conditionalize SocketServer import...
r29433 import SocketServer as socketserver
socketserver.ThreadingMixIn
except ImportError:
import socketserver
socketserver.ThreadingMixIn
try:
Pulkit Goyal
py3: conditionalize xmlrpclib import...
r29432 import xmlrpclib
xmlrpclib.Transport
except ImportError:
import xmlrpc.client as xmlrpclib
xmlrpclib.Transport
try:
Pulkit Goyal
py3: conditionalize the urlparse import...
r29431 import urlparse
urlparse.urlparse
except ImportError:
import urllib.parse as urlparse
urlparse.urlparse
try:
timeless
pycompat: add util.stringio to handle py3 divergence...
r28835 import cStringIO as io
stringio = io.StringIO
except ImportError:
import io
stringio = io.StringIO
try:
timeless
pycompat: add empty and queue to handle py3 divergence...
r28818 import Queue as _queue
timeless
pycompat: fix demand import handling of Queue...
r28833 _queue.Queue
timeless
pycompat: add empty and queue to handle py3 divergence...
r28818 except ImportError:
import queue as _queue
empty = _queue.Empty
queue = _queue.Queue
timeless
pycompat: alias xrange to range in py3
r28834
timeless
pycompat: add util.urlerr util.urlreq classes for py3 compat...
r28882 class _pycompatstub(object):
pass
def _alias(alias, origin, items):
""" populate a _pycompatstub
copies items from origin to alias
"""
def hgcase(item):
return item.replace('_', '').lower()
for item in items:
try:
setattr(alias, hgcase(item), getattr(origin, item))
except AttributeError:
pass
urlreq = _pycompatstub()
urlerr = _pycompatstub()
try:
import urllib2
import urllib
_alias(urlreq, urllib, (
"addclosehook",
"addinfourl",
"ftpwrapper",
"pathname2url",
"quote",
"splitattr",
"splitpasswd",
"splitport",
"splituser",
"unquote",
"url2pathname",
"urlencode",
"urlencode",
))
_alias(urlreq, urllib2, (
"AbstractHTTPHandler",
"BaseHandler",
"build_opener",
"FileHandler",
"FTPHandler",
"HTTPBasicAuthHandler",
"HTTPDigestAuthHandler",
"HTTPHandler",
"HTTPPasswordMgrWithDefaultRealm",
"HTTPSHandler",
"install_opener",
"ProxyHandler",
"Request",
"urlopen",
))
_alias(urlerr, urllib2, (
"HTTPError",
"URLError",
))
except ImportError:
import urllib.request
_alias(urlreq, urllib.request, (
"AbstractHTTPHandler",
"addclosehook",
"addinfourl",
"BaseHandler",
"build_opener",
"FileHandler",
"FTPHandler",
"ftpwrapper",
"HTTPHandler",
"HTTPSHandler",
"install_opener",
"pathname2url",
"HTTPBasicAuthHandler",
"HTTPDigestAuthHandler",
Gregory Szorc
pycompat: add HTTPPasswordMgrWithDefaultRealm to Python 3 block...
r29414 "HTTPPasswordMgrWithDefaultRealm",
timeless
pycompat: add util.urlerr util.urlreq classes for py3 compat...
r28882 "ProxyHandler",
"quote",
"Request",
"splitattr",
"splitpasswd",
"splitport",
"splituser",
"unquote",
"url2pathname",
"urlopen",
))
import urllib.error
_alias(urlerr, urllib.error, (
"HTTPError",
"URLError",
))
timeless
pycompat: alias xrange to range in py3
r28834 try:
xrange
except NameError:
import builtins
builtins.xrange = range