Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/pydoc.py

    r2 r391  
    3838__date__ = "26 February 2001"
    3939
    40 __version__ = "$Revision: 78208 $"
     40__version__ = "$Revision: 88564 $"
    4141__credits__ = """Guido van Rossum, for an excellent programming language.
    4242Tommy Burnette, the original creator of manpy.
     
    5353#     path will be displayed.
    5454
    55 import sys, imp, os, re, types, inspect, __builtin__, pkgutil
     55import sys, imp, os, re, types, inspect, __builtin__, pkgutil, warnings
    5656from repr import Repr
    5757from string import expandtabs, find, join, lower, split, strip, rfind, rstrip
     
    157157    return yes, no
    158158
    159 def visiblename(name, all=None):
     159def visiblename(name, all=None, obj=None):
    160160    """Decide whether to show documentation on a variable."""
    161161    # Certain special names are redundant.
     
    165165    # Private names are hidden, but special names are displayed.
    166166    if name.startswith('__') and name.endswith('__'): return 1
     167    # Namedtuples have public fields and methods with a single leading underscore
     168    if name.startswith('_') and hasattr(obj, '_fields'):
     169        return 1
    167170    if all is not None:
    168171        # only document that which the programmer exported in __all__
     
    210213    """Get the one-line summary out of a module file."""
    211214    mtime = os.stat(filename).st_mtime
    212     lastupdate, result = cache.get(filename, (0, None))
    213     if lastupdate < mtime:
     215    lastupdate, result = cache.get(filename, (None, None))
     216    if lastupdate is None or lastupdate < mtime:
    214217        info = inspect.getmoduleinfo(filename)
    215218        try:
     
    357360                                 'thread', 'zipimport') or
    358361             (file.startswith(basedir) and
    359               not file.startswith(os.path.join(basedir, 'site-packages'))))):
     362              not file.startswith(os.path.join(basedir, 'site-packages')))) and
     363            object.__name__ not in ('xml.etree', 'test.pydoc_mod')):
    360364            if docloc.startswith("http://"):
    361365                docloc = "%s/%s" % (docloc.rstrip("/"), object.__name__)
     
    475479        """Format a list of items into a multi-column list."""
    476480        result = ''
    477         rows = (len(list)+cols-1)/cols
     481        rows = (len(list)+cols-1)//cols
    478482        for col in range(cols):
    479             result = result + '<td width="%d%%" valign=top>' % (100/cols)
     483            result = result + '<td width="%d%%" valign=top>' % (100//cols)
    480484            for i in range(rows*col, rows*col+rows):
    481485                if i < len(list):
     
    627631            if (all is not None or
    628632                (inspect.getmodule(value) or object) is object):
    629                 if visiblename(key, all):
     633                if visiblename(key, all, object):
    630634                    classes.append((key, value))
    631635                    cdict[key] = cdict[value] = '#' + key
     
    643647            if (all is not None or
    644648                inspect.isbuiltin(value) or inspect.getmodule(value) is object):
    645                 if visiblename(key, all):
     649                if visiblename(key, all, object):
    646650                    funcs.append((key, value))
    647651                    fdict[key] = '#-' + key
     
    649653        data = []
    650654        for key, value in inspect.getmembers(object, isdata):
    651             if visiblename(key, all):
     655            if visiblename(key, all, object):
    652656                data.append((key, value))
    653657
     
    737741                push(msg)
    738742                for name, kind, homecls, value in ok:
    739                     push(self.document(getattr(object, name), name, mod,
    740                                        funcs, classes, mdict, object))
     743                    try:
     744                        value = getattr(object, name)
     745                    except Exception:
     746                        # Some descriptors may meet a failure in their __get__.
     747                        # (bug #1785)
     748                        push(self._docdescriptor(name, value, mod))
     749                    else:
     750                        push(self.document(value, name, mod,
     751                                        funcs, classes, mdict, object))
    741752                    push('\n')
    742753            return attrs
     
    773784            return attrs
    774785
    775         attrs = filter(lambda data: visiblename(data[0]),
     786        attrs = filter(lambda data: visiblename(data[0], obj=object),
    776787                       classify_class_attrs(object))
    777788        mdict = {}
    778789        for key, kind, homecls, value in attrs:
    779790            mdict[key] = anchor = '#' + name + '-' + key
    780             value = getattr(object, key)
     791            try:
     792                value = getattr(object, name)
     793            except Exception:
     794                # Some descriptors may meet a failure in their __get__.
     795                # (bug #1785)
     796                pass
    781797            try:
    782798                # The value may not be hashable (e.g., a data attr with
     
    10421058            if (all is not None
    10431059                or (inspect.getmodule(value) or object) is object):
    1044                 if visiblename(key, all):
     1060                if visiblename(key, all, object):
    10451061                    classes.append((key, value))
    10461062        funcs = []
     
    10491065            if (all is not None or
    10501066                inspect.isbuiltin(value) or inspect.getmodule(value) is object):
    1051                 if visiblename(key, all):
     1067                if visiblename(key, all, object):
    10521068                    funcs.append((key, value))
    10531069        data = []
    10541070        for key, value in inspect.getmembers(object, isdata):
    1055             if visiblename(key, all):
     1071            if visiblename(key, all, object):
    10561072                data.append((key, value))
    10571073
     
    11131129        return result
    11141130
    1115     def docclass(self, object, name=None, mod=None):
     1131    def docclass(self, object, name=None, mod=None, *ignored):
    11161132        """Produce text documentation for a given class object."""
    11171133        realname = object.__name__
     
    11581174                push(msg)
    11591175                for name, kind, homecls, value in ok:
    1160                     push(self.document(getattr(object, name),
    1161                                        name, mod, object))
     1176                    try:
     1177                        value = getattr(object, name)
     1178                    except Exception:
     1179                        # Some descriptors may meet a failure in their __get__.
     1180                        # (bug #1785)
     1181                        push(self._docdescriptor(name, value, mod))
     1182                    else:
     1183                        push(self.document(value,
     1184                                        name, mod, object))
    11621185            return attrs
    11631186
     
    11861209            return attrs
    11871210
    1188         attrs = filter(lambda data: visiblename(data[0]),
     1211        attrs = filter(lambda data: visiblename(data[0], obj=object),
    11891212                       classify_class_attrs(object))
    11901213        while attrs:
     
    14511474    if module:
    14521475        object = module
    1453         for part in parts[n:]:
    1454             try: object = getattr(object, part)
    1455             except AttributeError: return None
    1456         return object
    14571476    else:
    1458         if hasattr(__builtin__, path):
    1459             return getattr(__builtin__, path)
     1477        object = __builtin__
     1478    for part in parts[n:]:
     1479        try:
     1480            object = getattr(object, part)
     1481        except AttributeError:
     1482            return None
     1483    return object
    14601484
    14611485# --------------------------------------- interactive interpreter interface
     
    14751499        return object, thing
    14761500    else:
    1477         return thing, getattr(thing, '__name__', None)
     1501        name = getattr(thing, '__name__', None)
     1502        return thing, name if isinstance(name, str) else None
    14781503
    14791504def render_doc(thing, title='Python Library Documentation: %s', forceload=0):
     
    15331558    # (label, seealso-items).  The "label" is the label of the corresponding
    15341559    # section in the .rst file under Doc/ and an index into the dictionary
    1535     # in pydoc_topics.py.
     1560    # in pydoc_data/topics.py.
    15361561    #
    15371562    # CAUTION: if you change one of these dictionaries, be sure to adapt the
    15381563    #          list of needed labels in Doc/tools/sphinxext/pyspecific.py and
    1539     #          regenerate the pydoc_topics.py file by running
     1564    #          regenerate the pydoc_data/topics.py file by running
    15401565    #              make pydoc-topics
    15411566    #          in Doc/ and copying the output file into the Lib/ directory.
     
    17051730    }
    17061731
    1707     def __init__(self, input, output):
    1708         self.input = input
    1709         self.output = output
     1732    def __init__(self, input=None, output=None):
     1733        self._input = input
     1734        self._output = output
     1735
     1736    input  = property(lambda self: self._input or sys.stdin)
     1737    output = property(lambda self: self._output or sys.stdout)
    17101738
    17111739    def __repr__(self):
     
    17151743        return '<pydoc.Helper instance>'
    17161744
    1717     def __call__(self, request=None):
    1718         if request is not None:
     1745    _GoInteractive = object()
     1746    def __call__(self, request=_GoInteractive):
     1747        if request is not self._GoInteractive:
    17191748            self.help(request)
    17201749        else:
     
    17721801
    17731802If this is your first time using Python, you should definitely check out
    1774 the tutorial on the Internet at http://docs.python.org/tutorial/.
     1803the tutorial on the Internet at http://docs.python.org/%s/tutorial/.
    17751804
    17761805Enter the name of any module, keyword, or topic to get help on writing
     
    17821811of what it does; to list the modules whose summaries contain a given word
    17831812such as "spam", type "modules spam".
    1784 ''' % sys.version[:3])
     1813''' % tuple([sys.version[:3]]*2))
    17851814
    17861815    def list(self, items, columns=4, width=80):
     
    18221851    def showtopic(self, topic, more_xrefs=''):
    18231852        try:
    1824             import pydoc_topics
     1853            import pydoc_data.topics
    18251854        except ImportError:
    18261855            self.output.write('''
    18271856Sorry, topic and keyword documentation is not available because the
    1828 module "pydoc_topics" could not be found.
     1857module "pydoc_data.topics" could not be found.
    18291858''')
    18301859            return
     
    18381867        label, xrefs = target
    18391868        try:
    1840             doc = pydoc_topics.topics[label]
     1869            doc = pydoc_data.topics.topics[label]
    18411870        except KeyError:
    18421871            self.output.write('no documentation found for %s\n' % repr(topic))
     
    18841913''')
    18851914
    1886 help = Helper(sys.stdin, sys.stdout)
     1915help = Helper()
    18871916
    18881917class Scanner:
     
    19601989            modname = modname[:-9] + ' (package)'
    19611990        print modname, desc and '- ' + desc
    1962     try: import warnings
    1963     except ImportError: pass
    1964     else: warnings.filterwarnings('ignore') # ignore problems during import
    1965     ModuleScanner().run(callback, key)
     1991    def onerror(modname):
     1992        pass
     1993    with warnings.catch_warnings():
     1994        warnings.filterwarnings('ignore') # ignore problems during import
     1995        ModuleScanner().run(callback, key, onerror=onerror)
    19661996
    19671997# --------------------------------------------------- web browser interface
     
    20282058    class DocServer(BaseHTTPServer.HTTPServer):
    20292059        def __init__(self, port, callback):
    2030             host = (sys.platform == 'mac') and '127.0.0.1' or 'localhost'
    2031             self.address = ('', port)
     2060            host = 'localhost'
     2061            self.address = (host, port)
    20322062            self.url = 'http://%s:%d/' % (host, port)
    20332063            self.callback = callback
     
    21452175                if sys.platform == 'win32':
    21462176                    os.system('start "%s"' % url)
    2147                 elif sys.platform == 'mac':
    2148                     try: import ic
    2149                     except ImportError: pass
    2150                     else: ic.launchurl(url)
    21512177                else:
    21522178                    rc = os.system('netscape -remote "openURL(%s)" &' % url)
Note: See TracChangeset for help on using the changeset viewer.