本文整理汇总了Python中pylons.controllers.util.forward函数的典型用法代码示例。如果您正苦于以下问题:Python forward函数的具体用法?Python forward怎么用?Python forward使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了forward函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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})
示例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})
示例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))
示例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})
示例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))
示例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))
示例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
示例8: xmlrpc
def xmlrpc(self, *args, **kw):
try:
self.authenticate()
except Exception as e:
raise e
return forward(RootXMLRPCController())
示例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)
示例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)
示例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
示例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))
示例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))
示例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))
示例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))