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

Python http_date.build_http_date函数代码示例

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

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



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

示例1: handle_request

    def handle_request(self, request):
        if request.command != 'GET':
            request.error (400) # bad request
            return

        path, params, query, fragment = request.split_uri()

        if '%' in path:
            path = http_server.unquote(path)

        # strip off all leading slashes
        while path and path[0] == '/':
            path = path[1:]

        path, process_name_and_channel = path.split('/', 1)

        try:
            process_name, channel = process_name_and_channel.split('/', 1)
        except ValueError:
            # no channel specified, default channel to stdout
            process_name = process_name_and_channel
            channel = 'stdout'

        from supervisor.options import split_namespec
        group_name, process_name = split_namespec(process_name)

        group = self.supervisord.process_groups.get(group_name)
        if group is None:
            request.error(404) # not found
            return

        process = group.processes.get(process_name)
        if process is None:
            request.error(404) # not found
            return

        logfile = getattr(process.config, '%s_logfile' % channel, None)

        if logfile is None or not os.path.exists(logfile):
            # XXX problematic: processes that don't start won't have a log
            # file and we probably don't want to go into fatal state if we try
            # to read the log of a process that did not start.
            request.error(410) # gone
            return

        mtime = os.stat(logfile)[stat.ST_MTIME]
        request['Last-Modified'] = http_date.build_http_date(mtime)
        request['Content-Type'] = 'text/plain'
        # the lack of a Content-Length header makes the outputter
        # send a 'Transfer-Encoding: chunked' response

        request.push(tail_f_producer(request, logfile, 1024))

        request.done()
开发者ID:wowgeeker,项目名称:supervisor,代码行数:54,代码来源:http.py


示例2: __init__

    def __init__(self, *args):
        # unpack information about the request
        (self.channel, self.request, self.command, self.uri, self.version, self.header) = args

        self.outgoing = []
        self.reply_headers = {"Server": "Medusa/%s" % VERSION_STRING, "Date": http_date.build_http_date(time.time())}

        # New reply header list (to support multiple
        # headers with same name)
        self.__reply_header_list = []

        self.request_number = http_request.request_counter.increment()
        self._split_uri = None
        self._header_cache = {}
开发者ID:gburiola,项目名称:supervisor,代码行数:14,代码来源:http_server.py


示例3: test_handle_request

 def test_handle_request(self):
     supervisor = DummySupervisor()
     with tempfile.NamedTemporaryFile() as f:
         t = f.name
         supervisor.options.logfile = t
         handler = self._makeOne(supervisor)
         request = DummyRequest('/mainlogtail', None, None, None)
         handler.handle_request(request)
         self.assertEqual(request._error, None)
         from supervisor.medusa import http_date
         self.assertEqual(request.headers['Last-Modified'],
             http_date.build_http_date(os.stat(t)[stat.ST_MTIME]))
         self.assertEqual(request.headers['Content-Type'], 'text/plain')
         self.assertEqual(len(request.producers), 1)
         self.assertEqual(request._done, True)
开发者ID:ngocson2vn,项目名称:supervisor,代码行数:15,代码来源:test_http.py


示例4: test_handle_request

 def test_handle_request(self):
     supervisor = DummySupervisor()
     fd, tfilename = tempfile.mkstemp()
     try:
         supervisor.options.logfile = tfilename
         handler = self._makeOne(supervisor)
         request = DummyRequest('/mainlogtail', None, None, None)
         handler.handle_request(request)
         self.assertEqual(request._error, None)
         from supervisor.medusa import http_date
         self.assertEqual(request.headers['Last-Modified'],
                          http_date.build_http_date(os.stat(tfilename)[stat.ST_MTIME]))
         self.assertEqual(request.headers['Content-Type'], 'text/plain')
         self.assertEqual(len(request.producers), 1)
         self.assertEqual(request._done, True)
     finally:
         os.close(fd)
开发者ID:alexsilva,项目名称:supervisor,代码行数:17,代码来源:test_http.py


示例5: handle_request

    def handle_request (self, request):

        if request.command not in self.valid_commands:
            request.error (400) # bad request
            return

        self.hit_counter.increment()

        path, params, query, fragment = request.split_uri()

        if '%' in path:
            path = unquote (path)

        # strip off all leading slashes
        while path and path[0] == '/':
            path = path[1:]

        if self.filesystem.isdir (path):
            if path and path[-1] != '/':
                request['Location'] = 'http://%s/%s/' % (
                        request.channel.server.server_name,
                        path
                        )
                request.error (301)
                return

            # we could also generate a directory listing here,
            # may want to move this into another method for that
            # purpose
            found = 0
            if path and path[-1] != '/':
                path += '/'
            for default in self.directory_defaults:
                p = path + default
                if self.filesystem.isfile (p):
                    path = p
                    found = 1
                    break
            if not found:
                request.error (404) # Not Found
                return

        elif not self.filesystem.isfile (path):
            request.error (404) # Not Found
            return

        file_length = self.filesystem.stat (path)[stat.ST_SIZE]

        ims = get_header_match (IF_MODIFIED_SINCE, request.header)

        length_match = 1
        if ims:
            length = ims.group (4)
            if length:
                try:
                    length = int(length)
                    if length != file_length:
                        length_match = 0
                except:
                    pass

        ims_date = 0

        if ims:
            ims_date = http_date.parse_http_date (ims.group (1))

        try:
            mtime = self.filesystem.stat (path)[stat.ST_MTIME]
        except:
            request.error (404)
            return

        if length_match and ims_date:
            if mtime <= ims_date:
                request.reply_code = 304
                request.done()
                self.cache_counter.increment()
                return
        try:
            file = self.filesystem.open (path, 'rb')
        except IOError:
            request.error (404)
            return

        request['Last-Modified'] = http_date.build_http_date (mtime)
        request['Content-Length'] = file_length
        self.set_content_type (path, request)

        if request.command == 'GET':
            request.push (self.default_file_producer (file))

        self.file_counter.increment()
        request.done()
开发者ID:GulsahKose,项目名称:supervisor,代码行数:93,代码来源:default_handler.py


示例6: get

# -*- Mode: Python -*-

import supervisor.medusa.text_socket as socket
import time
from supervisor.medusa import http_date

now = http_date.build_http_date (time.time())

cache_request = '\r\n'.join(
        ['GET / HTTP/1.0',
         'If-Modified-Since: %s' % now,
         ]) + '\r\n\r\n'

nocache_request = 'GET / HTTP/1.0\r\n\r\n'

def get (request, host='', port=8080):
    s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
    s.connect((host, port))
    s.send(request)
    while 1:
        d = s.recv (8192)
        if not d:
            break
    s.close()

class timer:
    def __init__ (self):
        self.start = time.time()
    def end (self):
        return time.time() - self.start
开发者ID:GulsahKose,项目名称:supervisor,代码行数:30,代码来源:test_medusa.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python http_server.get_header函数代码示例发布时间:2022-05-27
下一篇:
Python counter.counter函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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