dpaste documentation · -e debug=true \-e secret_key=very-secret-key \-e port=12345 \...

31
dpaste Documentation Martin Mahner Jul 29, 2020

Upload: others

Post on 06-Jul-2020

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

Martin Mahner

Jul 29, 2020

Page 2: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste
Page 3: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

Contents

1 Documentation 3

HTTP Routing Table 27

i

Page 4: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

ii

Page 5: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

Full documentation on https://dpaste.readthedocs.io/

dpaste is a pastebin application written in Python using the Django framework. You can find a live installation ondpaste.de.

The project is intended to run standalone as any regular Django Project, but it’s also possible to install it into anexisting project as a typical Django application.

The code is open source and available on Github: https://github.com/bartTC/dpaste. If you found bugs, have problemsor ideas with the project or the website installation, please create an Issue there.

dpaste requires at a minimum Python 3.6 and Django 2.2.

Contents 1

Page 6: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

2 Contents

Page 7: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

CHAPTER 1

Documentation

1.1 Installation

There are various ways to install and deploy dpaste. See the guides below:

1.1.1 dpaste with Docker

dpaste Docker images are available to pull from the Docker Hub.

Quickstart to run a dpaste container image:

$ docker run --rm -p 8000:8000 barttc/dpaste:latest

The dpaste image serves the project using uWSGi and is ready for production-like environments. However it’s en-couraged to use an external database to store the data. See the example below for all available options, specificallyDATABASE_URL:

$ docker run --rm --name db1 --detach postgres:latest$ docker run --rm -p 12345:12345 \

--link db1 \-e DATABASE_URL=postgres://postgres@db1:5432/postgres \-e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \barttc/dpaste:latest

1.1.2 Integration into an existing Django project

Install the latest dpaste release in your environment. This will install all necessary dependencies of dpaste as well:

$ pip install dpaste

3

Page 8: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

Add dpaste.apps.dpasteAppConfig to your INSTALLED_APPS list:

INSTALLED_APPS = ('django.contrib.sessions',# ...'dpaste.apps.dpasteAppConfig',

)

Add dpaste and the (optiona) dpaste_api url patterns:

urlpatterns = patterns('',# ...

url(r'my-pastebin/', include('dpaste.urls.dpaste')),url(r'my-pastebin/api/', include('dpaste.urls.dpaste_api')),

)

Finally, migrate the database schema:

$ manage.py migrate dpaste

1.1.3 dpaste with docker-compose for local development

The project’s preferred way for local development is docker-compose:

$ docker-compose up

This will open the Django runserver on http://127.0.0.1:8000. Changes to the code are automatically reflected in theDocker container and the runserver will reload automatically.

Upon first run you will need to migrate the database. Do that in a separate terminal window:

$ docker-compose run --rm app ./manage.py migrate

1.1.4 dpaste with virtualenv for local development

If you prefer the classic local installation using Virtualenv then you can do so. There’s no magic involved.

Example:

$ python3 -m venv .venv$ source .venv/bin/activate$ pip install -e .[dev]$ ./manage.py migrate$ ./manage.py runserver

1.1.5 CSS and Javascript development

Static files are stored in the client/ directory and must get compiled and compressed before being used on thewebsite.

$ npm install

There are some helper scripts you can invoke with make

4 Chapter 1. Documentation

Page 9: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

make js Compile only JS files.

make css Compile only CSS files.

make css-watch Same as build-css but it automatically watches for changes in the CSS files and re-compiles it.

After compilation the CSS and JS files are stored in dpaste/static/ where they are picked up by Django (andDjango’s collectstatic command).

Note: These files are not commited to the project repository, however they are part of the pypi wheel package, sinceusers couldn’t compile those once they are within Python’s site-packages.

1.2 Testing

1.2.1 Testing with Tox

dpaste is continuously tested online with Travis. You can also run the test suite locally with tox. Tox automaticallytests the project against multiple Python and Django versions.

$ pip install tox

Then simply call it from the project directory.

$ cd dpaste/$ tox

Listing 1: Example tox output:

$ tox

py35-django-111 create: /tmp/tox/dpaste/py35-django-111SKIPPED:InterpreterNotFound: python3.5py36-django-111 create: /tmp/tox/dpaste/py36-django-111py36-django-111 installdeps: django>=1.11,<1.12py36-django-111 inst: /tmp/tox/dpaste/dist/dpaste-3.0a1.zip

...................----------------------------------------------------------------------Ran 48 tests in 1.724sOK

SKIPPED: py35-django-111: InterpreterNotFound: python3.5SKIPPED: py35-django-20: InterpreterNotFound: python3.5py36-django-111: commands succeededpy36-django-20: commands succeededcongratulations :)

1.2. Testing 5

Page 10: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

1.3 Management Commands

1.3.1 Purge expired snippets

Snippets are removed as soon as they exceed their expiration date and get fetched by a client, however if they neverget fetched this isn’t triggered. dpaste ships with a management command cleanup_snippets that removes theseexpired snippets.

It’s sufficient to run it daily.

To run it locally do:

$ pipenv run ./managepy cleanup_snippets

Options

--dry-run Does not actually delete the snippets. This is useful for local testing.

Setup a Crontab

A crontab line might look like:

1 20 * * * /srv/dpaste.de/pipenv run manage.py cleanup_snippets > /dev/null

Note: If you use the database session backend, you may also need to setup a crontab that removes the expired entriesfrom the session database.

See the related Django Documentation for details.

1.4 Settings

When dpaste is installed as a standalone service or integrated into an existing project there are various settings you canoverride to adjust dpaste’s behavior.

To do so, you need to override dpaste’s AppConfig. This is a feature introduced in Django 1.9 and allows you to setsettings more programmatically.

See Current AppConfig with default values for a full list of settings and functions you can override.

1.4.1 Example for your custom AppConfig:

# settings.pyfrom dpaste.apps import dpasteAppConfig

class MyBetterDpasteAppConfig(dpasteAppConfig):SLUG_LENGTH = 8LEXER_DEFAULT = 'js'

# ...

(continues on next page)

6 Chapter 1. Documentation

Page 11: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

(continued from previous page)

INSTALLED_APPS = ['myproject.settings.MyBetterDpasteAppConfig',

]

1.4.2 Current AppConfig with default values

This is the file content of dpaste/apps.py:

from django.apps import AppConfig, appsfrom django.utils.safestring import mark_safefrom django.utils.translation import gettext_lazy as _

class dpasteAppConfig(AppConfig):name = "dpaste"verbose_name = "dpaste"

# The application title used throughout the user interface.APPLICATION_NAME = "dpaste"

# This content is loaded in the <head> section of each template.# You can use it to add any HTML tags, specifically custom CSS styles.# This may can give you an easier way to adjust the UI to your needs# than having to add a template folder, plus custom template, plus# css static file etc.## Example:## EXTRA_HEAD_HTML = """# <style type="text/css"># header{ background-color: red; }# .btn { background-color: blue; border: 3px solid yellow; }# </style># """EXTRA_HEAD_HTML = ""

# HTML content injected in the About pageEXTRA_POST_ABOUT = ""

# HTML content injeted after the "New snippet" formEXTRA_POST_NEW = ""

# HTML content injected at the end of every formEXTRA_POST_FORM = ""

# Integer. Length of the random slug for each new snippet. In the rare# case an existing slug is generated again, the length will increase by# one more character.SLUG_LENGTH = 4

# String. A string of characters which are used to create the random slug.# This is intentionally missing l and I as they look too similar with# sans-serif fonts.SLUG_CHOICES = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ1234567890"

(continues on next page)

1.4. Settings 7

Page 12: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

(continued from previous page)

# String. The lexer key that is pre-selected in the dropdown. Note that# this is only used if the user has not saved a snippet before, otherwiseLEXER_DEFAULT = "python"

# Integer. Maximum number of bytes per snippet.MAX_CONTENT_LENGTH = 250 * 1024 * 1024

# A tuple of seconds and a descriptive string used in the lexer# expiration dropdown. Example::## from django.utils.translation import gettext_lazy as _# DPASTE_EXPIRE_CHOICES = (# (3600, _('In one hour')),# (3600 * 24 * 7, _('In one week')),# (3600 * 24 * 30, _('In one month')),# (3600 * 24 * 30 * 12 * 100, _('100 Years')),# )## **Infinite snippets** are supported. You can keep snippets forever when# you set the choice key to ``never``. The management command will ignore# these snippets::## from django.utils.translation import gettext_lazy as _# DPASTE_EXPIRE_CHOICES = (# (3600, _('In one hour')),# ('never', _('Never')),# )EXPIRE_CHOICES = (

("onetime", _("One-Time snippet")),(3600, _("Expire in one hour")),(3600 * 24 * 7, _("Expire in one week")),(3600 * 24 * 30, _("Expire in one month")),("never", _("Never Expire")),

)

# Default value for ``EXPIRE_CHOICES``EXPIRE_DEFAULT = 3600 * 24 * 7

# **One-Time snippets** are supported. One-Time snippets are automatically# deleted once a defined view count has reached (Default: ``2``). To# enable one-time snippets you have to add a choice ``onetime`` to the# expire choices::## from django.utils.translation import gettext_lazy as _# DPASTE_EXPIRE_CHOICES = (# ('onetime', _('One-Time snippet')),# (3600, _('In one hour')),# (3600 * 24 * 7, _('In one week')),# (3600 * 24 * 30, _('In one month')),# )## You can also set the maximum view count after what the snippet gets# deleted. The default is ``2``. One view is from the author, one view# is from another user.ONETIME_LIMIT = 2

(continues on next page)

8 Chapter 1. Documentation

Page 13: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

(continued from previous page)

# Disable "view Raw" mode.RAW_MODE_ENABLED = True

# If enabled, the "raw View" mode will display the snippet content as# plain text rather rendered in a template.RAW_MODE_PLAIN_TEXT = True

# Lexers which have wordwrap enabled by defaultLEXER_WORDWRAP = ("rst",)

# Key names of the default text and code lexer.PLAIN_TEXT_SYMBOL = "_text"PLAIN_CODE_SYMBOL = "_code"

@propertydef TEXT_FORMATTER(self):

"""Choices list with all "Text" lexer. Prepend keys with an underscoreso they don't accidentally clash with a Pygments Lexer name.

Each list contains a lexer tuple of:

(Lexer key,Lexer Display Name,Lexer Highlight Class)

If the Highlight Class is not given, PygmentsHighlighter is used."""from dpaste.highlight import (

PlainTextHighlighter,MarkdownHighlighter,RestructuredTextHighlighter,

)

return [(self.PLAIN_TEXT_SYMBOL, "Plain Text", PlainTextHighlighter),("_markdown", "Markdown", MarkdownHighlighter),("_rst", "reStructuredText", RestructuredTextHighlighter),

]

@propertydef CODE_FORMATTER(self):

"""Choices list with all "Code" Lexer. Each listcontains a lexer tuple of:

(Lexer key,Lexer Display Name,Lexer Highlight Class)

If the Highlight Class is not given, PygmentsHighlighter is used.

To get a current list of available lexers in Pygements do:

>>> from pygments import lexers>>> sorted([(i[1][0], i[0]) for i in lexers.get_all_lexers()])[('abap', 'ABAP'),

(continues on next page)

1.4. Settings 9

Page 14: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

(continued from previous page)

('abnf', 'ABNF'),('ada', 'Ada'),..."""from dpaste.highlight import PlainCodeHighlighter

return [(self.PLAIN_CODE_SYMBOL, "Plain Code", PlainCodeHighlighter),# ('abap', 'ABAP'),# ('abnf', 'ABNF'),# ('ada', 'Ada'),# ('adl', 'ADL'),# ('agda', 'Agda'),# ('aheui', 'Aheui'),# ('ahk', 'autohotkey'),# ('alloy', 'Alloy'),# ('ampl', 'Ampl'),# ('antlr', 'ANTLR'),# ('antlr-as', 'ANTLR With ActionScript Target'),# ('antlr-cpp', 'ANTLR With CPP Target'),# ('antlr-csharp', 'ANTLR With C# Target'),# ('antlr-java', 'ANTLR With Java Target'),# ('antlr-objc', 'ANTLR With ObjectiveC Target'),# ('antlr-perl', 'ANTLR With Perl Target'),# ('antlr-python', 'ANTLR With Python Target'),# ('antlr-ruby', 'ANTLR With Ruby Target'),# ('apacheconf', 'ApacheConf'),# ('apl', 'APL'),("applescript", "AppleScript"),("arduino", "Arduino"),# ('as', 'ActionScript'),# ('as3', 'ActionScript 3'),# ('aspectj', 'AspectJ'),# ('aspx-cs', 'aspx-cs'),# ('aspx-vb', 'aspx-vb'),# ('asy', 'Asymptote'),# ('at', 'AmbientTalk'),# ('autoit', 'AutoIt'),# ('awk', 'Awk'),# ('basemake', 'Base Makefile'),("bash", "Bash"),("bat", "Batchfile"),# ('bbcode', 'BBCode'),# ('bc', 'BC'),# ('befunge', 'Befunge'),# ('bib', 'BibTeX'),# ('blitzbasic', 'BlitzBasic'),# ('blitzmax', 'BlitzMax'),# ('bnf', 'BNF'),# ('boo', 'Boo'),# ('boogie', 'Boogie'),# ('brainfuck', 'Brainfuck'),# ('bro', 'Bro'),# ('bst', 'BST'),# ('bugs', 'BUGS'),("c", "C"),# ('c-objdump', 'c-objdump'),

(continues on next page)

10 Chapter 1. Documentation

Page 15: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

(continued from previous page)

# ('ca65', 'ca65 assembler'),# ('cadl', 'cADL'),# ('camkes', 'CAmkES'),# ('capdl', 'CapDL'),# ('capnp', "Cap'n Proto"),# ('cbmbas', 'CBM BASIC V2'),# ('ceylon', 'Ceylon'),# ('cfc', 'Coldfusion CFC'),# ('cfengine3', 'CFEngine3'),# ('cfm', 'Coldfusion HTML'),# ('cfs', 'cfstatement'),# ('chai', 'ChaiScript'),# ('chapel', 'Chapel'),# ('cheetah', 'Cheetah'),# ('cirru', 'Cirru'),# ('clay', 'Clay'),# ('clean', 'Clean'),("clojure", "Clojure"),# ('clojurescript', 'ClojureScript'),("cmake", "CMake"),# ('cobol', 'COBOL'),# ('cobolfree', 'COBOLFree'),("coffee-script", "CoffeeScript"),("common-lisp", "Common Lisp"),# ('componentpascal', 'Component Pascal'),("console", "Console/Bash Session"),# ('control', 'Debian Control file'),# ('coq', 'Coq'),# ('cpp', 'C++'),# ('cpp-objdump', 'cpp-objdump'),# ('cpsa', 'CPSA'),# ('cr', 'Crystal'),# ('crmsh', 'Crmsh'),# ('croc', 'Croc'),# ('cryptol', 'Cryptol'),("csharp", "C#"),# ('csound', 'Csound Orchestra'),# ('csound-document', 'Csound Document'),# ('csound-score', 'Csound Score'),("css", "CSS"),# ('css+django', 'CSS+Django/Jinja'),# ('css+erb', 'CSS+Ruby'),# ('css+genshitext', 'CSS+Genshi Text'),# ('css+lasso', 'CSS+Lasso'),# ('css+mako', 'CSS+Mako'),# ('css+mozpreproc', 'CSS+mozpreproc'),# ('css+myghty', 'CSS+Myghty'),# ('css+php', 'CSS+PHP'),# ('css+smarty', 'CSS+Smarty'),# ('cucumber', 'Gherkin'),("cuda", "CUDA"),# ('cypher', 'Cypher'),# ('cython', 'Cython'),# ('d', 'D'),# ('d-objdump', 'd-objdump'),("dart", "Dart"),("delphi", "Delphi"),

(continues on next page)

1.4. Settings 11

Page 16: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

(continued from previous page)

# ('dg', 'dg'),("diff", "Diff"),("django", "Django/Jinja"),("docker", "Docker"),# ('doscon', 'MSDOS Session'),# ('dpatch', 'Darcs Patch'),# ('dtd', 'DTD'),# ('duel', 'Duel'),# ('dylan', 'Dylan'),# ('dylan-console', 'Dylan session'),# ('dylan-lid', 'DylanLID'),# ('earl-grey', 'Earl Grey'),# ('easytrieve', 'Easytrieve'),# ('ebnf', 'EBNF'),# ('ec', 'eC'),# ('ecl', 'ECL'),# ('eiffel', 'Eiffel'),("elixir", "Elixir"),# ('elm', 'Elm'),# ('emacs', 'EmacsLisp'),# ('erb', 'ERB'),# ('erl', 'Erlang erl session'),("erlang", "Erlang"),# ('evoque', 'Evoque'),# ('extempore', 'xtlang'),# ('ezhil', 'Ezhil'),# ('factor', 'Factor'),# ('fan', 'Fantom'),# ('fancy', 'Fancy'),# ('felix', 'Felix'),# ('fennel', 'Fennel'),# ('fish', 'Fish'),# ('flatline', 'Flatline'),# ('forth', 'Forth'),# ('fortran', 'Fortran'),# ('fortranfixed', 'FortranFixed'),# ('foxpro', 'FoxPro'),# ('fsharp', 'FSharp'),# ('gap', 'GAP'),# ('gas', 'GAS'),# ('genshi', 'Genshi'),# ('genshitext', 'Genshi Text'),# ('glsl', 'GLSL'),# ('gnuplot', 'Gnuplot'),("go", "Go"),# ('golo', 'Golo'),# ('gooddata-cl', 'GoodData-CL'),# ('gosu', 'Gosu'),# ('groff', 'Groff'),# ('groovy', 'Groovy'),# ('gst', 'Gosu Template'),# ('haml', 'Haml'),("handlebars", "Handlebars"),("haskell", "Haskell"),# ('haxeml', 'Hxml'),# ('hexdump', 'Hexdump'),# ('hlsl', 'HLSL'),

(continues on next page)

12 Chapter 1. Documentation

Page 17: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

(continued from previous page)

# ('hsail', 'HSAIL'),("html", "HTML"),# ('html+cheetah', 'HTML+Cheetah'),("html+django", "HTML + Django/Jinja"),# ('html+evoque', 'HTML+Evoque'),# ('html+genshi', 'HTML+Genshi'),# ('html+handlebars', 'HTML+Handlebars'),# ('html+lasso', 'HTML+Lasso'),# ('html+mako', 'HTML+Mako'),# ('html+myghty', 'HTML+Myghty'),# ('html+ng2', 'HTML + Angular2'),# ('html+php', 'HTML+PHP'),# ('html+smarty', 'HTML+Smarty'),# ('html+twig', 'HTML+Twig'),# ('html+velocity', 'HTML+Velocity'),# ('http', 'HTTP'),# ('hx', 'Haxe'),# ('hybris', 'Hybris'),# ('hylang', 'Hy'),# ('i6t', 'Inform 6 template'),# ('idl', 'IDL'),# ('idris', 'Idris'),# ('iex', 'Elixir iex session'),# ('igor', 'Igor'),# ('inform6', 'Inform 6'),# ('inform7', 'Inform 7'),("ini", "INI"),# ('io', 'Io'),# ('ioke', 'Ioke'),# ('ipython2', 'IPython'),# ('ipython3', 'IPython3'),("ipythonconsole", "IPython console session"),("irc", "IRC logs"),# ('isabelle', 'Isabelle'),# ('j', 'J'),# ('jags', 'JAGS'),# ('jasmin', 'Jasmin'),("java", "Java"),# ('javascript+mozpreproc', 'Javascript+mozpreproc'),# ('jcl', 'JCL'),# ('jlcon', 'Julia console'),("js", "JavaScript"),# ('js+cheetah', 'JavaScript+Cheetah'),# ('js+django', 'JavaScript+Django/Jinja'),# ('js+erb', 'JavaScript+Ruby'),# ('js+genshitext', 'JavaScript+Genshi Text'),# ('js+lasso', 'JavaScript+Lasso'),# ('js+mako', 'JavaScript+Mako'),# ('js+myghty', 'JavaScript+Myghty'),# ('js+php', 'JavaScript+PHP'),# ('js+smarty', 'JavaScript+Smarty'),# ('jsgf', 'JSGF'),("json", "JSON"),("jsx", "JSX/React"),# ('json-object', 'JSONBareObject'),# ('jsonld', 'JSON-LD'),# ('jsp', 'Java Server Page'),

(continues on next page)

1.4. Settings 13

Page 18: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

(continued from previous page)

# ('julia', 'Julia'),# ('juttle', 'Juttle'),# ('kal', 'Kal'),# ('kconfig', 'Kconfig'),# ('koka', 'Koka'),("kotlin", "Kotlin"),# ('lagda', 'Literate Agda'),# ('lasso', 'Lasso'),# ('lcry', 'Literate Cryptol'),# ('lean', 'Lean'),("less", "LessCSS"),# ('lhs', 'Literate Haskell'),# ('lidr', 'Literate Idris'),# ('lighty', 'Lighttpd configuration file'),# ('limbo', 'Limbo'),# ('liquid', 'liquid'),# ('live-script', 'LiveScript'),# ('llvm', 'LLVM'),# ('logos', 'Logos'),# ('logtalk', 'Logtalk'),# ('lsl', 'LSL'),("lua", "Lua"),("make", "Makefile"),# ('mako', 'Mako'),# ('maql', 'MAQL'),# ('mask', 'Mask'),# ('mason', 'Mason'),# ('mathematica', 'Mathematica'),("matlab", "Matlab"),# ('matlabsession', 'Matlab session'),# ('md', 'markdown'),# ('minid', 'MiniD'),# ('modelica', 'Modelica'),# ('modula2', 'Modula-2'),# ('monkey', 'Monkey'),# ('monte', 'Monte'),# ('moocode', 'MOOCode'),# ('moon', 'MoonScript'),# ('mozhashpreproc', 'mozhashpreproc'),# ('mozpercentpreproc', 'mozpercentpreproc'),# ('mql', 'MQL'),# ('mscgen', 'Mscgen'),# ('mupad', 'MuPAD'),# ('mxml', 'MXML'),# ('myghty', 'Myghty'),# ('mysql', 'MySQL'),# ('nasm', 'NASM'),# ('ncl', 'NCL'),# ('nemerle', 'Nemerle'),# ('nesc', 'nesC'),# ('newlisp', 'NewLisp'),# ('newspeak', 'Newspeak'),# ('ng2', 'Angular2'),("nginx", "Nginx configuration file"),# ('nim', 'Nimrod'),# ('nit', 'Nit'),# ('nixos', 'Nix'),

(continues on next page)

14 Chapter 1. Documentation

Page 19: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

(continued from previous page)

# ('nsis', 'NSIS'),("numpy", "NumPy"),# ('nusmv', 'NuSMV'),# ('objdump', 'objdump'),# ('objdump-nasm', 'objdump-nasm'),("objective-c", "Objective-C"),# ('objective-c++', 'Objective-C++'),# ('objective-j', 'Objective-J'),# ('ocaml', 'OCaml'),# ('octave', 'Octave'),# ('odin', 'ODIN'),# ('ooc', 'Ooc'),# ('opa', 'Opa'),# ('openedge', 'OpenEdge ABL'),# ('pacmanconf', 'PacmanConf'),# ('pan', 'Pan'),# ('parasail', 'ParaSail'),# ('pawn', 'Pawn'),("perl", "Perl"),# ('perl6', 'Perl6'),("php", "PHP"),# ('pig', 'Pig'),# ('pike', 'Pike'),# ('pkgconfig', 'PkgConfig'),# ('plpgsql', 'PL/pgSQL'),("postgresql", "PostgreSQL SQL dialect"),# ('postscript', 'PostScript'),# ('pot', 'Gettext Catalog'),# ('pov', 'POVRay'),# ('powershell', 'PowerShell'),# ('praat', 'Praat'),# ('prolog', 'Prolog'),# ('properties', 'Properties'),# ('protobuf', 'Protocol Buffer'),# ('ps1con', 'PowerShell Session'),# ('psql', 'PostgreSQL console (psql)'),# ('pug', 'Pug'),# ('puppet', 'Puppet'),# ('py3tb', 'Python 3.0 Traceback'),# ('pycon', 'Python console session'),# ('pypylog', 'PyPy Log'),# ('pytb', 'Python Traceback'),("python", "Python"),# ('python3', 'Python 3'),# ('qbasic', 'QBasic'),# ('qml', 'QML'),# ('qvto', 'QVTO'),# ('racket', 'Racket'),# ('ragel', 'Ragel'),# ('ragel-c', 'Ragel in C Host'),# ('ragel-cpp', 'Ragel in CPP Host'),# ('ragel-d', 'Ragel in D Host'),# ('ragel-em', 'Embedded Ragel'),# ('ragel-java', 'Ragel in Java Host'),# ('ragel-objc', 'Ragel in Objective C Host'),# ('ragel-ruby', 'Ragel in Ruby Host'),# ('raw', 'Raw token data'),

(continues on next page)

1.4. Settings 15

Page 20: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

(continued from previous page)

("rb", "Ruby"),# ('rbcon', 'Ruby irb session'),# ('rconsole', 'RConsole'),# ('rd', 'Rd'),# ('rebol', 'REBOL'),# ('red', 'Red'),# ('redcode', 'Redcode'),# ('registry', 'reg'),# ('resource', 'ResourceBundle'),# ('rexx', 'Rexx'),# ('rhtml', 'RHTML'),# ('rnc', 'Relax-NG Compact'),# ('roboconf-graph', 'Roboconf Graph'),# ('roboconf-instances', 'Roboconf Instances'),# ('robotframework', 'RobotFramework'),# ('rql', 'RQL'),# ('rsl', 'RSL'),("rst", "reStructuredText"),# ('rts', 'TrafficScript'),("rust", "Rust"),# ('sas', 'SAS'),("sass", "Sass"),# ('sc', 'SuperCollider'),# ('scala', 'Scala'),# ('scaml', 'Scaml'),# ('scheme', 'Scheme'),# ('scilab', 'Scilab'),("scss", "SCSS"),# ('shen', 'Shen'),# ('silver', 'Silver'),# ('slim', 'Slim'),# ('smali', 'Smali'),# ('smalltalk', 'Smalltalk'),# ('smarty', 'Smarty'),# ('sml', 'Standard ML'),# ('snobol', 'Snobol'),# ('snowball', 'Snowball'),("sol", "Solidity"),# ('sourceslist', 'Debian Sourcelist'),# ('sp', 'SourcePawn'),# ('sparql', 'SPARQL'),# ('spec', 'RPMSpec'),# ('splus', 'S'),("sql", "SQL"),# ('sqlite3', 'sqlite3con'),# ('squidconf', 'SquidConf'),# ('ssp', 'Scalate Server Page'),# ('stan', 'Stan'),# ('stata', 'Stata'),("swift", "Swift"),# ('swig', 'SWIG'),# ('systemverilog', 'systemverilog'),# ('tads3', 'TADS 3'),# ('tap', 'TAP'),# ('tasm', 'TASM'),# ('tcl', 'Tcl'),# ('tcsh', 'Tcsh'),

(continues on next page)

16 Chapter 1. Documentation

Page 21: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

(continued from previous page)

# ('tcshcon', 'Tcsh Session'),# ('tea', 'Tea'),# ('termcap', 'Termcap'),# ('terminfo', 'Terminfo'),# ('terraform', 'Terraform'),("tex", "TeX"),# ('text', 'Text only'),# ('thrift', 'Thrift'),# ('todotxt', 'Todotxt'),# ('trac-wiki', 'MoinMoin/Trac Wiki markup'),# ('treetop', 'Treetop'),# ('ts', 'TypeScript'),# ('tsql', 'Transact-SQL'),# ('turtle', 'Turtle'),# ('twig', 'Twig'),("typoscript", "TypoScript"),# ('typoscriptcssdata', 'TypoScriptCssData'),# ('typoscripthtmldata', 'TypoScriptHtmlData'),# ('urbiscript', 'UrbiScript'),# ('vala', 'Vala'),# ('vb.net', 'VB.net'),# ('vcl', 'VCL'),# ('vclsnippets', 'VCLSnippets'),# ('vctreestatus', 'VCTreeStatus'),# ('velocity', 'Velocity'),# ('verilog', 'verilog'),# ('vgl', 'VGL'),# ('vhdl', 'vhdl'),("vim", "VimL"),# ('wdiff', 'WDiff'),# ('whiley', 'Whiley'),# ('x10', 'X10'),("xml", "XML"),# ('xml+cheetah', 'XML+Cheetah'),# ('xml+django', 'XML+Django/Jinja'),# ('xml+erb', 'XML+Ruby'),# ('xml+evoque', 'XML+Evoque'),# ('xml+lasso', 'XML+Lasso'),# ('xml+mako', 'XML+Mako'),# ('xml+myghty', 'XML+Myghty'),# ('xml+php', 'XML+PHP'),# ('xml+smarty', 'XML+Smarty'),# ('xml+velocity', 'XML+Velocity'),# ('xorg.conf', 'Xorg'),# ('xquery', 'XQuery'),("xslt", "XSLT"),# ('xtend', 'Xtend'),# ('xul+mozpreproc', 'XUL+mozpreproc'),("yaml", "YAML"),# ('yaml+jinja', 'YAML+Jinja'),# ('zephir', 'Zephir')

]

# Whether to send out cache headers (Max-Age, Never-Cache, etc.).CACHE_HEADER = True

# Defines how long pages are cached by upstream Proxies (Max-Age Header).(continues on next page)

1.4. Settings 17

Page 22: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

(continued from previous page)

# This does not affect caching of snippets, their max-age limit is set# to the expire date.CACHE_TIMEOUT = 60 * 10

@staticmethoddef get_base_url(request=None):

"""String. The full qualified hostname and path to the dpaste instance.This is used to generate a link in the API response. If the "Sites"framework is installed, it uses the current Site domain. Otherwiseit falls back to 'https://dpaste.de'"""if apps.is_installed("django.contrib.sites"):

from django.contrib.sites.shortcuts import get_current_site

site = get_current_site(request)if site:

return f"https://{site.domain}"return "https://dpaste-base-url.example.org"

@propertydef extra_template_context(self):

"""Returns a dictionary with context variables which are passed toall Template Views."""return {

"dpaste_application_name": self.APPLICATION_NAME,"dpaste_extra_head_html": mark_safe(self.EXTRA_HEAD_HTML),"dpaste_extra_post_about": mark_safe(self.EXTRA_POST_ABOUT),"dpaste_extra_post_new": mark_safe(self.EXTRA_POST_NEW),"dpaste_extra_post_form": mark_safe(self.EXTRA_POST_FORM),

}

1.5 API

1.5.1 API endpoint

dpaste provides a simple API endpoint to create new snippets. All you need to do is a simple POST request to the APIendpoint, usually /api/:

POST /api/Create a new Snippet on this dpaste installation. It returns the full URL that snippet was created.

Example request:

$ curl -X POST -F "format=url" -F "content=ABC" https:/dpaste.de/api/

Host: dpaste.deUser-Agent: curl/7.54.0Accept: */*

Example response:

18 Chapter 1. Documentation

Page 23: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

{"lexer": "python","url": "https://dpaste.de/EBKU","content": "ABC"

}

Form Parameters

• content – (required) The UTF-8 encoded string you want to paste.

• lexer – (optional) The lexer string key used for highlighting. See the CODE_FORMATTERproperty in Settings for a full list of choices. Default: _code.

• format – (optional) The format of the API response. Choices are:

– default — Returns a full qualified URL wrapped in quotes. Example: "https://dpaste.de/xsWd"

– url — Returns the full qualified URL to the snippet, without surrounding quotes, butwith a line break. Example: https://dpaste.de/xsWd\n

– json — Returns a JSON object containing the URL, lexer and content of the the snippet.Example:

{"url": "https://dpaste.de/xsWd","lexer": "python","content": "The text body of the snippet."

}

• expires – (optional) A keyword to indicate the lifetime of a snippet in seconds. Thevalues are predefined by the server. Calling this with an invalid value returns a HTTP 400BadRequest together with a list of valid values. Default: 2592000. In the default configu-ration valid values are:

– onetime

– never

– 3600

– 604800

– 2592000

• filename – (optional) A filename which we use to determine a lexer, if lexer is not set.In case we can’t determine a file, the lexer will fallback to plain code (no highlighting).A given lexer will overwrite any filename! Example:

{"url": "https://dpaste.de/xsWd","lexer": "","filename": "python","content": "The text body of the snippet."

}

This will create a python highlighted snippet. However in this example:

{"url": "https://dpaste.de/xsWd",

(continues on next page)

1.5. API 19

Page 24: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

(continued from previous page)

"lexer": "php","filename": "python","content": "The text body of the snippet."

}

Since the lexer is set too, we will create a php highlighted snippet.

Status Codes

• 200 OK – No Error.

• 400 Bad Request – One of the above form options was invalid, the response will contain ameaningful error message.

Hint: If you have a standalone installation and your API returns https://dpaste-base-url.example.orgas the domain, you need to adjust the setting get_base_url property. See Settings.

1.5.2 Third party API integration

subdpaste a Sublime Editor plugin: https://github.com/bartTC/SubDpaste

Marmalade an Emacs plugin: http://marmalade-repo.org/packages/dpaste_de

atom-dpaste for the Atom editor: https://atom.io/packages/atom-dpaste

dpaste-magic an iPython extension: https://pypi.org/project/dpaste-magic/

You can also paste your file content to the API via curl, directly from the command line:

$ alias dpaste="curl -F 'format=url' -F 'content=<-' https://dpaste.org/api/"$ cat foo.txt | dpastehttps://dpaste.de/ke2pB

Note: If you wrote or know a third party dpaste plugin or extension, please open an Issue on Github and it’s addedhere.

1.6 Changelog

1.6.1 3.5 (2020-01-08)

• Mobile view improvements.

• Upgraded django-csp dependency to v3.6 that ships with Django 3.0 support.

1.6.2 3.4 (2019-12-08)

• Dropped support for Python 3.4.

• Dropped support for Python 3.5.

• Dropped support for Django 1.11.

20 Chapter 1. Documentation

Page 25: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

• Dropped support for Django 2.0.

• Dropped support for Django 2.1.

• Added support for Python 3.8.

• Added support for Django 3.0.

• Snippets which are expired are now deleted as soon as they are requested by a client. It’s not necessary topurge them minutely with the cleanup_snipppet managemenent command. It’s still encouraged to havethe management command setup, just run it daily, so snippets which expired but never got fetched by a clientare deleted properly.

• All pages have sane Expire or Max-Age header.

• Onetime snippets which were never viewed a second time are now deleted if they reach the default expire date.

• New AppConfig setting APPLICATION_NAME that can be used to replace the term “dpaste” throughout theUI.

• New AppConfig setting EXTRA_HEAD_HTML and similars that can be used to add custom HTML to eachtemplate, to easily override the stock UI of dpaste.

• New “Slim” view that displays the highlighted snippet without header, options etc, and can be iframed.

• Forced line-break for superlongwordsthatwouldexceedthecanvas.

• Local development is no longer centered around pipenv, instead it’s using docker-compose or the classicvirtualenv based setups.

• Error pages are now correctly translated.

• Testsuite and Tox uses pytest instead of a homebrewed testrunner.

1.6.3 3.3.1 (2019-08-04):

• Exclude the local settings file from the pypi release.

1.6.4 3.3 (2019-07-12)

• The compiled static files (CSS, JS) are now shipped with the Pypi package since its not possible to compile themafter installation with pip.

1.6.5 3.2 (2019-06-24)

• “Edit Snippet” panel is now hidden by default to remove visual noise.

• Linux/Unix browsers now use Ctrl+Enter as a shortcut to submit the form.

• Added a dedicated “Copy Snippet” button to copy the content to the clipboard.

• Added “View Raw” option to optionally render the ‘raw’ snippet content with a template rather served as plaintext. This was added to hinder abuse.

• Added “Json” to the list of lexers.

• Added ‘JSX/React” to the list of lexers.

1.6. Changelog 21

Page 26: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

1.6.6 3.1 (2019-05-16)

• Django 2.1 support and tests.

• Django 2.2 support and tests.

• General code cleanup by running the entire codebase through black.

• Right-to-left support for text snippets.

• dart-sass is now used for SASS compilation.

• Updated lexer list.

• “View Raw” feature can be disabled in app config to hinder abuse.

1.6.7 3.0 (2018-06-22)

Huge release. Full cleanup and update of the entire codebase. Details:

• Requires Python 3.4 and up.

• Dropped support for Django 1.8 to 1.10 due to it’s general end of support. The project will likely work well butit’s no longer specifically tested.

• All views are now class based and use the latest generic based views sugar.

• Django 1.11 based templates, forms, views, models, etc.

• Added pipenv support for local development.

• Added AppConfig support to set and maintain settings.

• Added “Rendered Text” lexer with support for rST and Markdown.

• Added Content Security Policy features, with django-csp (this is mainly required for the “rendered” text feature).

• Removed jQuery dependency, all Javascript is native.

• Removed Bootstrap dependency.

• Removed ‘Maximum History’ limit setting.

• Removed translations.

• Removed “Suspicious” middleware which was never been used, documented, and also not functional for a while.

• Fixed issues around leading whitespace in lines.

• Fixed CMD+Enter form submission shortcut in Firefox.

1.6.8 2.14 (no public release)

• Django 1.11 compatibility. But not Django 2.0 yet.

• Removed “Suspicious” middleware which was never been used, documented, and also not functional for a while.

22 Chapter 1. Documentation

Page 27: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

1.6.9 2.13 (2017-01-20)

• (Backwards incompatible) Removal of django-mptt and therefor the removal of a tree based snippet list, due toperformance reasons with large snippet counts. Snippets still have a ‘parent’ relation if it’s an answer of anothersnippet, however this is no longer a Nested Set. The UI is simplified too and the user can now only compare ananswer to it’s parent snippet. I believe this is the major use case anyway.

• (Backwards incompatible) Removal of the “Gist” button feature.

• Fixed broken 404 view handler in Django 1.9+.

• Python 3.6 and Django 1.10 compatibility and tests.

1.6.10 2.12 (2016-09-06)

• Fixed “Content Type” problem with Django 1.10.

• Development requirements now use a different version scheme to be compatible with older pip versions.

1.6.11 2.11 (2016-09-04)

• Django 1.10 Support

• R Lexer is enabled by default

• Minor fixes and improvements.

1.6.12 2.10 (2016-03-23)

• Dropped Django 1.4 and 1.7 support!

• Full Django 1.8 support

• Full Django 1.9 support

• C++ Lexer is enabled by default

• (Backwards incompatible) All API calls must pass the data within a POST request. It can’t mix POST and GETarguments anymore. This was weird behavior anyway and is likely no issue for any paste plugin out there.

1.6.13 2.9 (2015-08-12)

• Full Django 1.7 support

• Full Django 1.8 support

• New Django migrations, with fallback to South migrations if South is installed. If you want to switch fromSouth to native Django migrations, and have an existing databsae, fake the initial migrations: manage.py migrate–fake-initial

• Added full i18n support and several languages

• More settings can be overrridden, like the jQuery URL, site name and wether you want to enable Gthub Gist.

• Ships a middleware that blocks anonymous proxies and TOR nodes. Not enabled by default.

1.6. Changelog 23

Page 28: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

1.6.14 2.8 (2014-08-02)

• The API create view has a new argument ‘filename’ which is used to determine the lexer out of a given filename.

• Fixed a XSS bug where HTML tags were not properly escaped with the simple code lexer.

1.6.15 2.7 (2014-06-08)

• “never” as an expiration choice is enable by default! This creates snippets in the database which are neverpurged.

• The API create call now supports to set the exiration time.

• Some simple Bootstrap 3 support.

• Gist fixes on Python 3.

1.6.16 2.6 (2014-04-12)

• Fix for the rare case of duplicate slug (secret id) generation.

• A new ‘code’ lexer renders source code with no highlighting.

• Whitespace fixes with tab indention and word wrap mode.

• Installation docs.

1.6.17 2.5 (2014-01-21)

• IRC lexer is now in the default lexer list.

• One-Time snippet support. Snippets get automatically deleted after the another user looks at it.

• Toggle wordwrap for code snippets.

• General UI and readability improvements.

1.6.18 2.4 (2014-01-11)

• API accepts the format or lexer via GET too. You can call an API url like example.com/api/?format=json and have the body in POST only.

• Added an option to keep snippets forever.

• ABAP lexer is now in the default lexer list.

1.6.19 2.3 (2014-01-07)

• API Documentation.

• Full test coverage.

• Removed Twitter button from homepage.

• Slug generation is less predictable.

24 Chapter 1. Documentation

Page 29: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

1.6.20 2.2 (2013-12-18)

• Added documentation

• Added support for CSRF middleware.

• Windows users can submit the form using Ctrl+Enter.

• The raw view now sends the X-Content-Type-Options=nosniff header.

• Various constants can now be overridden by settings.

• Support for python setup.py test to run the tox suite.

1.6.21 2.1 (2013-12-14)

• Changes and fixes along the package management.

1.6.22 2.0 (2013-11-29)

• A huge cleanup and nearly total rewrite.

• dpaste now includes a Django project which is used on www.dpaste.de as well as hooks to get it integrated intoexisting projcts.

1.6. Changelog 25

Page 30: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

dpaste Documentation

26 Chapter 1. Documentation

Page 31: dpaste Documentation · -e DEBUG=True \-e SECRET_KEY=very-secret-key \-e PORT=12345 \ barttc/dpaste:latest 1.1.2Integration into an existing Django project Install the latest dpaste

HTTP Routing Table

/apiPOST /api/, 18

27