当前位置: 首页>>代码示例>>Python>>正文


Python Repr.repr方法代码示例

本文整理汇总了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 
开发者ID:glmcdona,项目名称:meddle,代码行数:7,代码来源:pydoc.py

示例2: repr

# 需要导入模块: from repr import Repr [as 别名]
# 或者: from repr.Repr import repr [as 别名]
def repr(self, object):
        return Repr.repr(self, object) 
开发者ID:glmcdona,项目名称:meddle,代码行数:4,代码来源:pydoc.py

示例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)) 
开发者ID:glmcdona,项目名称:meddle,代码行数:8,代码来源:pydoc.py

示例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)) 
开发者ID:glmcdona,项目名称:meddle,代码行数:12,代码来源:pydoc.py

示例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__) 
开发者ID:glmcdona,项目名称:meddle,代码行数:7,代码来源:pydoc.py

示例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) 
开发者ID:glmcdona,项目名称:meddle,代码行数:6,代码来源:pydoc.py

示例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) 
开发者ID:glmcdona,项目名称:meddle,代码行数:5,代码来源:pydoc.py

示例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()) 
开发者ID:glmcdona,项目名称:meddle,代码行数:33,代码来源:pydoc.py

示例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: 
开发者ID:glmcdona,项目名称:meddle,代码行数:40,代码来源:pydoc.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_repr.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_repr.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_repr.py

示例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__)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_repr.py

示例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 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_repr.py

示例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')) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_repr.py


注:本文中的repr.Repr.repr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。