示例#1
0
def view_paste_with_extension(paste_id, filetype):
    query = util.getPaste(paste_id)
    if not query:
        return fourohfour()
    data = query.get('data')
    mime = util.getMime(mimestr=filetype)
    data = io.BytesIO(query.get('data'))
    return Response(data, mimetype=mime)
示例#2
0
def view_paste_with_highlighting(paste_id, filetype):
    query = util.getPaste(paste_id)
    if not query:
        return fourohfour()
    data = query.get('data')
    mime = util.getMime(mimestr=filetype)
    print(mime)
    return render_template('paste.html', paste=data.decode('utf-8'),
            mime=mime)
示例#3
0
文件: views.py 项目: Endi1/pbnh
def view_paste_with_highlighting(paste_id, filetype):
    if not filetype:
        filetype = 'txt'
    query = util.getPaste(paste_id)
    if not query:
        return fourohfour()
    data = query.get('data')
    try:
        return render_template('paste.html', paste=data.decode('utf-8'),
                mime=filetype)
    except UnicodeDecodeError:
        return fourohfour()
示例#4
0
def view_paste_with_highlighting(paste_id, filetype):
    if not filetype:
        filetype = 'txt'
    query = util.getPaste(paste_id)
    if not query:
        abort(404)
    data = query.get('data')
    try:
        return render_template('paste.html', paste=data.decode('utf-8'),
                mime=filetype)
    except UnicodeDecodeError:
        return abort(500)
示例#5
0
文件: views.py 项目: Endi1/pbnh
def view_paste_with_extension(paste_id, filetype):
    query = util.getPaste(paste_id)
    if not query:
        return fourohfour()
    if filetype == 'md':
        data = query.get('data').decode('utf-8')
        return render_template('markdown.html', paste=data)
    if filetype == 'rst':
        data = query.get('data').decode('utf-8')
        return Response(publish_parts(data, writer_name='html')['html_body'])
    data = io.BytesIO(query.get('data'))
    mime = util.getMime(mimestr=filetype)
    return Response(data, mimetype=mime)
示例#6
0
文件: views.py 项目: Endi1/pbnh
def view_paste_with_extension(paste_id, filetype):
    query = util.getPaste(paste_id)
    if not query:
        return fourohfour()
    if filetype == 'md':
        data = query.get('data').decode('utf-8')
        return render_template('markdown.html', paste=data)
    if filetype == 'rst':
        data = query.get('data').decode('utf-8')
        return Response(publish_parts(data, writer_name='html')['html_body'])
    data = io.BytesIO(query.get('data'))
    mime = util.getMime(mimestr=filetype)
    return Response(data, mimetype=mime)
示例#7
0
def view_paste(paste_id):
    """
    If there are no extensions or slashes check if the mimetype is text, if it
    is text attempt to highlight it. If not return the data and set the mimetype
    so the browser can attempt to render it.
    """
    query = util.getPaste(paste_id)
    if not query:
        return fourohfour()
    mime = query.get('mime')
    data = query.get('data')
    if mime.split('/')[0] == 'text':
        return render_template('paste.html', paste=data.decode('utf-8'),
                mime=mime)
    else:
        data = io.BytesIO(query.get('data'))
        return send_file(data, mimetype=mime)
    return fourohfour()
示例#8
0
文件: views.py 项目: bhanderson/pbnh
def view_paste(paste_id):
    """
    If there are no extensions or slashes check if the mimetype is text, if it
    is text attempt to highlight it. If not return the data and set the
    mimetype so the browser can attempt to render it.
    """
    query = util.getPaste(paste_id)
    if not query:
        abort(404)
    mime = query.get('mime')
    data = query.get('data')
    if mime == 'redirect':
        return redirect(data, code=302)
    if mime.startswith('text/'):
        return render_template('paste.html', paste=data.decode('utf-8'),
                               mime=mime)
    else:
        data = io.BytesIO(query.get('data'))
        return send_file(data, mimetype=mime)
示例#9
0
def view_paste(paste_id):
    """
    If there are no extensions or slashes check if the mimetype is text, if it
    is text attempt to highlight it. If not return the data and set the mimetype
    so the browser can attempt to render it.
    """
    query = util.getPaste(paste_id)
    if not query:
        abort(404)
    mime = query.get('mime')
    data = query.get('data')
    if mime == 'redirect':
        return redirect(data, code=302)
    if mime.startswith('text/'):
        return render_template('paste.html', paste=data.decode('utf-8'),
                mime=mime)
    else:
        data = io.BytesIO(query.get('data'))
        return send_file(data, mimetype=mime)