mercurial/util.py
changeset 31950 cc70c6dbac30
parent 31946 f3b80537a70d
child 31952 a34b5e7c6683
equal deleted inserted replaced
31949:eaf3819631c2 31950:cc70c6dbac30
    36 import sys
    36 import sys
    37 import tempfile
    37 import tempfile
    38 import textwrap
    38 import textwrap
    39 import time
    39 import time
    40 import traceback
    40 import traceback
       
    41 import warnings
    41 import zlib
    42 import zlib
    42 
    43 
    43 from . import (
    44 from . import (
    44     encoding,
    45     encoding,
    45     error,
    46     error,
   153 def bitsfrom(container):
   154 def bitsfrom(container):
   154     bits = 0
   155     bits = 0
   155     for bit in container:
   156     for bit in container:
   156         bits |= bit
   157         bits |= bit
   157     return bits
   158     return bits
       
   159 
       
   160 # python 2.6 still have deprecation warning enabled by default. We do not want
       
   161 # to display anything to standard user so detect if we are running test and
       
   162 # only use python deprecation warning in this case.
       
   163 _dowarn = bool(encoding.environ.get('HGEMITWARNINGS'))
       
   164 if _dowarn:
       
   165     # explicitly unfilter our warning for python 2.7
       
   166     #
       
   167     # The option of setting PYTHONWARNINGS in the test runner was investigated.
       
   168     # However, module name set through PYTHONWARNINGS was exactly matched, so
       
   169     # we cannot set 'mercurial' and have it match eg: 'mercurial.scmutil'. This
       
   170     # makes the whole PYTHONWARNINGS thing useless for our usecase.
       
   171     warnings.filterwarnings('default', '', DeprecationWarning, 'mercurial')
       
   172     warnings.filterwarnings('default', '', DeprecationWarning, 'hgext')
       
   173     warnings.filterwarnings('default', '', DeprecationWarning, 'hgext3rd')
       
   174 
       
   175 def nouideprecwarn(msg, version, stacklevel=1):
       
   176     """Issue an python native deprecation warning
       
   177 
       
   178     This is a noop outside of tests, use 'ui.deprecwarn' when possible.
       
   179     """
       
   180     if _dowarn:
       
   181         msg += ("\n(compatibility will be dropped after Mercurial-%s,"
       
   182                 " update your code.)") % version
       
   183         warnings.warn(msg, DeprecationWarning, stacklevel + 1)
   158 
   184 
   159 DIGESTS = {
   185 DIGESTS = {
   160     'md5': hashlib.md5,
   186     'md5': hashlib.md5,
   161     'sha1': hashlib.sha1,
   187     'sha1': hashlib.sha1,
   162     'sha512': hashlib.sha512,
   188     'sha512': hashlib.sha512,