all variables in pydoc are ok

parent 3d8c3ce4
......@@ -120,16 +120,26 @@
(define miss (slask-it ((@ (guile) list) 'miss)))
(define* (getattr a b #:optional (k miss))
(let ((r (ref a (if (string? b) (string->symbol b) b) miss)))
(if (eq? r miss)
(if (eq? k miss)
(if (equal? b "__module__")
"<builtin>"
(raise AttributeError
"object/class ~a is missing attribute ~a" a b))
k)
r)))
(define (f)
(let ((r (ref a (if (string? b) (string->symbol b) b) miss)))
(if (eq? r miss)
(if (eq? k miss)
(if (equal? b "__module__")
"<builtin>"
(raise AttributeError
"object/class ~a is missing attribute ~a" a b))
k)
r)))
(if (port? a)
(cond
((equal? b "encoding")
(port-encoding a))
(else
(f)))
(f)))
(define (setattr a k v)
(pf-set a (if (string? k) (string->symbol k) k) v))
......
......@@ -55,6 +55,9 @@ except ImportError:
def popleft(self):
return self.pop(0)
# Fallback to encode stdout
_encoding='ascii'
# --------------------------------------------------------- common routines
def pathdirs():
......@@ -72,7 +75,6 @@ def pathdirs():
def getdoc(object):
"""Get the doc string or comments for an object."""
result = inspect.getdoc(object) or inspect.getcomments(object)
result = _encode(result)
return result and re.sub('^ *\n', '', rstrip(result)) or ''
def splitdoc(doc):
......@@ -173,10 +175,6 @@ def classify_class_attrs(object):
return name, kind, cls, value
return map(fixup, inspect.classify_class_attrs(object))
# ----------------------------------------------------- Unicode support helpers
def _encode(text, encoding='ascii'):
return text
def _binstr(obj):
# Ensure that we have an encoded (binary) string representation of obj,
# even if it is a unicode string.
......@@ -413,10 +411,6 @@ class HTMLRepr(Repr):
repr_unicode = repr_string
def cmp(a,b):
return (a > b) - (a < b)
class HTMLDoc(Doc):
"""Formatter class for HTML documentation."""
......@@ -428,13 +422,13 @@ class HTMLDoc(Doc):
def page(self, title, contents):
"""Format an HTML page."""
return _encode('''
return '''
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: %s</title>
<meta charset="utf-8">
</head><body bgcolor="#f0f0f8">
%s
</body></html>''' % (title, contents), 'ascii')
</body></html>''' % (title, contents)
def heading(self, title, fgcol, bgcol, extras=''):
"""Format a page heading."""
......@@ -832,7 +826,7 @@ class HTMLDoc(Doc):
try:
attrs.sort(key=lambda t: t[0])
except TypeError:
attrs.sort(lambda t1, t2: cmp(t1[0], t2[0])) # 2.3 compat
attrs.sort(lambda t1, t2: t1[0] < t2[0]) # 2.3 compat
# Pump out the attrs, segregated by kind.
attrs = spill('Methods %s' % tag, attrs,
......@@ -1388,7 +1382,7 @@ def pipepager(text, cmd):
"""Page through text by feeding it to another program."""
pipe = os.popen(cmd, 'w')
try:
pipe.write(_encode(text))
pipe.write(text)
pipe.close()
except OSError:
pass # Ignore broken pipes caused by quitting the pager program.
......@@ -1398,7 +1392,7 @@ def tempfilepager(text, cmd):
import tempfile
filename = tempfile.mktemp()
file = open(filename, 'w')
file.write(_encode(text))
file.write(text)
file.close()
try:
os.system(cmd + ' "' + filename + '"')
......@@ -1407,7 +1401,7 @@ def tempfilepager(text, cmd):
def ttypager(text):
"""Page through text on a text terminal."""
lines = plain(_encode(plain(text), getattr(sys.stdout, 'encoding', _encoding))).split('\n')
lines = text.decode(getattr(sys.stdout, 'encoding', _encoding)).split('\n')
try:
import tty
fd = sys.stdin.fileno()
......@@ -1451,7 +1445,7 @@ def ttypager(text):
def plainpager(text):
"""Simply print unformatted text. This is the ultimate fallback."""
sys.stdout.write(_encode(plain(text), getattr(sys.stdout, 'encoding', _encoding)))
sys.stdout.write(text.encode(getattr(sys.stdout, 'encoding', _encoding)))
def describe(thing):
"""Produce a short description of the given thing."""
......@@ -1572,6 +1566,8 @@ def writedocs(dir, pkgpath='', done=None):
writedoc(modname)
return
_GoInteractive = object()
class Helper:
# These dictionaries map a topic name to either an alias, or a tuple
......@@ -1649,12 +1645,6 @@ class Helper:
'[': 'LISTS SUBSCRIPTS SLICINGS',
']': 'LISTS SUBSCRIPTS SLICINGS'
}
for topic, symbols_ in _symbols_inverse.iteritems():
for symbol in symbols_:
topics = symbols.get(symbol, topic)
if topic not in topics:
topics = topics + ' ' + topic
symbols[symbol] = topics
topics = {
'TYPES': ('types', 'STRINGS UNICODE NUMBERS SEQUENCES MAPPINGS '
......@@ -1694,7 +1684,7 @@ class Helper:
'SPECIALMETHODS': ('specialnames', 'BASICMETHODS ATTRIBUTEMETHODS '
'CALLABLEMETHODS SEQUENCEMETHODS1 MAPPINGMETHODS '
'SEQUENCEMETHODS2 NUMBERMETHODS CLASSES'),
'BASICMETHODS': ('customization', 'cmp hash repr str SPECIALMETHODS'),
'BASICMETHODS': ('customization', 'shash repr str SPECIALMETHODS'),
'ATTRIBUTEMETHODS': ('attribute-access', 'ATTRIBUTES SPECIALMETHODS'),
'CALLABLEMETHODS': ('callable-types', 'CALLS SPECIALMETHODS'),
'SEQUENCEMETHODS1': ('sequence-types', 'SEQUENCES SEQUENCEMETHODS2 '
......@@ -1763,7 +1753,6 @@ class Helper:
return ''
return '<pydoc.Helper instance>'
_GoInteractive = object()
def __call__(self, request=_GoInteractive):
if request is not self._GoInteractive:
self.help(request)
......@@ -1930,6 +1919,13 @@ Enter any module name to get more help. Or, type "modules spam" to search
for modules whose descriptions contain the word "spam".
''')
for topic, symbols_ in Helper._symbols_inverse.iteritems():
for symbol in symbols_:
topics = Helper.symbols.get(symbol, topic)
if topic not in topics:
topics = topics + ' ' + topic
Helper.symbols[symbol] = topics
help = Helper()
......
......@@ -1331,29 +1331,43 @@ explicitly tell it to not update etc.
ass)
(let lp ((code code))
(syntax-case code (set! @ @@)
(syntax-case code (@ @@)
((set! x y)
(equal? (syntax->datum #'set!) 'set!)
(aif it (hash-ref m (syntax->datum #'x))
#`(set! #,it #,(sec #'y))
(error "wrong set! in classdef" (syntax->datum #'x))))
(((@ (guile) set!) x y)
(equal? (syntax->datum #'set!) 'set!)
(aif it (hash-ref m (syntax->datum #'x))
#`((@ (guile) set!) #,it #,(sec #'y))
(error "wrong set! in classdef" (syntax->datum #'x))))
(((@@ a set-x) x y ...)
(equal? 'set-x (syntax->datum #'set-x))
(equal? (syntax->datum #'set-x) 'set-x)
(aif it (hash-ref m (syntax->datum #'x))
#`((@@ a set-x) #,it y ...)
(error "wrong set! in classdef" (syntax->datum #'x))))
(((@@ u qset) x . y)
(equal? (syntax->datum #'qset) 'qset!)
(((@@ u qset!) x . y)
(equal? (syntax->datum #'qset!) 'qset!)
(aif it (hash-ref m (syntax->datum #'x))
#`((@@ u qset) #,it . #,(sec #'y))
#`((@@ u qset!) #,it . #,(sec #'y))
(error "wrong set! in classdef" (syntax->datum #'x))))
(((@ a begin)
((@@ b qset!) c d)
e)
(and (equal? (syntax->datum #'c) (syntax->datum #'e))
(equal? (syntax->datum #'begin) 'begin)
(equal? (syntax->datum #'qset!) 'qset!))
(aif it (hash-ref m (syntax->datum #'c))
#`((@ a begin)
((@@ b qset!) #,it #,(sec #'d))
#,it)
(error "wrong set! in classdef" (syntax->datum #'x))))
((x . y)
(cons (lp #'x) (lp #'y)))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment