コード例 #1
0
ファイル: views.py プロジェクト: travisperson/pbnh
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
ファイル: views.py プロジェクト: travisperson/pbnh
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
ファイル: views.py プロジェクト: travisperson/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:
        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)