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


Python CGIHTTPServer.nobody_uid方法代码示例

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


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

示例1: run_cgi

# 需要导入模块: import CGIHTTPServer [as 别名]
# 或者: from CGIHTTPServer import nobody_uid [as 别名]

#.........这里部分代码省略.........
        uqrest = urllib.unquote(rest)
        env['PATH_INFO'] = uqrest
        env['PATH_TRANSLATED'] = self.translate_path(uqrest)
        env['SCRIPT_NAME'] = scriptname
        if query:
            env['QUERY_STRING'] = query
        host = self.address_string()
        if host != self.client_address[0]:
            env['REMOTE_HOST'] = host
        env['REMOTE_ADDR'] = self.client_address[0]
        authorization = self.headers.getheader("authorization")
        if authorization:
            authorization = authorization.split()
            if len(authorization) == 2:
                import base64, binascii
                env['AUTH_TYPE'] = authorization[0]
                if authorization[0].lower() == "basic":
                    try:
                        authorization = base64.decodestring(authorization[1])
                    except binascii.Error:
                        pass
                    else:
                        authorization = authorization.split(':')
                        if len(authorization) == 2:
                            env['REMOTE_USER'] = authorization[0]
        # XXX REMOTE_IDENT
        if self.headers.typeheader is None:
            env['CONTENT_TYPE'] = self.headers.type
        else:
            env['CONTENT_TYPE'] = self.headers.typeheader
        length = self.headers.getheader('content-length')
        if length:
            env['CONTENT_LENGTH'] = length
        referer = self.headers.getheader('referer')
        if referer:
            env['HTTP_REFERER'] = referer
        accept = []
        for line in self.headers.getallmatchingheaders('accept'):
            if line[:1] in "\t\n\r ":
                accept.append(line.strip())
            else:
                accept = accept + line[7:].split(',')
        env['HTTP_ACCEPT'] = ','.join(accept)
        ua = self.headers.getheader('user-agent')
        if ua:
            env['HTTP_USER_AGENT'] = ua
        co = filter(None, self.headers.getheaders('cookie'))
        if co:
            env['HTTP_COOKIE'] = ', '.join(co)
        # XXX Other HTTP_* headers
        # Since we're setting the env in the parent, provide empty
        # values to override previously set values
        for k in ('QUERY_STRING', 'REMOTE_HOST', 'CONTENT_LENGTH',
                  'HTTP_USER_AGENT', 'HTTP_COOKIE', 'HTTP_REFERER'):
            env.setdefault(k, "")
        os.environ.update(env)

        self.send_response(200, "Script output follows")

        decoded_query = query.replace('+', ' ')

        if self.have_fork:
            # Unix -- fork as we should
            args = [script]
            if '=' not in decoded_query:
                args.append(decoded_query)
            nobody = CGIHTTPServer.nobody_uid()
            self.wfile.flush() # Always flush before forking
            pid = os.fork()
            if pid != 0:
                # Parent
                pid, sts = os.waitpid(pid, 0)
                # throw away additional data [see bug #427345]
                while select.select([self.rfile], [], [], 0)[0]:
                    if not self.rfile.read(1):
                        break
                if sts:
                    self.log_error("CGI script exit status %#x", sts)
                return
            # Child
            try:
                try:
                    os.setuid(nobody)
                except os.error:
                    pass
                os.dup2(self.rfile.fileno(), 0)
                os.dup2(self.wfile.fileno(), 1)
                #hack to import python scripts due to permission restrictions
                #regarding launching another interpreter instance                                               
                root, ext = os.path.splitext(scriptfile)
                if ext == '.py':
                    root, script = os.path.split(root)
                    sys.path.append(root)
                    __import__(script)
                    os._exit(0)
                else:
                    os.execve(scriptfile, args, os.environ)
            except:
                self.server.handle_error(self.request, self.client_address)
                os._exit(127)
开发者ID:mubeta06,项目名称:android,代码行数:104,代码来源:webserver.py

示例2: run_cgi

# 需要导入模块: import CGIHTTPServer [as 别名]
# 或者: from CGIHTTPServer import nobody_uid [as 别名]

#.........这里部分代码省略.........
        accept = []
        for line in self.headers.getallmatchingheaders('accept'):
            if line[:1] in "\t\n\r ":
                accept.append(line.strip())
            else:
                accept = accept + line[7:].split(',')
        env['HTTP_ACCEPT'] = ','.join(accept)
        ua = self.headers.getheader('user-agent')
        if ua:
            env['HTTP_USER_AGENT'] = ua
        co = filter(None, self.headers.getheaders('cookie'))
        if co:
            env['HTTP_COOKIE'] = ', '.join(co)
        # XXX Other HTTP_* headers
        # Since we're setting the env in the parent, provide empty
        # values to override previously set values
        for k in ('QUERY_STRING', 'REMOTE_HOST', 'CONTENT_LENGTH',
                  'HTTP_USER_AGENT', 'HTTP_COOKIE', 'HTTP_REFERER'):
            env.setdefault(k, "")

        if self.command.lower() == 'post':
            self.send_response(303, 'redirection')
        else:
            self.send_response(200, "Script output follows")

        decoded_query = query.replace('+', ' ')

        if self.have_fork:
            # Unix -- fork as we should
            args = [script]
            if '=' not in decoded_query:
                args.append(decoded_query)
            if sys.platform != 'darwin':
                nobody = CGIHTTPServer.nobody_uid()
            self.wfile.flush() # Always flush before forking
            pid = os.fork()
            if pid != 0:
                # Parent
                pid, sts = os.waitpid(pid, 0)
                # throw away additional data [see bug #427345]
                while select.select([self.rfile], [], [], 0)[0]:
                    if not self.rfile.read(1):
                        break
                if sts:
                    self.log_error("CGI script exit status %#x", sts)
                return
            # Child
            try:
                if sys.platform != 'darwin':
                    try:
                        os.setuid(nobody)
                    except os.error:
                        pass
                os.dup2(self.rfile.fileno(), 0)
                os.dup2(self.wfile.fileno(), 1)
                os.execve(scriptfile, args, env)

            except:
                self.server.handle_error(self.request, self.client_address)
                os._exit(127)

        else:
            # Non Unix - use subprocess
            import subprocess
            cmdline = [scriptfile]
            if self.is_python(scriptfile):
开发者ID:codepongo,项目名称:blog,代码行数:70,代码来源:cgiserver.py

示例3: run_cgi

# 需要导入模块: import CGIHTTPServer [as 别名]
# 或者: from CGIHTTPServer import nobody_uid [as 别名]

#.........这里部分代码省略.........
                accept = accept + line[7:].split(",")
        env["HTTP_ACCEPT"] = ",".join(accept)
        ua = self.headers.getheader("user-agent")
        if ua:
            env["HTTP_USER_AGENT"] = ua
        co = filter(None, self.headers.getheaders("cookie"))
        if co:
            env["HTTP_COOKIE"] = ", ".join(co)
        # XXX Other HTTP_* headers
        # Since we're setting the env in the parent, provide empty
        # values to override previously set values
        for k in ("QUERY_STRING", "REMOTE_HOST", "CONTENT_LENGTH", "HTTP_USER_AGENT", "HTTP_COOKIE", "HTTP_REFERER"):
            env.setdefault(k, "")

        self.send_response(200, "Script output follows")

        decoded_query = query.replace("+", " ")

        if self.is_php(scriptfile):
            env["SCRIPT_FILENAME"] = os.path.abspath(scriptfile)
            self.init_bin()

        # if self.have_fork and not self.is_php(scriptfile):
        if self.have_fork:
            # Unix -- fork as we should
            args = [script]
            if self.is_php(scriptfile):
                args = [scriptfile]
                scriptfile = self.php_bin
            #     args = [scriptfile]
            #     scriptfile = '/usr/bin/php'
            if "=" not in decoded_query:
                args.append(decoded_query)
            nobody = CGIHTTPServer.nobody_uid()
            self.wfile.flush()  # Always flush before forking
            pid = os.fork()
            if pid != 0:
                # Parent
                pid, sts = os.waitpid(pid, 0)
                # throw away additional data [see bug #427345]
                while select.select([self.rfile], [], [], 0)[0]:
                    if not self.rfile.read(1):
                        break
                if sts:
                    self.log_error("CGI script exit status %#x", sts)
                return
            # Child
            try:
                # try:
                #     os.setuid(nobody)
                # except os.error:
                #     pass
                os.dup2(self.rfile.fileno(), 0)
                os.dup2(self.wfile.fileno(), 1)
                os.execve(scriptfile, args, env)
            except:
                self.server.handle_error(self.request, self.client_address)
                os._exit(127)

        else:
            # Non Unix - use subprocess
            import subprocess

            cmdline = [scriptfile]
            if self.is_python(scriptfile):
                interp = sys.executable
开发者ID:pekepeke,项目名称:tinyhttp-app,代码行数:70,代码来源:tinyhttp.py


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