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


Python cgitb.text方法代码示例

本文整理汇总了Python中cgitb.text方法的典型用法代码示例。如果您正苦于以下问题:Python cgitb.text方法的具体用法?Python cgitb.text怎么用?Python cgitb.text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cgitb的用法示例。


在下文中一共展示了cgitb.text方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _handle

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def _handle(self, environ):
        try:
            environ['bottle.app'] = self
            request.bind(environ)
            response.bind()
            route, args = self.router.match(environ)
            environ['route.handle'] = route
            environ['bottle.route'] = route
            environ['route.url_args'] = args
            return route.call(**args)
        except HTTPResponse:
            return _e()
        except RouteReset:
            route.reset()
            return self._handle(environ)
        except (KeyboardInterrupt, SystemExit, MemoryError):
            raise
        except Exception:
            if not self.catchall: raise
            stacktrace = format_exc()
            environ['wsgi.errors'].write(stacktrace)
            detailed_tb = cgitb.text(sys.exc_info())
            return HTTPError(500, detailed_tb, _e(), stacktrace) 
开发者ID:Juniper,项目名称:contrail-server-manager,代码行数:25,代码来源:bottle.py

示例2: wsgi

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def wsgi(self, environ, start_response):
        """ The bottle WSGI-interface. """
        try:
            out = self._cast(self._handle(environ))
            # rfc2616 section 4.3
            if response._status_code in (100, 101, 204, 304)\
            or environ['REQUEST_METHOD'] == 'HEAD':
                if hasattr(out, 'close'): out.close()
                out = []
            start_response(response._status_line, response.headerlist)
            return out
        except (KeyboardInterrupt, SystemExit, MemoryError):
            raise
        except Exception:
            if not self.catchall: raise
            err = '<h1>Critical error while processing request: %s</h1>' \
                  % html_escape(environ.get('PATH_INFO', '/'))
            if DEBUG:
                err += '<h2>Error:</h2>\n<pre>\n%s\n</pre>\n' \
                       '<h2>Traceback:</h2>\n<pre>\n%s\n</pre>\n' \
                       % (html_escape(repr(_e())), html_escape(format_exc()))
            environ['wsgi.errors'].write(err)
            headers = [('Content-Type', 'text/html; charset=UTF-8')]
            start_response('500 INTERNAL SERVER ERROR', headers)
            return [tob(err)] 
开发者ID:Juniper,项目名称:contrail-server-manager,代码行数:27,代码来源:bottle.py

示例3: auth_basic

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def auth_basic(check, realm="private", text="Access denied"):
    ''' Callback decorator to require HTTP auth (basic).
        TODO: Add route(check_auth=...) parameter. '''
    def decorator(func):
      def wrapper(*a, **ka):
        user, password = request.auth or (None, None)
        if user is None or not check(user, password):
          response.headers['WWW-Authenticate'] = 'Basic realm="%s"' % realm
          return HTTPError(401, text)
        return func(*a, **ka)
      return wrapper
    return decorator


# Shortcuts for common Bottle methods.
# They all refer to the current default application. 
开发者ID:Juniper,项目名称:contrail-server-manager,代码行数:18,代码来源:bottle.py

示例4: text_traceback

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def text_traceback():
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        res = 'the original traceback:'.join(
            cgitb.text(sys.exc_info()).split('the original traceback:')[1:]
        ).strip()
    return res 
开发者ID:italia,项目名称:daf-recipes,代码行数:9,代码来源:base.py

示例5: _get_content_as_unicode

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def _get_content_as_unicode(self, url):
        '''
        Get remote content as unicode.

        We let requests handle the conversion [1] , which will use the
        content-type header first or chardet if the header is missing
        (requests uses its own embedded chardet version).

        As we will be storing and serving the contents as unicode, we actually
        replace the original XML encoding declaration with an UTF-8 one.


        [1] http://github.com/kennethreitz/requests/blob/63243b1e3b435c7736acf1e51c0f6fa6666d861d/requests/models.py#L811

        '''
        url = url.replace(' ', '%20')
        response = requests.get(url, timeout=10)

        content = response.text

        # Remove original XML declaration
        content = re.sub('<\?xml(.*)\?>', '', content)

        # Get rid of the BOM and other rubbish at the beginning of the file
        content = re.sub('.*?<', '<', content, 1)
        content = content[content.index('<'):]

        return content 
开发者ID:italia,项目名称:daf-recipes,代码行数:30,代码来源:base.py

示例6: test_fonts

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def test_fonts(self):
        text = "Hello Robbie!"
        self.assertEqual(cgitb.small(text), "<small>{}</small>".format(text))
        self.assertEqual(cgitb.strong(text), "<strong>{}</strong>".format(text))
        self.assertEqual(cgitb.grey(text),
                         '<font color="#909090">{}</font>'.format(text)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_cgitb.py

示例7: test_text

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def test_text(self):
        try:
            raise ValueError("Hello World")
        except ValueError as err:
            text = cgitb.text(sys.exc_info())
            self.assertIn("ValueError", text)
            self.assertIn("Hello World", text) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:test_cgitb.py

示例8: test_syshook_no_logdir_text_format

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def test_syshook_no_logdir_text_format(self):
        # Issue 12890: we were emitting the <p> tag in text mode.
        with temp_dir() as tracedir:
            rc, out, err = assert_python_failure(
                  '-c',
                  ('import cgitb; cgitb.enable(format="text", logdir=%s); '
                   'raise ValueError("Hello World")') % repr(tracedir))
        out = out.decode(sys.getfilesystemencoding())
        self.assertIn("ValueError", out)
        self.assertIn("Hello World", out)
        self.assertNotIn('<p>', out)
        self.assertNotIn('</p>', out) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_cgitb.py

示例9: abort

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def abort(code=500, text='Unknown Error: Application stopped.'):
    """ Aborts execution and causes a HTTP error. """
    raise HTTPError(code, text) 
开发者ID:Juniper,项目名称:contrail-server-manager,代码行数:5,代码来源:bottle.py

示例10: dump_raw_text

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def dump_raw_text(self, text):
        raise NotImplementedError() 
开发者ID:windelbouwman,项目名称:ppci,代码行数:4,代码来源:reporting.py

示例11: dump_exception

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def dump_exception(self, einfo):
        self.print(cgitb.text(einfo)) 
开发者ID:windelbouwman,项目名称:ppci,代码行数:4,代码来源:reporting.py

示例12: _get_table

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def _get_table(self, db, tablename, app):
        tablename = tablename + '_' + app
        table = db.get(tablename)
        if not table:
            table = db.define_table(
                tablename,
                db.Field('ticket_id', length=100),
                db.Field('ticket_data', 'text'),
                db.Field('created_datetime', 'datetime'))
        return table 
开发者ID:uwdata,项目名称:termite-visualizations,代码行数:12,代码来源:restricted.py


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