• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python webapi.header函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中webapi.header函数的典型用法代码示例。如果您正苦于以下问题:Python header函数的具体用法?Python header怎么用?Python header使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: modified

def modified(date=None, etag=None):
    """
    Checks to see if the page has been modified since the version in the
    requester's cache.
    
    When you publish pages, you can include `Last-Modified` and `ETag`
    with the date the page was last modified and an opaque token for
    the particular version, respectively. When readers reload the page, 
    the browser sends along the modification date and etag value for
    the version it has in its cache. If the page hasn't changed, 
    the server can just return `304 Not Modified` and not have to 
    send the whole page again.
    
    This function takes the last-modified date `date` and the ETag `etag`
    and checks the headers to see if they match. If they do, it returns 
    `True` and sets the response status to `304 Not Modified`. It also
    sets `Last-Modified and `ETag` output headers.
    """
    n = set(x.strip('" ') for x in web.ctx.env.get('HTTP_IF_NONE_MATCH', '').split(','))
    m = net.parsehttpdate(web.ctx.env.get('HTTP_IF_MODIFIED_SINCE', '').split(';')[0])
    validate = False
    if etag:
        if '*' in n or etag in n:
            validate = True
    if date and m:
        # we subtract a second because 
        # HTTP dates don't have sub-second precision
        if date-datetime.timedelta(seconds=1) <= m:
            validate = True
    
    if validate: web.ctx.status = '304 Not Modified'
    lastmodified(date)
    web.header('ETag', '"' + etag + '"')
    return not validate
开发者ID:asldevi,项目名称:watchdog,代码行数:34,代码来源:http.py


示例2: __call__

    def __call__(self, *a, **kw):
        import webapi as web

        if "headers" in web.ctx and self.content_type:
            web.header("Content-Type", self.content_type, unique=True)

        return BaseTemplate.__call__(self, *a, **kw)
开发者ID:mzkmzk,项目名称:jit,代码行数:7,代码来源:template.py


示例3: __call__

 def __call__(self, *a, **kw):
     __hidetraceback__ = True
     import webapi as web
     if 'headers' in web.ctx and self.content_type:
         web.header('Content-Type', self.content_type, unique=True)
         
     return BaseTemplate.__call__(self, *a, **kw)
开发者ID:wangfeng3769,项目名称:remotebox,代码行数:7,代码来源:template.py


示例4: nomethod

def nomethod(cls):
    """Returns a `405 Method Not Allowed` error for `cls`."""
    web.ctx.status = '405 Method Not Allowed'
    web.header('Content-Type', 'text/html')
    web.header('Allow', \
           ', '.join([method for method in \
                     ['GET', 'HEAD', 'POST', 'PUT', 'DELETE'] \
                        if hasattr(cls, method)]))
开发者ID:1ngmar,项目名称:ianki,代码行数:8,代码来源:request.py


示例5: expires

def expires(delta):
    """
    Outputs an `Expires` header for `delta` from now. 
    `delta` is a `timedelta` object or a number of seconds.
    """
    if isinstance(delta, (int, long)):
        delta = datetime.timedelta(seconds=delta)
    date_obj = datetime.datetime.utcnow() + delta
    web.header('Expires', net.httpdate(date_obj))
开发者ID:Alexand,项目名称:20questions,代码行数:9,代码来源:http.py


示例6: redirect

def redirect(url, status='301 Moved Permanently'):
    """
    Returns a `status` redirect to the new URL. 
    `url` is joined with the base URL so that things like 
    `redirect("about") will work properly.
    """
    newloc = urlparse.urljoin(web.ctx.home + web.ctx.path, url)
    web.ctx.status = status
    web.ctx.output = ''    
    web.header('Content-Type', 'text/html')
    web.header('Location', newloc)
开发者ID:Codesleuth,项目名称:rabbitmq-dotnet-client,代码行数:11,代码来源:http.py


示例7: f

    def f(*args, **kw):
        x = fn(*args, **kw)
        web.header('Content-Type', 'text/plain; charset=UTF-8')
        try:
            if x and (type(x) is not dict) \
                 and ((hasattr(x, '__iter__') or hasattr(x, 'next'))):
                x = list(x)

            yield get_encoder(web.ctx._out_format)(x)
        except:
            yield 'not json :(\n'
            yield x
开发者ID:kindy61,项目名称:webpy,代码行数:12,代码来源:resty.py


示例8: __call__

    def __call__(self, *a, **kw):
        d = self.globals.copy()
        d.update(self._parseargs(a, kw))
        f = Fill(self.tree, d=d)
        if self.filter: f.filter = self.filter

        import webapi as web
        if 'headers' in web.ctx and self.filename:
            content_type = self.find_content_type()
            if content_type:
                web.header('Content-Type', content_type, unique=True)
        
        return f.go()
开发者ID:antoine,项目名称:metagenda,代码行数:13,代码来源:template.py


示例9: wsgifunc

    def wsgifunc(self, *middleware):
        """Returns a WSGI-compatible function for this application."""
        def peep(iterator):
            """Peeps into an iterator by doing an iteration
            and returns an equivalent iterator.
            """
            # wsgi requires the headers first
            # so we need to do an iteration
            # and save the result for later
            try:
                firstchunk = iterator.next()
            except StopIteration:
                firstchunk = ''

            return itertools.chain([firstchunk], iterator)
                                
        def is_generator(x): return x and hasattr(x, 'next')
        
        def wsgi(env, start_resp):
            stime = time.time()
            # clear threadlocal to avoid inteference of previous requests
            self._cleanup()

            self.load(env)
            try:
                # allow uppercase methods only
                if web.ctx.method.upper() != web.ctx.method:
                    raise web.nomethod()

                result = self.handle_with_processors()
                if is_generator(result):
                    result = peep(result)
                elif not hasattr(result, '__iter__'):
                    result = [result]
            except web.HTTPError, e:
                result = [e.data]

            result = web.utf8(iter(result))

            status, headers = web.ctx.status, web.ctx.headers
            web.header('X-TIME', time.time() - stime)
            del stime
            start_resp(status, headers)
            
            def cleanup():
                self._cleanup()
                yield '' # force this function to be a generator
                            
            return itertools.chain(result, cleanup())
开发者ID:kindy61,项目名称:webpy,代码行数:49,代码来源:application.py


示例10: render

def render(template, terms=None, asTemplate=False, base=None, 
           isString=False):
    """
    Renders a template, caching where it can.
    
    `template` is the name of a file containing the a template in
    the `templates/` folder, unless `isString`, in which case it's the 
    template itself.

    `terms` is a dictionary used to fill the template. If it's None, then
    the caller's local variables are used instead, plus context, if it's not 
    already set, is set to `context`.

    If asTemplate is False, it `output`s the template directly. Otherwise,
    it returns the template object.

    If the template is a potential base template (that is, something other templates)
    can extend, then base should be a string with the name of the template. The
    template will be cached and made available for future calls to `render`.

    Requires [Cheetah](http://cheetahtemplate.org/).
    """
    # terms=['var1', 'var2'] means grab those variables
    if isinstance(terms, list):
        new = {}
        old = upvars()
        for k in terms: 
            new[k] = old[k]
        terms = new
    # default: grab all locals
    elif terms is None:
        terms = {'context': ctx, 'ctx':ctx}
        terms.update(sys._getframe(1).f_locals)
    # terms=d means use d as the searchList
    if not isinstance(terms, tuple): 
        terms = (terms,)
    
    if 'headers' in ctx and not isString and template.endswith('.html'): 
        header('Content-Type','text/html; charset=utf-8', unique=True)
        
    if loadhooks.has_key('reloader'):
        compiled_tmpl = __compiletemplate(template, base=base, isString=isString)
    else:
        compiled_tmpl = _compiletemplate(template, base=base, isString=isString)
    compiled_tmpl = compiled_tmpl(searchList=terms, filter=WebSafe)
    if asTemplate: 
        return compiled_tmpl
    else: 
        return output(str(compiled_tmpl))
开发者ID:1ngmar,项目名称:ianki,代码行数:49,代码来源:cheetah.py


示例11: redirect

def redirect(url, status='301 Moved Permanently'):
    """
    Returns a `status` redirect to the new URL. 
    `url` is joined with the base URL so that things like 
    `redirect("about") will work properly.
    """
    if url.startswith("/"):
        newloc = web.ctx.homepath + url
    else:
        newloc = url

    web.ctx.status = status
    web.ctx.output = ''    
    web.header('Content-Type', 'text/html')
    web.header('Location', newloc)
开发者ID:antoine,项目名称:metagenda,代码行数:15,代码来源:http.py


示例12: modified

def modified(date=None, etag=None):
    """
    Checks to see if the page has been modified since the version in the
    requester's cache.

    When you publish pages, you can include `Last-Modified` and `ETag`
    with the date the page was last modified and an opaque token for
    the particular version, respectively. When readers reload the page,
    the browser sends along the modification date and etag value for
    the version it has in its cache. If the page hasn't changed,
    the server can just return `304 Not Modified` and not have to
    send the whole page again.

    This function takes the last-modified date `date` and the ETag `etag`
    and checks the headers to see if they match. If they do, it returns
    `True`, or otherwise it raises NotModified error. It also sets
    `Last-Modified` and `ETag` output headers.
    """
    try:
        from __builtin__ import set
    except ImportError:
        from sets import Set as set

    n = set([x.strip('" ')
            for x in web.ctx.env.get('HTTP_IF_MODIFIED_SINCE', '').split(',')])
    m = net.parsehttpdate(
        web.ctx.env.get('HTTP_IF_MODIFIED_SINCE', '').split(';')[0])
    validate = False
    if etag:
        if '*' in n or etag in n:
            validate = True
    if date and m:
        if date - datetime.timedelta(seconds=1) <= m:
            validate = True
    if date:
        lastmodified(date)
    if etag:
        web.header('ETag', '"' + etag + '"')
    if validate:
        raise web.NotModified()
    else:
        return True
开发者ID:xuechao8086,项目名称:tinyhttpd,代码行数:42,代码来源:http.py


示例13: write

def write(cgi_response):
    """
    Converts a standard CGI-style string response into `header` and 
    `output` calls.
    """
    cgi_response = str(cgi_response)
    cgi_response.replace('\r\n', '\n')
    head, body = cgi_response.split('\n\n', 1)
    lines = head.split('\n')

    for line in lines:
        if line.isspace(): 
            continue
        hdr, value = line.split(":", 1)
        value = value.strip()
        if hdr.lower() == "status": 
            web.ctx.status = value
        else: 
            web.header(hdr, value)

    web.output(body)
开发者ID:Codesleuth,项目名称:rabbitmq-dotnet-client,代码行数:21,代码来源:http.py


示例14: _do

    def _do(self, name, filter=None):
        if self.cache is False or name not in self.cache:
            p = glob.glob(self.loc + name + '.*')
            if not p and os.path.isdir(self.loc + name):
                return render(self.loc + name + '/', cache=self.cache)
            elif not p:
                raise AttributeError, 'no template named ' + name
            p = p[0]
            c = Template(open(p).read())
            if self.cache is not False: self.cache[name] = (p, c)
        
        if self.cache is not False: p, c = self.cache[name]

        if p.endswith('.html'):
            import webapi as web
            if 'headers' in web.ctx:
                web.header('Content-Type', 'text/html; charset=utf-8', unique=True)
            if not filter: c.filter = websafe
        elif p.endswith('.xml'):
            if not filter: c.filter = websafe
        
        return c
开发者ID:Codesleuth,项目名称:rabbitmq-dotnet-client,代码行数:22,代码来源:template.py


示例15: is_generator

            try:
                # allow uppercase methods only
                if web.ctx.method.upper() != web.ctx.method:
                    raise web.nomethod()

                result = self.handle_with_processors()
            except NotFound:
                web.ctx.status = "404 Not Found"
                result = self.notfound()
            except web.HTTPError, e:
                result = e.data
            except:
                print >>web.debug, traceback.format_exc()
                web.ctx.status = "500 Internal Server Error"
                web.header("Content-Type", "text/html")
                result = self.internalerror()

            if is_generator(result):
                result = peep(result)
            else:
                result = [utils.utf8(result)]

            status, headers = web.ctx.status, web.ctx.headers
            start_resp(status, headers)

            # @@@
            # Since the CherryPy Webserver uses thread pool, the thread-local state is never cleared.
            # This interferes with the other requests.
            # clearing the thread-local storage to avoid that.
            # see utils.ThreadedDict for details
开发者ID:Letractively,项目名称:pytof,代码行数:30,代码来源:application.py


示例16: is_generator

            try:
                # allow uppercase methods only
                if web.ctx.method.upper() != web.ctx.method:
                    raise web.nomethod()

                result = self.handle_with_processors()
            except NotFound:
                web.ctx.status = "404 Not Found"
                result = self.notfound()
            except web.HTTPError, e:
                result = e.data
            except:
                print >> web.debug, traceback.format_exc()
                web.ctx.status = '500 Internal Server Error'
                web.header('Content-Type', 'text/html')
                result = self.internalerror()

            if is_generator(result):
                result = peep(result)
            else:
                result = [utils.utf8(result)]

            status, headers = web.ctx.status, web.ctx.headers
            start_resp(status, headers)

            #@@@
            # Since the CherryPy Webserver uses thread pool, the thread-local state is never cleared.
            # This interferes with the other requests. 
            # clearing the thread-local storage to avoid that.
            # see utils.ThreadedDict for details
开发者ID:christopherbdnk,项目名称:watchdog,代码行数:30,代码来源:application.py


示例17: lastmodified

def lastmodified(date_obj):
    """Outputs a `Last-Modified` header for `datetime`."""
    web.header('Last-Modified', net.httpdate(date_obj))
开发者ID:Alexand,项目名称:20questions,代码行数:3,代码来源:http.py


示例18: __call__

 def __call__(self, *a, **kw):
     import webapi as web
     if 'headers' in web.ctx and self.content_type:
         web.header('Content-Type', self.content_type)
         
     return BaseTemplate.__call__(self, *a, **kw)
开发者ID:btbytes,项目名称:webpy,代码行数:6,代码来源:template.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python webapi.input函数代码示例发布时间:2022-05-26
下一篇:
Python web_utils.WebUtils类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap