def create_paste(): """Create Pastes. On successful POST this API will return a URL with the <pasted_id> for the newly created content. POST content must be in JSON format and contain the key "content" > "{'content': 'example'}" :returns: str """ request = flask.request try: content = request.json['content'] _, url, _ = backend.write(content, backend='show_paste') except ValueError: raise exceptions.BadRequest('Missing paste content.') else: return_url = urlparse.urljoin(request.url, url) + '.raw' return_headers = { 'Content-Type': 'text/plain; charset="utf-8"', 'Location': return_url } return_headers.update(CACHE_HEADERS) return return_url, 201, return_headers
def create_links(): """Create shortened links. On successful POST this API will return a URL with the <pasted_id> for the newly created content. The link shortener will validate the content is a "valid" URL before writting the specific content and returning the data. POST content must be in JSON format and contain the key "content" > "{'content': 'example'}" :returns: str """ request = flask.request try: content = request.json['content'] valid_url = urlparse.urlparse(content) if valid_url.scheme and valid_url.netloc: _, url, _ = backend.write(content, backend='show_link', truncate=16) else: raise exceptions.BadRequest('No valid URL provided') except ValueError: raise exceptions.BadRequest('Missing link content') else: return_url = urlparse.urljoin(request.url, url) return_headers = { 'Content-Type': 'text/plain; charset="utf-8"', 'Location': return_url } return_headers.update(CACHE_HEADERS) return return_url, 201, return_headers
def links_index(): urlform = forms.UrlForm() if urlform.validate_on_submit(): key, url, created = backend.write(urlform.content.data, backend='show_link', truncate=16) if created: flask.flash('Link created', 'success') else: flask.flash('Link found', 'primary') response = flask.make_response( flask.redirect(flask.url_for('show_link_data', pasted_id=key)) ) response.headers['X-XSS-Protection'] = '0' response.headers = _add_headers(response.headers) return response else: log.warning('Form validation failed') for values in urlform.errors.values(): for value in values: log.warning('urlform errors', error=value) flask.flash(value, 'danger') return flask.render_template( 'post_links.html', urlform=urlform, pasted_page_description='Shorten links, make connections.' )
def pastes_index(): pasteform = forms.PasteForm() if pasteform.validate_on_submit(): key, url, created = backend.write(pasteform.content.data, backend='show_paste') if created: flask.flash('Paste created', 'success') else: flask.flash('Paste found', 'primary') response = flask.make_response( flask.redirect(flask.url_for('show_paste', pasted_id=key)) ) response.headers['X-XSS-Protection'] = '0' response.headers['X-RAW-Location'] = flask.url_for( 'show_paste_raw', pasted_id=key, _external=True ) response.headers = _add_headers(response.headers) return response else: log.warning('Form validation failed') for values in pasteform.errors.values(): for value in values: log.warning('urlform errors', error=value) flask.flash(value, 'danger') return flask.render_template( 'post_pastes.html', pasteform=pasteform, pasted_page_description='Create content, tell a story.' )
def pastes_index(): request = flask.request pasteform = forms.PasteForm() if pasteform.validate_on_submit(): content = request.form['content'] _, url, created = backend.write(content, backend='show_paste') if created: flask.flash('Paste created', 'success') status = 201 else: flask.flash('Paste found', 'primary') status = 200 raw_request_url = urlparse.urljoin(request.url, url) + '.raw' response = flask.make_response( flask.render_template('return_paste.html', url=url, content=content, remote_url=urlparse.urljoin( request.url, url), paste_url=raw_request_url, form=pasteform), status) response.headers['X-XSS-Protection'] = '0' response.headers = _add_headers(response.headers) return response else: return flask.render_template('post_pastes.html', pasteform=pasteform)
def links_index(): request = flask.request urlform = forms.UrlForm() if urlform.validate_on_submit(): content = request.form['content'] key, local_pasted_url, created = backend.write(content, backend='show_link', truncate=16) if created: flask.flash('Link created', 'success') status = 201 else: flask.flash('Link found', 'primary') status = 200 response = flask.make_response( flask.render_template( 'return_link.html', go_to_remote_url=local_pasted_url, content=content, remote_url=urlparse.urljoin(request.url_root, local_pasted_url), help_url=urlparse.urljoin(request.url_root, 'links/' + key), form=urlform), status) response.headers['X-XSS-Protection'] = '0' response.headers = _add_headers(response.headers) return response else: return flask.render_template('post_links.html', urlform=urlform)
def create_paste(): request = flask.request try: content = request.json['content'] _, url, _ = backend.write(content, backend='show_paste') except ValueError: raise exceptions.BadRequest('Missing paste content.') else: return_headers = {'Content-Type': 'text/plain; charset="utf-8"'} return_headers.update(CACHE_HEADERS) return urlparse.urljoin(request.url, url) + '.raw', 201, return_headers
def index(): request = flask.request urlform = forms.UrlForm() pasteform = forms.PasteForm() created = False status = 200 if urlform.validate_on_submit(): content = request.form['content'] _, _, created = backend.write(content, backend='show_link', truncate=16) elif pasteform.validate_on_submit(): content = request.form['content'] _, _, created = backend.write(content, backend='show_paste') if created: flask.flash('quick paste created', 'success') status = 201 else: flask.flash('quick paste created', 'primary') return flask.render_template('index.html', urlform=urlform, pasteform=pasteform), status
def create_paste(): request = flask.request try: content = request.json['content'] valid_url = urlparse.urlparse(content) if valid_url.scheme and valid_url.netloc: _, url, _ = backend.write(content, backend='show_link') else: raise exceptions.BadRequest('No valid URL provided') except ValueError: raise exceptions.BadRequest('Missing link content') else: return_headers = {'Content-Type': 'text/plain; charset="utf-8"'} return_headers.update(CACHE_HEADERS) return urlparse.urljoin(request.url, url), 201, return_headers