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


Python web.header方法代码示例

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


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

示例1: _api_convert_output

# 需要导入模块: import web [as 别名]
# 或者: from web import header [as 别名]
def _api_convert_output(return_value):
    """ Convert the output to what the client asks """
    content_type = web.ctx.environ.get('CONTENT_TYPE', 'text/json')

    if "text/json" in content_type:
        web.header('Content-Type', 'text/json; charset=utf-8')
        return json.dumps(return_value)
    if "text/html" in content_type:
        web.header('Content-Type', 'text/html; charset=utf-8')
        dump = yaml.dump(return_value)
        return "<pre>" + web.websafe(dump) + "</pre>"
    if "text/yaml" in content_type or \
                    "text/x-yaml" in content_type or \
                    "application/yaml" in content_type or \
                    "application/x-yaml" in content_type:
        web.header('Content-Type', 'text/yaml; charset=utf-8')
        dump = yaml.dump(return_value)
        return dump
    web.header('Content-Type', 'text/json; charset=utf-8')
    return json.dumps(return_value) 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:22,代码来源:_api_page.py

示例2: GET_AUTH

# 需要导入模块: import web [as 别名]
# 或者: from web import header [as 别名]
def GET_AUTH(self, courseid):  # pylint: disable=arguments-differ
        """ GET request """
        course, __ = self.get_course_and_check_rights(courseid, allow_all_staff=False)

        data = web.input()

        if "download" in data:
            filepath = os.path.join(self.backup_dir, courseid, data["download"] + '.zip')

            if not os.path.exists(os.path.dirname(filepath)):
                raise web.notfound()

            web.header('Content-Type', 'application/zip', unique=True)
            web.header('Content-Disposition', 'attachment; filename="' + data["download"] + '.zip' + '"', unique=True)

            return open(filepath, 'rb')

        else:
            return self.page(course) 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:21,代码来源:danger_zone.py

示例3: GET_AUTH

# 需要导入模块: import web [as 别名]
# 或者: from web import header [as 别名]
def GET_AUTH(self, courseid, groupid=''):  # pylint: disable=arguments-differ
        """ Edit a group """
        course, __ = self.get_course_and_check_rights(courseid, allow_all_staff=True)

        if course.is_lti():
            raise web.notfound()

        if "download" in web.input():
            web.header('Content-Type', 'text/x-yaml', unique=True)
            web.header('Content-Disposition', 'attachment; filename="groups.yaml"', unique=True)
            groups = [{"description": group["description"],
                           "students": group["students"],
                           "size": group["size"],
                            "audiences": [str(c) for c in group["audiences"]]} for group in
                          self.user_manager.get_course_groups(course)]

            return yaml.dump(groups)

        return self.display_page(course) 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:21,代码来源:group_edit.py

示例4: GET_AUTH

# 需要导入模块: import web [as 别名]
# 或者: from web import header [as 别名]
def GET_AUTH(self, courseid):  # pylint: disable=arguments-differ
        """ GET request """
        course, __ = self.get_course_and_check_rights(courseid)
        user_input = web.input(tasks=[], aggregations=[], users=[])
        error = ""

        # First, check for a particular submission
        if "submission" in user_input:
            submission = self.database.submissions.find_one({"_id": ObjectId(user_input.submission),
                                                             "courseid": course.get_id(),
                                                             "status": {"$in": ["done", "error"]}})
            if submission is None:
                raise web.notfound()

            self._logger.info("Downloading submission %s - %s - %s - %s", submission['_id'], submission['courseid'],
                              submission['taskid'], submission['username'])
            archive, error = self.submission_manager.get_submission_archive(course, [submission], [])
            if not error:
                web.header('Content-Type', 'application/x-gzip', unique=True)
                web.header('Content-Disposition', 'attachment; filename="submissions.tgz"', unique=True)
                return archive

        # Else, display the complete page
        return self.display_page(course, user_input, error) 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:26,代码来源:download.py

示例5: action_download

# 需要导入模块: import web [as 别名]
# 或者: from web import header [as 别名]
def action_download(self, courseid, taskid, path):
        """ Download a file or a directory """

        wanted_path = self.verify_path(courseid, taskid, path)
        if wanted_path is None:
            raise web.notfound()

        task_fs = self.task_factory.get_task_fs(courseid, taskid)
        (method, mimetype_or_none, file_or_url) = task_fs.distribute(wanted_path)

        if method == "local":
            web.header('Content-Type', mimetype_or_none)
            return file_or_url
        elif method == "url":
            raise web.redirect(file_or_url)
        else:
            raise web.notfound() 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:19,代码来源:task_edit_file.py

示例6: GET

# 需要导入模块: import web [as 别名]
# 或者: from web import header [as 别名]
def GET(self):
        res = scanapp.scan()
        web.header("Content-Type","text/html; charset=utf-8")
        html = """
        <html><head>扫描结果</head><body><table>%s</table></body></html>
        """
        table = ""
        tr = "<tr>%s</tr>"
        td = "<td>%s</td>"
        count = 6
        tmp = ""
        for r in res:
            if count > 0:
                tmp += td % r
                count -= 1
            elif count == 0:
                count = 6
                table += tr % tmp
                tmp = ""
        return html % table 
开发者ID:mrmign,项目名称:iOS-private-api-scanner,代码行数:22,代码来源:site.py

示例7: POST

# 需要导入模块: import web [as 别名]
# 或者: from web import header [as 别名]
def POST(self):
        auth_form = get_form()
        if not auth_form.validates():
            flash('error', 'form validation failed')
            return render.form(get_form(name='delete'))

        is_ipv4 = web.net.validipaddr(auth_form['ipaddr'].value)
        is_ipv6 = web.net.validip6addr(auth_form['ipaddr'].value)
        if is_ipv4 == False and is_ipv6 == False:
            flash('error', '%s is not a valid ipv4/6 address' % auth_form['ipaddr'].value)
            return render.form(get_form(name='delete'))
        
        web.debug('De-authorising ipaddr=%s' % auth_form['ipaddr'].value)
        web.header('Content-Type', 'text/html')
        db_result = db.delete('ipaddrs', where="user_id=%s AND ipaddr='%s'" % (session.user['ID'],
                                                                               auth_form['ipaddr'].value))
        web.debug('db.delete: %s' % db_result)
        if db_result == 0: db_result = 1
        for i in range(0, db_result):
            if is_ipv4: result = run_ipt_cmd(auth_form['ipaddr'].value, 'D')
            if is_ipv6: result = run_ipt6_cmd(auth_form['ipaddr'].value, 'D') 
            web.debug('iptables_update: %s' % [result])
        session.auth_ip_count -= 1
        flash('success', '%s de-authorized' % auth_form['ipaddr'].value)
        return render.form(get_form(name='delete')) 
开发者ID:ab77,项目名称:netflix-proxy,代码行数:27,代码来源:auth.py

示例8: GET

# 需要导入模块: import web [as 别名]
# 或者: from web import header [as 别名]
def GET(self):
        get = web.input()
        try:
            get.filename = get.filename.encode('utf-8');
            import os        
            fp = open(get.filename,'rb')
            size = os.path.getsize(get.filename)
            filename = os.path.basename(get.filename)
            
            #输出文件头
            web.header("Content-Disposition", "attachment; filename=" +filename);
            web.header("Content-Length", size);
            web.header('Content-Type','application/octet-stream');
            buff = 4096
            while True:
                fBody = fp.read(buff)
                if fBody:
                    yield fBody
                else:
                    return
        except Exception, e:
            yield 'Error' 
开发者ID:NNBBXX,项目名称:BaoTa-Panel,代码行数:24,代码来源:main.py

示例9: GET

# 需要导入模块: import web [as 别名]
# 或者: from web import header [as 别名]
def GET(self,name):
        ext = name.split(".")[-1] # Gather extension
        if name.find('.')<0:
            ext = 'jpg'
        imfile = self.get_local( os.path.splitext(name)[0] )
        #print imfile
        try:
            web.header("Content-Type", cType[ext]) # Set the Header
            return open(imfile,"rb").read() # Notice 'rb' for reading images
        except:
            raise web.notfound() 
开发者ID:li-xirong,项目名称:jingwei,代码行数:13,代码来源:images.py

示例10: POST

# 需要导入模块: import web [as 别名]
# 或者: from web import header [as 别名]
def POST(self):
    if not 'user' in session or session.user is None:
      f = register_form()
      return render.login(f)

    i = web.input()
    if not i.has_key('samples_dir'):
      return render.error("No samples sub-directory specified.")
    if not i.has_key('magic'):
      return render.error("No magic header specified.")
    if not i.has_key('extension'):
      return render.error("No file extension specified.")
    if not i.has_key('search'):
      search = ""
    else:
      search = i["search"]
    if i["samples_dir"].find(".") > -1 or \
       i["samples_dir"].find("/") > -1 or \
       i["samples_dir"].find("\\") > -1:
      return render.error("Invalid sub-directory")

    db = init_web_db()
    res = db.select("config", what="value", where="name = 'TEMPLATES_PATH'")
    res = list(res)
    if len(res) == 0:
      return render.error("Samples path is not yet configured. Please configure it in the configuration section.")
    whole_dir = os.path.join(res[0].value, i.samples_dir)

    if not os.path.exists(whole_dir):
      os.makedirs(whole_dir)

    from find_samples import CSamplesFinder
    finder = CSamplesFinder()
    finder.find(i.extension, i.magic, whole_dir, search)
    return render.message("Process finished.")

#----------------------------------------------------------------------- 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:39,代码来源:nightmare_frontend.py

示例11: GET

# 需要导入模块: import web [as 别名]
# 或者: from web import header [as 别名]
def GET(self):
    if not 'user' in session or session.user is None:
      f = register_form()
      return render.login(f)

    i = web.input()
    if not i.has_key("id"):
      return render.error("No crash identifier given")
    if i.has_key("diff"):
      is_diff = True
    else:
      is_diff = False

    db = init_web_db()

    try:
      original_file, crash_file = find_original_file(db, i.id)
    except:
      return render.error(sys.exc_info()[1])

    if original_file is not None:
      basename = os.path.basename(original_file)
      web.header("Content-type", "application/octet-stream")
      web.header("Content-disposition", "attachment; filename=%s" % basename)
      f = open(original_file, 'rb')
      return f.read()

    return render.error("Cannot find original sample.")

#----------------------------------------------------------------------- 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:32,代码来源:nightmare_frontend.py

示例12: send

# 需要导入模块: import web [as 别名]
# 或者: from web import header [as 别名]
def send(self):
        web.header('Allow', ",".join(self.methods))
        return APIError.send(self) 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:5,代码来源:_api_page.py

示例13: GET

# 需要导入模块: import web [as 别名]
# 或者: from web import header [as 别名]
def GET(self, courseid, taskid, path):  # pylint: disable=arguments-differ
        """ GET request """
        try:
            course = self.course_factory.get_course(courseid)
            if not self.user_manager.course_is_open_to_user(course):
                return handle_course_unavailable(self.app.get_homepath(), self.template_helper, self.user_manager, course)

            path_norm = posixpath.normpath(urllib.parse.unquote(path))

            if taskid == "$common":
                public_folder = course.get_fs().from_subfolder("$common").from_subfolder("public")
            else:

                task = course.get_task(taskid)
                if not self.user_manager.task_is_visible_by_user(task):  # ignore LTI check here
                    return self.template_helper.get_renderer().task_unavailable()

                public_folder = task.get_fs().from_subfolder("public")
            (method, mimetype_or_none, file_or_url) = public_folder.distribute(path_norm, False)

            if method == "local":
                web.header('Content-Type', mimetype_or_none)
                return file_or_url
            elif method == "url":
                raise web.redirect(file_or_url)
            else:
                raise web.notfound()
        except web.HTTPError as error_or_redirect:
            raise error_or_redirect
        except:
            if web.config.debug:
                raise
            else:
                raise web.notfound() 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:36,代码来源:tasks.py

示例14: GET_AUTH

# 需要导入模块: import web [as 别名]
# 或者: from web import header [as 别名]
def GET_AUTH(self, courseid):  # pylint: disable=arguments-differ
        """ GET request """
        course, __ = self.get_course_and_check_rights(courseid)

        if "download" in web.input():
            web.header('Content-Type', 'text/x-yaml', unique=True)
            web.header('Content-Disposition', 'attachment; filename="audiences.yaml"', unique=True)
            audiences = [{"description": audience["description"],
                           "students": audience["students"],
                           "tutors": audience["tutors"]} for audience in
                          self.user_manager.get_course_audiences(course)]

            return yaml.dump(audiences)

        return self.page(course) 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:17,代码来源:audience_list.py

示例15: GET

# 需要导入模块: import web [as 别名]
# 或者: from web import header [as 别名]
def GET(self, id):
        settings = self.user_manager.get_auth_method(id).get_settings()
        auth = OneLogin_Saml2_Auth(prepare_request(settings), settings)
        metadata = auth.get_settings().get_sp_metadata()
        errors = auth.get_settings().validate_metadata(metadata)

        if len(errors) == 0:
            web.header('Content-Type', 'text/xml')
            return metadata
        else:
            web.ctx.status = "500 Internal Server Error"
            return ', '.join(errors) 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:14,代码来源:saml2_auth.py


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