示例#1
0
文件: wsgi.py 项目: 77720616/django
 def __init__(self, environ):
     script_name = base.get_script_name(environ)
     path_info = base.get_path_info(environ)
     if not path_info:
         # Sometimes PATH_INFO exists, but is empty (e.g. accessing
         # the SCRIPT_NAME URL without a trailing slash). We really need to
         # operate as if they'd requested '/'. Not amazingly nice to force
         # the path like this, but should be harmless.
         path_info = '/'
     self.environ = environ
     self.path_info = path_info
     self.path = '%s/%s' % (script_name.rstrip('/'), path_info.lstrip('/'))
     self.META = environ
     self.META['PATH_INFO'] = path_info
     self.META['SCRIPT_NAME'] = script_name
     self.method = environ['REQUEST_METHOD'].upper()
     _, content_params = self._parse_content_type(self.META.get('CONTENT_TYPE', ''))
     if 'charset' in content_params:
         try:
             codecs.lookup(content_params['charset'])
         except LookupError:
             pass
         else:
             self.encoding = content_params['charset']
     self._post_parse_error = False
     try:
         content_length = int(self.environ.get('CONTENT_LENGTH'))
     except (ValueError, TypeError):
         content_length = 0
     self._stream = LimitedStream(self.environ['wsgi.input'], content_length)
     self._read_started = False
     self.resolver_match = None
示例#2
0
 def __init__(self, environ):
     script_name = base.get_script_name(environ)
     path_info = base.get_path_info(environ)
     if not path_info:
         # Sometimes PATH_INFO exists, but is empty (e.g. accessing
         # the SCRIPT_NAME URL without a trailing slash). We really need to
         # operate as if they'd requested '/'. Not amazingly nice to force
         # the path like this, but should be harmless.
         path_info = '/'
     self.environ = environ
     self.path_info = path_info
     self.path = '%s/%s' % (script_name.rstrip('/'), path_info.lstrip('/'))
     self.META = environ
     self.META['PATH_INFO'] = path_info
     self.META['SCRIPT_NAME'] = script_name
     self.method = environ['REQUEST_METHOD'].upper()
     _, content_params = self._parse_content_type(
         self.META.get('CONTENT_TYPE', ''))
     if 'charset' in content_params:
         try:
             codecs.lookup(content_params['charset'])
         except LookupError:
             pass
         else:
             self.encoding = content_params['charset']
     self._post_parse_error = False
     try:
         content_length = int(self.environ.get('CONTENT_LENGTH'))
     except (ValueError, TypeError):
         content_length = 0
     self._stream = LimitedStream(self.environ['wsgi.input'],
                                  content_length)
     self._read_started = False
     self.resolver_match = None
示例#3
0
文件: wsgi.py 项目: hexxter/django
 def __init__(self, environ):
     script_name = base.get_script_name(environ)
     path_info = base.get_path_info(environ)
     if not path_info or path_info == script_name:
         # Sometimes PATH_INFO exists, but is empty (e.g. accessing
         # the SCRIPT_NAME URL without a trailing slash). We really need to
         # operate as if they'd requested '/'. Not amazingly nice to force
         # the path like this, but should be harmless.
         #
         # (The comparison of path_info to script_name is to work around an
         # apparent bug in flup 1.0.1. See Django ticket #8490).
         path_info = "/"
     self.environ = environ
     self.path_info = path_info
     self.path = "%s%s" % (script_name, path_info)
     self.META = environ
     self.META["PATH_INFO"] = path_info
     self.META["SCRIPT_NAME"] = script_name
     self.method = environ["REQUEST_METHOD"].upper()
     _, content_params = self._parse_content_type(self.META.get("CONTENT_TYPE", ""))
     if "charset" in content_params:
         try:
             codecs.lookup(content_params["charset"])
         except LookupError:
             pass
         else:
             self.encoding = content_params["charset"]
     self._post_parse_error = False
     try:
         content_length = int(self.environ.get("CONTENT_LENGTH"))
     except (ValueError, TypeError):
         content_length = 0
     self._stream = LimitedStream(self.environ["wsgi.input"], content_length)
     self._read_started = False
示例#4
0
    def __call__(self, environ, start_response):
        # Hand non-static requests to Django
        if not self._should_handle(get_path_info(environ)):
            return self.application(environ, start_response)

        # Serve static requests from static.Cling
        if not self.debug:
            environ = self._transpose_environ(environ)
            return self.cling(environ, start_response)
        # Serve static requests in debug mode from StaticFilesHandler
        else:
            return self.debug_cling(environ, start_response)
示例#5
0
    def __call__(self, environ, start_response):
        # Hand non-static requests to Django
        if not self._should_handle(get_path_info(environ)):
            return self.application(environ, start_response)

        # Serve static requests from static.Cling
        if not self.debug:
            environ = self._transpose_environ(environ)
            return self.cling(environ, start_response)
        # Serve static requests in debug mode from StaticFilesHandler
        else:
            return self.debug_cling(environ, start_response)
示例#6
0
    def __call__(self, environ, start_response):
        # Hand non-static requests to Django
        if not self._should_handle(get_path_info(environ)):
            return self.application(environ, start_response)

        def max_age(status, headers, exc_info=None):
            headers.append(('Cache-Control', "max-age=31536000"))
            return start_response(status, headers, exc_info)

        # Serve static requests from static.Cling
        if not self.debug:
            environ = self._transpose_environ(environ)
            return self._gzip(self.cling, environ, max_age)
        # Serve static requests in debug mode from StaticFilesHandler
        else:
            return self._gzip(self.debug_cling, environ, start_response)
示例#7
0
    def __init__(self, environ): # 要传入环境变量
        script_name = base.get_script_name(environ) # 脚本
        path_info = base.get_path_info(environ)     # 路径

        if not path_info or path_info == script_name:
            # Sometimes PATH_INFO exists, but is empty (e.g. accessing
            # the SCRIPT_NAME URL without a trailing slash). We really need to
            # operate as if they'd requested '/'. Not amazingly nice to force
            # the path like this, but should be harmless.
            #
            # (The comparison of path_info to script_name is to work around an
            # apparent bug in flup 1.0.1. See Django ticket #8490).
            path_info = '/'

        self.environ = environ
        self.path_info = path_info
        self.path = '%s%s' % (script_name, path_info)

        self.META = environ
        self.META['PATH_INFO'] = path_info
        self.META['SCRIPT_NAME'] = script_name
        self.method = environ['REQUEST_METHOD'].upper()

        _, content_params = self._parse_content_type(self.META.get('CONTENT_TYPE', '')) # 分析请求内容类型

        if 'charset' in content_params:
            try:
                codecs.lookup(content_params['charset'])
            except LookupError:
                pass
            else:
                self.encoding = content_params['charset']

        self._post_parse_error = False

        try:
            content_length = int(self.environ.get('CONTENT_LENGTH')) # 长度
        except (ValueError, TypeError):
            content_length = 0

        self._stream = LimitedStream(self.environ['wsgi.input'], content_length)
        self._read_started = False
示例#8
0
 def __call__(self, environ, start_response):
     if not self._should_handle(get_path_info(environ)):
         return self.application(environ, start_response)
     return super(FSFilesHandler, self).__call__(environ, start_response)
示例#9
0
 def __call__(self, environ, start_response):
     if not self._should_handle(get_path_info(environ)):
         return self.application(environ, start_response)
     return super(FSFilesHandler, self).__call__(environ, start_response)