Пример #1
0
def put(uuid):
    content, filename = request_content()
    if not content:
        return "Nope.\n", 400

    id, digest = model.get_digest(content)
    if id or digest:
        url = id_url(b66=id) if id else id_url(sha1=digest)
        return redirect(url, "Paste already exists.\n", 409)

    id, digest = model.put(uuid.bytes, content)
    if id or digest:
        url = id_url(b66=(id, filename)) if id else id_url(sha1=digest)
        return redirect(url, "{} updated.\n".format(url), 200)

    return "Not found.\n", 404
Пример #2
0
def put(uuid):
    content, filename = request_content()
    if not content:
        return "Nope.\n", 400

    id, digest = model.get_digest(content)
    if id or digest:
        url = id_url(b66=id) if id else id_url(sha1=digest)
        return redirect(url, "Paste already exists.\n", 409)

    id, digest = model.put(uuid.bytes, content)
    if id or digest:
        url = id_url(b66=(id, filename)) if id else id_url(sha1=digest)
        return redirect(url, "{} updated.\n".format(url), 200)

    return "Not found.\n", 404
Пример #3
0
def get(b66):
    id, name = b66
    content = model.get_content(id)
    if not content:
        return 'Not found.\n', 404

    content = content.decode('utf-8')

    return redirect(content, '{}\n'.format(content))
Пример #4
0
def get(b66):
    id, name = b66
    content = model.get_content(id)
    if not content:
        return 'Not found.\n', 404

    content = content.decode('utf-8')

    return redirect(content, '{}\n'.format(content))
Пример #5
0
def post():
    content, _ = request_content()
    if not content:
        return "Nope.\n", 400

    content = content.decode('utf-8').split('\n')[0].encode('utf-8')

    id = model.get_digest(content)
    if not id:
        id = model.insert(content)

    url = id_url(b66=id)
    return redirect(url, "{}\n".format(url), 200)
Пример #6
0
def post():
    content, _ = request_content()
    if not content:
        return "Nope.\n", 400

    content = content.decode('utf-8').split('\n')[0].encode('utf-8')

    id = model.get_digest(content)
    if not id:
        id = model.insert(content)

    url = id_url(b66=id)
    return redirect(url, "{}\n".format(url), 200)
Пример #7
0
def url():
    stream, _ = request_content()
    if not stream:
        return "Nope.\n", 400

    stream = BytesIO(stream.read().decode('utf-8').split()[0].encode('utf-8'))

    cur = model.get_digest(stream)
    if not cur.count():
        url = model.insert(stream, redirect=1)
    else:
        url = cur.__next__()

    url = id_url(sid=url['digest'])
    return redirect(url, "{}\n".format(url), 200)
Пример #8
0
def post():
    content, filename = request_content()
    if not content:
        return "Nope.\n", 400

    uuid = None
    id, digest = model.get_digest(content)
    if not id and not digest:
        if request.form.get('p'):
            digest, uuid = model.insert_private(content)
        else:
            id, uuid = model.insert(content)

    url = id_url(b66=(id, filename)) if id else id_url(sha1=(digest, filename))
    uuid = str(UUID(bytes=uuid)) if uuid else '<redacted>'
    return redirect(url, safe_dump(dict(url=url, uuid=uuid), default_flow_style=False))
Пример #9
0
def post():
    content, filename = request_content()
    if not content:
        return "Nope.\n", 400

    uuid = None
    id, digest = model.get_digest(content)
    if not id and not digest:
        if request.form.get('p'):
            digest, uuid = model.insert_private(content)
        else:
            id, uuid = model.insert(content)

    url = id_url(b66=(id, filename)) if id else id_url(sha1=(digest, filename))
    uuid = str(UUID(bytes=uuid)) if uuid else '<redacted>'
    return redirect(
        url, safe_dump(dict(url=url, uuid=uuid), default_flow_style=False))
Пример #10
0
def get(sid=None, sha1=None, label=None, lexer=None, handler=None):
    cur = None
    if sid:
        sid, name, value = sid
        cur = model.get_content(**{
            '$or' : [
                {
                    'digest': {
                        '$regex': '{}$'.format(sid)
                    }
                },
                {
                    'label' : value
                }
            ],
            'private': {
                '$exists': False
            }
        })
    if sha1:
        digest, name = sha1[:2]
        cur = model.get_content(digest = digest).hint([('digest', 1)])
    if label:
        label, name = label
        cur = model.get_content(label = label).hint([('label', 1)])

    if not cur or not cur.count():
        return "Not found.\n", 404

    paste = cur.__next__()
    content = model._get(paste.get('content'))

    if paste.get('redirect'):
        content = content.decode('utf-8')
        return redirect(content, '{}\n'.format(content))

    mimetype, _ = guess_type(name)

    if lexer != None:
        return highlight(content, lexer)
    if handler != None:
        return _handler.get(handler, content, mimetype)
    if mimetype:
        return Response(content, mimetype=mimetype)

    return content
Пример #11
0
def get(sid=None, sha1=None, label=None, lexer=None, handler=None):
    cur = None
    if sid:
        sid, name, value = sid
        cur = model.get_content(**{
            '$or' : [
                {
                    'digest': {
                        '$regex': '{}$'.format(sid)
                    }
                },
                {
                    'label' : value
                }
            ],
            'private': {
                '$exists': False
            }
        })
    if sha1:
        digest, name = sha1[:2]
        cur = model.get_content(digest = digest).hint([('digest', 1)])
    if label:
        label, name = label
        cur = model.get_content(label = label).hint([('label', 1)])

    if not cur or not cur.count():
        return "Not found.\n", 404

    paste = cur.__next__()
    if paste.get('sunset'):
        request.max_age = (paste['date'] + timedelta(seconds=paste['sunset'])) - datetime.utcnow()
        if request.max_age < timedelta():
            request.max_age = 0
        else:
            request.max_age = request.max_age.seconds

        if paste['date'] + timedelta(seconds=paste['sunset']) < datetime.utcnow():
            max_age = datetime.utcnow() - (paste['date'] + timedelta(seconds=paste['sunset']))
            uuid = UUID(hex=paste['_id'])
            paste = invalidate(uuid)
            result = model.delete(uuid)
            if not result['n']:
                return "This should not happen.", 500
            return complex_response(paste, status="expired")

    content = model._get(paste.get('content'))

    if paste.get('redirect'):
        content = content.decode('utf-8')
        return redirect(content, '{}\n'.format(content))

    mimetype, _ = guess_type(name)
    if not mimetype:
        mimetype = paste.get('mimetype')

    if lexer != None:
        return highlight(content, lexer)
    if handler != None:
        return _handler.get(handler, content, mimetype)
    if mimetype:
        return Response(content, mimetype=mimetype)

    return content
Пример #12
0
def delete(uuid):
    id, digest = model.delete(uuid.bytes)
    if id or digest:
        url = id_url(b66=id) if id else id_url(sha1=digest)
        return redirect(url, "{} deleted.\n".format(url), 200)
    return "Not found.\n", 404
Пример #13
0
def delete(uuid):
    id, digest = model.delete(uuid.bytes)
    if id or digest:
        url = id_url(b66=id) if id else id_url(sha1=digest)
        return redirect(url, "{} deleted.\n".format(url), 200)
    return "Not found.\n", 404