mercurial/pycompat.py
changeset 32615 c9318beb7c1a
parent 32450 548478efc46c
child 32859 a05f3675c46a
equal deleted inserted replaced
32614:4b426ae96ff2 32615:c9318beb7c1a
   175 
   175 
   176     def raisewithtb(exc, tb):
   176     def raisewithtb(exc, tb):
   177         """Raise exception with the given traceback"""
   177         """Raise exception with the given traceback"""
   178         raise exc.with_traceback(tb)
   178         raise exc.with_traceback(tb)
   179 
   179 
       
   180     def getdoc(obj):
       
   181         """Get docstring as bytes; may be None so gettext() won't confuse it
       
   182         with _('')"""
       
   183         doc = getattr(obj, u'__doc__', None)
       
   184         if doc is None:
       
   185             return doc
       
   186         return sysbytes(doc)
       
   187 
   180     def _wrapattrfunc(f):
   188     def _wrapattrfunc(f):
   181         @functools.wraps(f)
   189         @functools.wraps(f)
   182         def w(object, name, *args):
   190         def w(object, name, *args):
   183             return f(object, sysstr(name), *args)
   191             return f(object, sysstr(name), *args)
   184         return w
   192         return w
   252                 "expect str, not %s" % type(filename).__name__)
   260                 "expect str, not %s" % type(filename).__name__)
   253 
   261 
   254     # In Python 2, fsdecode() has a very chance to receive bytes. So it's
   262     # In Python 2, fsdecode() has a very chance to receive bytes. So it's
   255     # better not to touch Python 2 part as it's already working fine.
   263     # better not to touch Python 2 part as it's already working fine.
   256     fsdecode = identity
   264     fsdecode = identity
       
   265 
       
   266     def getdoc(obj):
       
   267         return getattr(obj, '__doc__', None)
   257 
   268 
   258     def getoptb(args, shortlist, namelist):
   269     def getoptb(args, shortlist, namelist):
   259         return getopt.getopt(args, shortlist, namelist)
   270         return getopt.getopt(args, shortlist, namelist)
   260 
   271 
   261     strkwargs = identity
   272     strkwargs = identity