本文整理汇总了Python中repr.Repr.repr方法的典型用法代码示例。如果您正苦于以下问题:Python Repr.repr方法的具体用法?Python Repr.repr怎么用?Python Repr.repr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类repr.Repr
的用法示例。
在下文中一共展示了Repr.repr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fail
# 需要导入模块: from repr import Repr [as 别名]
# 或者: from repr.Repr import repr [as 别名]
def fail(self, object, name=None, *args):
"""Raise an exception for unimplemented types."""
message = "don't know how to document object%s of type %s" % (
name and ' ' + repr(name), type(object).__name__)
raise TypeError, message
示例2: repr
# 需要导入模块: from repr import Repr [as 别名]
# 或者: from repr.Repr import repr [as 别名]
def repr(self, object):
return Repr.repr(self, object)
示例3: repr1
# 需要导入模块: from repr import Repr [as 别名]
# 或者: from repr.Repr import repr [as 别名]
def repr1(self, x, level):
if hasattr(type(x), '__name__'):
methodname = 'repr_' + join(split(type(x).__name__), '_')
if hasattr(self, methodname):
return getattr(self, methodname)(x, level)
return self.escape(cram(stripid(repr(x)), self.maxother))
示例4: repr_string
# 需要导入模块: from repr import Repr [as 别名]
# 或者: from repr.Repr import repr [as 别名]
def repr_string(self, x, level):
test = cram(x, self.maxstring)
testrepr = repr(test)
if '\\' in test and '\\' not in replace(testrepr, r'\\', ''):
# Backslashes are only literal in the string and are never
# needed to make any special characters, so show a raw string.
return 'r' + testrepr[0] + self.escape(test) + testrepr[0]
return re.sub(r'((\\[\\abfnrtv\'"]|\\[0-9]..|\\x..|\\u....)+)',
r'<font color="#c040c0">\1</font>',
self.escape(testrepr))
示例5: repr_instance
# 需要导入模块: from repr import Repr [as 别名]
# 或者: from repr.Repr import repr [as 别名]
def repr_instance(self, x, level):
try:
return self.escape(cram(stripid(repr(x)), self.maxstring))
except:
return self.escape('<%s instance>' % x.__class__.__name__)
示例6: docother
# 需要导入模块: from repr import Repr [as 别名]
# 或者: from repr.Repr import repr [as 别名]
def docother(self, object, name=None, mod=None, *ignored):
"""Produce HTML documentation for a data object."""
lhs = name and '<strong>%s</strong> = ' % name or ''
return lhs + self.repr(object)
示例7: formatvalue
# 需要导入模块: from repr import Repr [as 别名]
# 或者: from repr.Repr import repr [as 别名]
def formatvalue(self, object):
"""Format an argument default value as text."""
return '=' + self.repr(object)
示例8: showtopic
# 需要导入模块: from repr import Repr [as 别名]
# 或者: from repr.Repr import repr [as 别名]
def showtopic(self, topic, more_xrefs=''):
try:
import pydoc_data.topics
except ImportError:
self.output.write('''
Sorry, topic and keyword documentation is not available because the
module "pydoc_data.topics" could not be found.
''')
return
target = self.topics.get(topic, self.keywords.get(topic))
if not target:
self.output.write('no documentation found for %s\n' % repr(topic))
return
if type(target) is type(''):
return self.showtopic(target, more_xrefs)
label, xrefs = target
try:
doc = pydoc_data.topics.topics[label]
except KeyError:
self.output.write('no documentation found for %s\n' % repr(topic))
return
pager(strip(doc) + '\n')
if more_xrefs:
xrefs = (xrefs or '') + ' ' + more_xrefs
if xrefs:
import StringIO, formatter
buffer = StringIO.StringIO()
formatter.DumbWriter(buffer).send_flowing_data(
'Related help topics: ' + join(split(xrefs), ', ') + '\n')
self.output.write('\n%s\n' % buffer.getvalue())
示例9: serve
# 需要导入模块: from repr import Repr [as 别名]
# 或者: from repr.Repr import repr [as 别名]
def serve(port, callback=None, completer=None):
import BaseHTTPServer, mimetools, select
# Patch up mimetools.Message so it doesn't break if rfc822 is reloaded.
class Message(mimetools.Message):
def __init__(self, fp, seekable=1):
Message = self.__class__
Message.__bases__[0].__bases__[0].__init__(self, fp, seekable)
self.encodingheader = self.getheader('content-transfer-encoding')
self.typeheader = self.getheader('content-type')
self.parsetype()
self.parseplist()
class DocHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def send_document(self, title, contents):
try:
self.send_response(200)
self.send_header('Content-Type', 'text/html')
self.end_headers()
self.wfile.write(html.page(title, contents))
except IOError: pass
def do_GET(self):
path = self.path
if path[-5:] == '.html': path = path[:-5]
if path[:1] == '/': path = path[1:]
if path and path != '.':
try:
obj = locate(path, forceload=1)
except ErrorDuringImport, value:
self.send_document(path, html.escape(str(value)))
return
if obj:
self.send_document(describe(obj), html.document(obj, path))
else:
self.send_document(path,
'no Python documentation found for %s' % repr(path))
else:
示例10: test_string
# 需要导入模块: from repr import Repr [as 别名]
# 或者: from repr.Repr import repr [as 别名]
def test_string(self):
eq = self.assertEqual
eq(r("abc"), "'abc'")
eq(r("abcdefghijklmnop"),"'abcdefghijklmnop'")
s = "a"*30+"b"*30
expected = repr(s)[:13] + "..." + repr(s)[-14:]
eq(r(s), expected)
eq(r("\"'"), repr("\"'"))
s = "\""*30+"'"*100
expected = repr(s)[:13] + "..." + repr(s)[-14:]
eq(r(s), expected)
示例11: test_tuple
# 需要导入模块: from repr import Repr [as 别名]
# 或者: from repr.Repr import repr [as 别名]
def test_tuple(self):
eq = self.assertEqual
eq(r((1,)), "(1,)")
t3 = (1, 2, 3)
eq(r(t3), "(1, 2, 3)")
r2 = Repr()
r2.maxtuple = 2
expected = repr(t3)[:-2] + "...)"
eq(r2.repr(t3), expected)
示例12: test_numbers
# 需要导入模块: from repr import Repr [as 别名]
# 或者: from repr.Repr import repr [as 别名]
def test_numbers(self):
eq = self.assertEqual
eq(r(123), repr(123))
eq(r(123L), repr(123L))
eq(r(1.0/3), repr(1.0/3))
n = 10L**100
expected = repr(n)[:18] + "..." + repr(n)[-19:]
eq(r(n), expected)
示例13: test_file
# 需要导入模块: from repr import Repr [as 别名]
# 或者: from repr.Repr import repr [as 别名]
def test_file(self):
fp = open(unittest.__file__)
self.assertTrue(repr(fp).startswith(
"<open file %r, mode 'r' at 0x" % unittest.__file__))
fp.close()
self.assertTrue(repr(fp).startswith(
"<closed file %r, mode 'r' at 0x" % unittest.__file__))
示例14: test_lambda
# 需要导入模块: from repr import Repr [as 别名]
# 或者: from repr.Repr import repr [as 别名]
def test_lambda(self):
self.assertTrue(repr(lambda x: x).startswith(
"<function <lambda"))
# XXX anonymous functions? see func_repr
示例15: test_builtin_function
# 需要导入模块: from repr import Repr [as 别名]
# 或者: from repr.Repr import repr [as 别名]
def test_builtin_function(self):
eq = self.assertEqual
# Functions
eq(repr(hash), '<built-in function hash>')
# Methods
self.assertTrue(repr(''.split).startswith(
'<built-in method split of str object at 0x'))