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


Python Response.unicode_body方法代码示例

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


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

示例1: source_code

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import unicode_body [as 别名]
 def source_code(self, req):
     location = req.params["location"]
     module_name, lineno = location.split(":", 1)
     module = sys.modules.get(module_name)
     if module is None:
         # Something weird indeed
         res = Response(content_type="text/html", charset="utf8")
         res.unicode_body = "The module <code>%s</code> does not have an entry in sys.modules" % html_quote(
             module_name
         )
         return res
     filename = module.__file__
     if filename[-4:] in (".pyc", ".pyo"):
         filename = filename[:-1]
     elif filename.endswith("$py.class"):
         filename = "%s.py" % filename[:-9]
     f = open(filename, "rb")
     source = f.read()
     f.close()
     html = (
         "<div>Module: <b>%s</b> file: %s</div>"
         '<style type="text/css">%s</style>'
         % (html_quote(module_name), html_quote(filename), formatter.pygments_css)
     ) + formatter.highlight(filename, source, linenos=True)
     source_lines = len(source.splitlines())
     if source_lines < 60:
         html += "\n<br>" * (60 - source_lines)
     res = Response(content_type="text/html", charset="utf8")
     res.unicode_body = html
     return res
开发者ID:Pylons,项目名称:weberror,代码行数:32,代码来源:evalexception.py

示例2: source_code

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import unicode_body [as 别名]
 def source_code(self, req):
     location = req.params['location']
     module_name, lineno = location.split(':', 1)
     module = sys.modules.get(module_name)
     if module is None:
         # Something weird indeed
         res = Response(content_type='text/html', charset='utf8')
         res.unicode_body = 'The module <code>%s</code> does not have an entry in sys.modules' % html_quote(module_name)
         return res
     filename = module.__file__
     if filename[-4:] in ('.pyc', '.pyo'):
         filename = filename[:-1]
     elif filename.endswith('$py.class'):
         filename = '%s.py' % filename[:-9]
     f = open(filename, 'rb')
     source = f.read()
     f.close()
     html = (
         ('<div>Module: <b>%s</b> file: %s</div>'
          '<style type="text/css">%s</style>'
          % (html_quote(module_name), html_quote(filename), formatter.pygments_css))
         + formatter.highlight(filename, source, linenos=True))
     source_lines = len(source.splitlines())
     if source_lines < 60:
         html += '\n<br>'*(60-source_lines)
     res = Response(content_type='text/html', charset='utf8')
     res.unicode_body = html
     return res
开发者ID:dourvaris,项目名称:weberror,代码行数:30,代码来源:evalexception.py

示例3: list_profiles

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import unicode_body [as 别名]
    def list_profiles(self, req):
        """
        Displays all available profiles in list format.

        ``req``:
            :class:`webob.Request` containing the environment information from
            the request itself.

        Returns a WSGI application.
        """
        if "enable" in req.params:
            try:
                if not os.path.exists(ENABLED_FLAG_FILE):
                    open(ENABLED_FLAG_FILE, "w").close()
                self.profiling_enabled = True
            except IOError:
                log.error("Unable to create %s to enable profiling", os.path.abspath(ENABLED_FLAG_FILE))
                raise
        elif "disable" in req.params:
            try:
                if os.path.exists(ENABLED_FLAG_FILE):
                    os.remove(ENABLED_FLAG_FILE)
                self.profiling_enabled = False
            except IOError:
                log.error("Unable to delete %s to disable profiling", os.path.abspath(ENABLED_FLAG_FILE))
                raise

        resp = Response(charset="utf8")
        session_history = self._backend.get_all()
        resp.unicode_body = self.get_template("list.tmpl").render_unicode(
            history=session_history, path=req.path, profiling_enabled=self.profiling_enabled
        )
        return resp
开发者ID:GertBurger,项目名称:linesman,代码行数:35,代码来源:middleware.py

示例4: challenge

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import unicode_body [as 别名]
 def challenge(self, environ, status, app_headers, forget_headers):
     # redirect to login_form
     res = Response()
     res.status = 401
     res.unicode_body = render_snippet('not_authorized.html')
     #res.location = '/data/not_authorized' #self.login_form_url+"?%s=%s" %(self.came_from_field, request.url)
     return res
开发者ID:diabulos,项目名称:ckanext-dgu,代码行数:9,代码来源:drupal_repoze_plugin.py

示例5: __call__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import unicode_body [as 别名]
    def __call__(self, environ, start_response):

        # SQLAlchemy boilerplate code to connect to db and connect models to db objects
        engine = create_engine(engine_string)
        Session = sessionmaker(bind=engine)
        session = Session()

        req = Request(environ)

        #TODO: have GET parameters to restrict by entry year what rows to fetch

        summary = {}
        summary['full_count'] = session.query(Subject).filter(None).count()
        summary['male'] = session.query(Subject).filter(Subject.sex == u'Male').count()
        summary['female'] = session.query(Subject).filter(Subject.sex == u'Female').count()
        summary['amerind'] = session.query(Subject).filter(Subject.amerind == True).count()
        summary['afram'] = session.query(Subject).filter(Subject.afram == True).count()
        summary['pacif'] = session.query(Subject).filter(Subject.pacif == True).count()
        summary['asian'] = session.query(Subject).filter(Subject.asian == True).count()
        summary['white'] = session.query(Subject).filter(Subject.white == True).count()
        summary['unknown']  = session.query(Subject).filter(Subject.unknown == True).count()
        summary['hisp'] = session.query(Subject).filter(Subject.ethnicity == u'Hispanic or Latino').count()
        summary['nonhisp'] = session.query(Subject).filter(Subject.ethnicity == u'Not Hispanic or Latino').count()

        env = Environment(loader=FileSystemLoader(os.path.join(basepath,'templates')))
        template = env.get_template('subject_summary.html')
        template = template.render(summary=summary)

        resp = Response()
        resp.content_type='text/html'
        resp.unicode_body = template
        return resp(environ, start_response)
开发者ID:awatts,项目名称:subject_demographics,代码行数:34,代码来源:subject_controller.py

示例6: __call__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import unicode_body [as 别名]
        def __call__(self, environ, start_response):
            try:
                return self.app(environ, start_response)
            except Exception as exc:
                # get a formatted exception
                out = StringIO()
                print_exc(file=out)
                LOG.exception(exc)

                # get formatted WSGI environment
                formatted_environ = pformat(environ)

                # render our template
                result = debug_template.render(
                    traceback=out.getvalue(),
                    environment=formatted_environ
                )

                # construct and return our response
                response = Response()
                if isinstance(exc, HTTPException):
                    response.status_int = exc.status
                else:
                    response.status_int = 500
                response.unicode_body = result
                return response(environ, start_response)
开发者ID:adamchainz,项目名称:pecan,代码行数:28,代码来源:debug.py

示例7: get_version_info

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import unicode_body [as 别名]
    def get_version_info(self, req, file="version"):
        resp = Response()
        resp.charset = 'UTF-8'
        if utils.is_xml_response(req):
            resp_file = os.path.join(POSSIBLE_TOPDIR,
                "keystone/content/%s.xml.tpl" % file)
            resp.content_type = "application/xml"
        elif utils.is_atom_response(req):
            resp_file = os.path.join(POSSIBLE_TOPDIR,
                "keystone/content/%s.atom.tpl" % file)
            resp.content_type = "application/atom+xml"
        else:
            resp_file = os.path.join(POSSIBLE_TOPDIR,
                "keystone/content/%s.json.tpl" % file)
            resp.content_type = "application/json"

        hostname = req.environ.get("SERVER_NAME")
        port = req.environ.get("SERVER_PORT")
        if 'HTTPS' in req.environ:
            protocol = 'https'
        else:
            protocol = 'http'

        resp.unicode_body = template.template(resp_file,
            PROTOCOL=protocol,
            HOST=hostname,
            PORT=port,
            API_VERSION=version.API_VERSION,
            API_VERSION_STATUS=version.API_VERSION_STATUS,
            API_VERSION_DATE=version.API_VERSION_DATE)

        return resp
开发者ID:HugoKuo,项目名称:keystone-essex3,代码行数:34,代码来源:version.py

示例8: _render_atom_feed

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import unicode_body [as 别名]
def _render_atom_feed(request, mb, messages):    
    entries = []
    for message in messages:
        renderer = _get_atom_renderer(message, request)
        if renderer is not None:
            entries.append(renderer)

    info = MailboxInfo.get(mb)
    
    # absolute url for requested feed
    feed_url = request.url
    template_info = TemplateContext(request,
          {'id': feed_url,
           'self_link': feed_url,
           'updated': datetime.utcnow(), # XXX
           'title': info.title or request.context.get_mailbox_slug(mb.name),
           'entries': entries,
          })

    res = HttpResponse(content_type='application/atom+xml')
    res.charset = 'utf-8'
    res.unicode_body = request.context.render('radar/atom/atom.xml', template_info)
    res.headers['etag'] = get_mailbox_etag(mb)
    
    return res
开发者ID:ltucker,项目名称:radarpost,代码行数:27,代码来源:controller.py

示例9: __call__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import unicode_body [as 别名]
 def __call__(self,environ,start_response):
   args = Request(environ).path_info.split("/")
   res = Response()
   res.unicode_body = template(
     os.path.join(os.path.dirname(__file__),'webobTestTemplate.tpl'),
     numA=int(args[-2]),numB=int(args[-1]))
   return res(environ,start_response)
开发者ID:lp,项目名称:appenginePythonBenchmark,代码行数:9,代码来源:webobTestSimpleTemplate.py

示例10: __call__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import unicode_body [as 别名]
 def __call__(self,environ,start_response):
   args = Request(environ).path_info.split("/")
   res = Response()
   bvars = dict ( numA = int(args[-2]), numB = int(args[-1]) )
   res.unicode_body = Template(tags,root=os.path.dirname(__file__)
     ).render('webobBreveTestTemplate',bvars)
   return res(environ,start_response)
开发者ID:lp,项目名称:appenginePythonBenchmark,代码行数:9,代码来源:webobTestBreve.py

示例11: __call__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import unicode_body [as 别名]
 def __call__(self,environ,start_response):
   args = Request(environ).path_info.split("/")
   res = Response()
   res.unicode_body = Environment(loader=FileSystemLoader(
               os.path.join(
                   os.path.dirname(__file__),"templates/"))).get_template(
                       "webobJinjaTestTemplate.html").render(nums=range(int(args[-2])),numB=int(args[-1]))
   return res(environ,start_response)
开发者ID:lp,项目名称:appenginePythonBenchmark,代码行数:10,代码来源:webobTestJinja.py

示例12: set_header

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import unicode_body [as 别名]
def set_header(req):
    resp = Response()
    body = [u"Set Headers:"]
    for k, v in sorted(req.params.items()):
        body.extend([k, v]) 
        resp.headers.add(k, v)
    resp.unicode_body = u'\n'.join(body)
    return resp
开发者ID:jean,项目名称:zope.testbrowser,代码行数:10,代码来源:wsgitestapp.py

示例13: get_login_view

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import unicode_body [as 别名]
def get_login_view(req):
   rsp = Response()
   rsp.status_code = 200
   rsp.content_type = 'text/html'
   kw = {}
   if 'username' in req.session:
      kw['username'] = req.session['username']
   rsp.unicode_body = xhtml.render_page('login', kw)
   return rsp
开发者ID:watsonjiang,项目名称:newgo,代码行数:11,代码来源:login.py

示例14: challenge

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import unicode_body [as 别名]
 def challenge(self, environ, status, app_headers, forget_headers):
     '''
     The challenger.
     '''
     res = Response()
     res.headerlist = [('Content-type', 'application/json')]
     res.charset = 'utf8'
     res.unicode_body = u"{error:'wrong credentials'}"
     res.status = 403
     return res
开发者ID:bbcf,项目名称:biorepo,代码行数:12,代码来源:auth_plugin.py

示例15: render

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import unicode_body [as 别名]
 def render(self, controller, action, format, status, dict):
     '''
     Method gets fallowing arguments: controller, action, format, code, dict
     '''
     template = '{0}/{1}.{2}'.format(controller, action, format)
     content = self.engine.render(template=template, dict=dict)
     response = Response()
     response.status_int = status
     response.unicode_body = content
     return response
开发者ID:lukaszsliwa,项目名称:genius,代码行数:12,代码来源:view.py


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