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

Python util.forward函数代码示例

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

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



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

示例1: serve_file

def serve_file(id, reduced=False):
    """Serve the content (binary data) of a file.
    
    :param str id: the ``id`` value of the file whose file data will be served.
    :param bool reduced: toggles serving of file data or reduced-size file data.

    """
    file = Session.query(File).options(subqueryload(File.parent_file)).get(id)
    if getattr(file, 'parent_file', None):
        file = file.parent_file
    elif getattr(file, 'url', None):
        response.status_int = 400
        return json.dumps({'error': u'The content of file %s is stored elsewhere at %s' % (id, file.url)})
    if file:
        files_dir = h.get_OLD_directory_path('files', config=config)
        if reduced:
            filename = getattr(file, 'lossy_filename', None)
            if not filename:
                response.status_int = 404
                return json.dumps({'error': u'There is no size-reduced copy of file %s' % id})
            file_path = os.path.join(files_dir, 'reduced_files', filename)
        else:
            file_path = os.path.join(files_dir, file.filename)
        unrestricted_users = h.get_unrestricted_users()
        if h.user_is_authorized_to_access_model(session['user'], file, unrestricted_users):
            return forward(FileApp(file_path))
        else:
            response.status_int = 403
            return json.dumps(h.unauthorized_msg)
    else:
        response.status_int = 404
        return json.dumps({'error': 'There is no file with id %s' % id})
开发者ID:jrwdunham,项目名称:old,代码行数:32,代码来源:files.py


示例2: export_deprecated

 def export_deprecated(self, id):
     """Export the parser as a self-contained archive including a Python interface and all required files.
     """
     try:
         parser = Session.query(MorphologicalParser).get(id)
         directory = parser.directory
         archive_dir = os.path.join(directory, 'archive')
         if os.path.exists(archive_dir):
             rmtree(archive_dir)
         os.mkdir(archive_dir)
         parser.copy_files(archive_dir)
         parser.phonology.copy_files(archive_dir)
         parser.morphology.copy_files(archive_dir)
         parser.language_model.copy_files(archive_dir)
         lib_path = os.path.join(config['here'], 'onlinelinguisticdatabase', 'lib')
         simplelm_path = os.path.join(lib_path, 'simplelm')
         parser_path = os.path.join(lib_path, 'parser.py')
         parse_path = os.path.join(lib_path, 'parse.py')
         new_parse_path = os.path.join(archive_dir, 'parse.py')
         copytree(simplelm_path, os.path.join(archive_dir, 'simplelm'))
         copyfile(parser_path, os.path.join(archive_dir, 'parser.py'))
         copyfile(parse_path, new_parse_path)
         os.chmod(new_parse_path, 0744)
         data = parser.export()
         data_path = os.path.join(archive_dir, 'data.pickle')
         cPickle.dump(data, open(data_path, 'wb'))
         zip_path = h.zipdir(archive_dir)
         return forward(FileApp(zip_path))
     except Exception, e:
         log.warn(e)
         response.status_int = 400
         return json.dumps({'error': 'An error occured while attempting to export '
                            'morphological parser %s' % id})
开发者ID:jrwdunham,项目名称:old,代码行数:33,代码来源:morphologicalparsers.py


示例3: batch_plate_template_download

    def batch_plate_template_download(self, id=None):
        plate = self.__load_batch_plate(id)
        box2 = Session.query(Box2).get(self.form_result['box2_id'])
        if not plate or not box2:
            abort(404)
            
        code = plate.batch.plate_type.code

        if self.form_result['qc_plate']:
            plate.qc_plate = self.form_result['qc_plate']
            Session.commit()

        # TODO FIXFIX or incorporate into model
        if plate.qc_plate:
            serial = 'QC'
        else:
            serial = box2.name.split(' ')[-1]
        # only mfgco supported right now
        if code == 'mfgco':
            qlt_file = "%s/carryover.qlt" % config['qlb.setup_template_store']
        elif code == 'fvtitr':
            qlt_file = "%s/fvbatch_QC.qlt" % config['qlb.setup_template_store']
        else:
            abort(404)
        
        response.headers['Content-Type'] = 'application/quantalife-template'
        h.set_download_response_header(request, response, "%s_%s.qlt" % (serial, plate.name))
        response.headers['Pragma'] = 'no-cache'
        response.headers['Cache-Control'] = 'no-cache'
        return forward(FileApp(qlt_file, response.headerlist))
开发者ID:v-makarenko,项目名称:vtoolsmq,代码行数:30,代码来源:product.py


示例4: servefile

    def servefile(self, id, file_id):
        """Return the corpus as a file in the format specified in the URL query string.

        :URL: ``PUT /corpora/id/servefile/file_id``.
        :param str id: the ``id`` value of the corpus.
        :param str file_id: the ``id`` value of the corpus file.
        :returns: the file data

        """
        corpus = Session.query(Corpus).get(id)
        if corpus:
            try:
                corpus_file = filter(lambda cf: cf.id == int(file_id), corpus.files)[0]
                corpus_file_path = os.path.join(get_corpus_dir_path(corpus),
                                              '%s.gz' % corpus_file.filename)
                if authorized_to_access_corpus_file(session['user'], corpus_file):
                    return forward(FileApp(corpus_file_path, content_type='application/x-gzip'))
                else:
                    response.status_int = 403
                    return json.dumps(h.unauthorized_msg)
            except Exception:
                response.status_int = 400
                return json.dumps({'error': 'Unable to serve corpus file %d of corpus %d' % (
                        file_id, id)})
        else:
            response.status_int = 404
            return json.dumps({'error': 'There is no corpus with id %s' % id})
开发者ID:jrwdunham,项目名称:old,代码行数:27,代码来源:corpora.py


示例5: beta_qlt

    def beta_qlt(self, id=None):
        c.beta = True

        setup, struct = self.__load_setup(id)
        if not setup:
            abort(404)
        
        quadrant = request.params.get('quadrant', None)
        if not quadrant or quadrant not in ('A','B','C','D','E','F','G','H'):
            abort(404)
        
        plate_layout = struct.get('plate_layout', None)
        if not plate_layout:
            abort(404)
        
        # TODO this line of code sucks (this whole thing sucks)
        if plate_layout[2] in ('s', 'sh', 'sw'):
            qlt_file = "%s/%s" % (config['qlb.setup_template_store'], plate_layout[0])
        else:
            qlt_file = "%s/%s" % (config['qlb.setup_template_store'], (plate_layout[0] % quadrant))
        
        # figure out which plate layout to load
        response.headers['Content-Type'] = 'application/quantalife-template'
        h.set_download_response_header(request, response, "%s.qlt" % ("%s_%s" % (setup.prefix, quadrant)))
        response.headers['Pragma'] = 'no-cache'
        response.headers['Cache-Control'] = 'no-cache'
        return forward(FileApp(qlt_file, response.headerlist))
开发者ID:v-makarenko,项目名称:vtoolsmq,代码行数:27,代码来源:setup.py


示例6: serve_file

def serve_file(file, attachment=False):
    headers = [('Content-Disposition', 'attachment; filename="%s"' % file.filename.encode('utf-8'))]
    content_type, content_encoding = mimetypes.guess_type(file.filename.encode('utf-8'))
    kwargs = {'content_type': content_type}
    if content_type in ['image/png', 'image/jpeg'] and not attachment:
        headers = [('Content-Disposition', 'inline; filename="%s"' % file.filename.encode('utf-8'))]
    return forward(FileApp(file.filepath(), headers=headers, **kwargs))
开发者ID:nous-consulting,项目名称:ututi,代码行数:7,代码来源:files.py


示例7: serve

    def serve(self, id, download=False, **kwargs):
        """Serve a :class:`~mediacore.model.media.MediaFile` binary.

        :param id: File ID
        :type id: ``int``
        :param bool download: If true, serve with an Content-Disposition that
            makes the file download to the users computer instead of playing
            in the browser.
        :raises webob.exc.HTTPNotFound: If no file exists with this ID.
        :raises webob.exc.HTTPNotAcceptable: If an Accept header field
            is present, and if the mimetype of the requested file doesn't
            match, then a 406 (not acceptable) response is returned.

        """
        file = fetch_row(MediaFile, id=id)

        file_path = helpers.file_path(file).encode('utf-8')
        file_type = file.mimetype.encode('utf-8')
        file_name = file.display_name.encode('utf-8')

        if not os.path.exists(file_path):
            log.warn('No such file or directory: %r', file_path)
            raise HTTPNotFound()

        # Ensure the request accepts files with this container
        accept = request.environ.get('HTTP_ACCEPT', '*/*')
        if not mimeparse.best_match([file_type], accept):
            raise HTTPNotAcceptable() # 406

        method = config.get('file_serve_method', None)
        headers = []

        # Serving files with this header breaks playback on iPhone
        if download:
            headers.append(('Content-Disposition',
                            'attachment; filename="%s"' % file_name))

        if method == 'apache_xsendfile':
            # Requires mod_xsendfile for Apache 2.x
            # XXX: Don't send Content-Length or Etag headers,
            #      Apache handles them for you.
            response.headers['X-Sendfile'] = file_path
            response.body = ''
            response.headers.update(headers)
        elif method == 'nginx_redirect':
            for header in ['pragma', 'cache-control', "content-type"]:
                if header in response.headers:
                    del response.headers[header]
            response.headers['X-Accel-Redirect'] = file_path
            response.headers.update(headers)
        else:
            app = FileApp(file_path, headers, content_type=file_type)
            return forward(app)

        response.headers['Content-Type'] = file_type
        for header, value in headers:
            response.headers[header] = value

        return None
开发者ID:kiberpipa,项目名称:mediacore,代码行数:59,代码来源:media.py


示例8: xmlrpc

 def xmlrpc(self, *args, **kw):
     try:
         self.authenticate()
     
     except Exception as e:
         raise e
     
     return forward(RootXMLRPCController())
开发者ID:smarkm,项目名称:ovm,代码行数:8,代码来源:root.py


示例9: retrieve_temp

    def retrieve_temp(self, path):
        """retrieve_temp action is referenced by the <a> button rendered in
        /derived/file/export.html.

        """

        path = os.path.join(config['app_conf']['temporary_store'], path)
        app = FileApp(path)
        return forward(app) 
开发者ID:jrwdunham,项目名称:old-webapp,代码行数:9,代码来源:file.py


示例10: retrieve

    def retrieve(self, path):
        """retrieve action is referenced by the <a>, <img>, <audio>, <video>,
        <embed>, etc. tags.

        """

        path = os.path.join(config['app_conf']['permanent_store'], path)
        app = FileApp(path)
        return forward(app)
开发者ID:jrwdunham,项目名称:old-webapp,代码行数:9,代码来源:file.py


示例11: as_text

    def as_text(cls, slug, username, key):
        filepath = join(cls.datapath, slug, username, '%s.txt' % key)
        headers = [('Content-Type', 'text/plain'), ('Content-Disposition', 'attachment; filename=%s' % key) ]

        try:
            text = forward(FileApp(filepath, headers))
        except OSError:
            abort(404, 'Game does not exist: %s' % slug)
        else:
            return text
开发者ID:DaneTheory,项目名称:turbulenz_local,代码行数:10,代码来源:userdata.py


示例12: download_file

    def download_file(self, id=None):
        self.__setup_box2_code_context(id)
        thefile = self.__file_id_query(c.box2.id, self.form_result['file_id'])
        if not thefile:
            abort(404)

        h.set_download_response_header(request, response, thefile.name)
        response.content_type = thefile.mime_type
        file_path = self.__upload_file_path(c.box2, thefile.path)
        response.headers['Pragma'] = 'no-cache'
        response.headers['Cache-Control'] = 'no-cache'
        return forward(FileApp(file_path, response.headerlist))
开发者ID:v-makarenko,项目名称:vtoolsmq,代码行数:12,代码来源:box2.py


示例13: get

 def get(self, id):
     """
     To get the PDF created previously.
     """
     name = gettempdir() + sep + self.TEMP_FILE_PREFIX + id + self.TEMP_FILE_SUFFIX
     headers = {
         'Content-Length' : getsize(name),
         'Content-Type' : 'application/pdf',
         'Content-Disposition' : 'attachment; filename='+id+'.pdf',
         'Pragma' : 'public',
         'Expires' : '0',
         'Cache-Control' : 'private'
         }
     return forward(FileApp(name, **headers))
开发者ID:mapfish,项目名称:mapfish-archives,代码行数:14,代码来源:printer.py


示例14: validation_download

    def validation_download(self):
        plate_template = Session.query(PlateTemplate).get(self.form_result['plate_template_id'])
        plate_type = Session.query(PlateType).filter_by(code=self.form_result['plate_type_code']).first()
        plate_template.plate_type_id = plate_type.id
        Session.commit()

        response.headers['Content-Type'] = 'application/quantalife-template'
        h.set_download_response_header(request, response, "%s.qlt" % plate_template.prefix)
        response.headers['Pragma'] = 'no-cache'

        # yeah, this is somewhat dangerous...
        template_path = "%s/%s" % (config['qlb.setup_template_store'], os.path.basename(self.form_result['template_name']))

        return forward(FileApp(template_path, response.headerlist))
开发者ID:v-makarenko,项目名称:vtoolsmq,代码行数:14,代码来源:template.py


示例15: download

 def download(self, id=None, *args, **kwargs):
     if id is None:
         abort(404)
     
     qlbwell = Session.query(QLBWell).get(id)
     if not qlbwell:
         abort(404)
     
     if not qlbwell.file:
         abort(404)
     
     storage = QLStorageSource(config)
     response.headers['Content-Type'] = 'application/quantalife-raw'
     h.set_download_response_header(request, response, qlbwell.file.basename)
     return forward(FileApp(storage.qlbwell_path(qlbwell), response.headerlist))
开发者ID:v-makarenko,项目名称:vtoolsmq,代码行数:15,代码来源:well.py


示例16: export

    def export(self, id):
        """Export the parser as a self-contained .zip archive including a Python interface and all required files.

        This allows a user to use the parser locally (assuming they have foma and MITLM installed) via
        the following procedure:

            $ unzip archive.zip
            $ cd archive
            $ ./parse.py chiens chats tombait

        """
        try:
            parser = Session.query(MorphologicalParser).get(id)
            directory = parser.directory
            lib_path = os.path.abspath(os.path.dirname(h.__file__))

            # config.pickle is a dict used to construct the parser (see lib/parse.py)
            config_ = parser.export()
            config_path = os.path.join(directory, 'config.pickle')
            cPickle.dump(config_, open(config_path, 'wb'))

            # cache.pickle is a dict encoding the cached parses of this parser
            cache_dict = parser.cache.export()
            cache_path = os.path.join(directory, 'cache.pickle')
            cPickle.dump(cache_dict, open(cache_path, 'wb'))

            # create the .zip archive, including the files of the parser, the simplelm package,
            # the parser.py module and the parse.py executable.
            zip_path = os.path.join(directory, 'archive.zip')
            zip_file = h.ZipFile(zip_path, 'w')
            #zip_file.write_directory(parser.directory)
            for file_name in os.listdir(directory):
                if (os.path.splitext(file_name)[1] not in ('.log', '.sh', '.zip') and
                    file_name != 'morpheme_language_model.pickle'):
                    zip_file.write_file(os.path.join(directory, file_name))
            zip_file.write_directory(os.path.join(lib_path, 'simplelm'), keep_dir=True)
            zip_file.write_file(os.path.join(lib_path, 'parser.py'))
            zip_file.write_file(os.path.join(lib_path, 'parse.py'))
            zip_file.close()
            return forward(FileApp(zip_path))
        except Exception, e:
            log.warn(e)
            response.status_int = 400
            return json.dumps({'error': 'An error occured while attempting to export '
                'morphological parser %s: %s' % (id, e)})
开发者ID:jrwdunham,项目名称:old,代码行数:45,代码来源:morphologicalparsers.py


示例17: crossdomain_xml

    def crossdomain_xml(self, **kwargs):
        """Serve the crossdomain XML file manually if static_files is disabled.

        If someone forgets to add this Alias we might as well serve this file
        for them and save everyone the trouble. This only works when MediaCore
        is served out of the root of a domain and if Cooliris is enabled.
        """
        global crossdomain_app

        if not request.settings['appearance_enable_cooliris']:
            # Ensure the cache is cleared if cooliris is suddenly disabled
            if crossdomain_app:
                crossdomain_app = None
            raise HTTPNotFound()

        if not crossdomain_app:
            relpath = 'mediacore/public/crossdomain.xml'
            abspath = os.path.join(config['here'], relpath)
            crossdomain_app = FileApp(abspath)

        return forward(crossdomain_app)
开发者ID:Jpoudrier,项目名称:mediacore-community,代码行数:21,代码来源:sitemaps.py


示例18: proxyDownload

 def proxyDownload(self, id=None, tar=False):
     
     if proxyDl==True:
         
         # get path to file with ID id from database
         item = DBSession.query(s.share).filter(s.share.id == id).one()
         host = item.getHost()
         service = item.getService()
         filename = str( item.getShowPath().split("/")[-1] )
         
         if service.username and service.username != "anonymous":
             # uri = "smb://username:[email protected]/path/to/file"
             uri = u"smb://%s:%[email protected]%s%s" % ( service.username, service.password, host.ip, item.getShowPath() )
         else:
             # uri = "smb://hostip/path/to/file"
             uri = u"smb://%s%s" % ( host.ip, item.getShowPath() )
         
         #imports moved to the top
         f = smbfileapp.FileApp(uri)
         return forward(f)
     else: #proxyDl not enabled
         return "<p><strong>proxyDownloader is (currently) not available on this system!</strong><br /><em>Sorry.</em></p>\n"
开发者ID:agrynchuk,项目名称:noodle-ng,代码行数:22,代码来源:root.py


示例19: servecompiled

    def servecompiled(self, id):
        """Serve the compiled foma script of the phonology.

        :URL: ``PUT /phonologies/servecompiled/id``
        :param str id: the ``id`` value of a phonology.
        :returns: a stream of bytes -- the compiled phonology script.  

        """
        phonology = Session.query(Phonology).get(id)
        if phonology:
            if h.foma_installed():
                compiled_path = phonology.get_file_path('binary')
                if os.path.isfile(compiled_path):
                    return forward(FileApp(compiled_path))
                else:
                    response.status_int = 400
                    return json.dumps({'error': 'Phonology %d has not been compiled yet.' % phonology.id})
            else:
                response.status_int = 400
                return json.dumps({'error': 'Foma and flookup are not installed.'})
        else:
            response.status_int = 404
            return json.dumps({'error': 'There is no phonology with id %s' % id})
开发者ID:jrwdunham,项目名称:old,代码行数:23,代码来源:phonologies.py


示例20: serve_arpa

    def serve_arpa(self, id):
        """Serve the generated ARPA file of the morpheme language model.

        :URL: ``PUT /morphologies/serve_arpa/id``
        :param str id: the ``id`` value of a morpheme language model.
        :returns: a stream of bytes -- the ARPA file of the LM.

        """
        lm = Session.query(MorphemeLanguageModel).get(id)
        if lm:
            arpa_path = lm.get_file_path('arpa')
            if os.path.isfile(arpa_path):
                if authorized_to_access_arpa_file(session['user'], lm):
                    return forward(FileApp(arpa_path, content_type='text/plain'))
                else:
                    response.status_int = 403
                    return json.dumps(h.unauthorized_msg)
            else:
                response.status_int = 404
                return json.dumps({'error':
                    'The ARPA file for morpheme language model %s has not been compiled yet.' % id})
        else:
            response.status_int = 404
            return json.dumps({'error': 'There is no morpheme language model with id %s' % id})
开发者ID:FieldDB,项目名称:old,代码行数:24,代码来源:morphemelanguagemodels.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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