pax_global_header00006660000000000000000000000064136155341710014520gustar00rootroot0000000000000052 comment=7d69508d92f3298f9bfe89bf34c2a6461bf68b30 pastedeploy-2.1.0/000077500000000000000000000000001361553417100140515ustar00rootroot00000000000000pastedeploy-2.1.0/.github/000077500000000000000000000000001361553417100154115ustar00rootroot00000000000000pastedeploy-2.1.0/.github/ISSUE_TEMPLATE/000077500000000000000000000000001361553417100175745ustar00rootroot00000000000000pastedeploy-2.1.0/.github/ISSUE_TEMPLATE/bug_report.md000066400000000000000000000013601361553417100222660ustar00rootroot00000000000000--- name: Bug Report about: Create a report to help us improve --- ## Get Support To get help or technical support, see [Get Support](https://pylonsproject.org/community-support.html). ## Bug Report Please [search the issue tracker](https://github.com/Pylons/pastedeploy/issues) for similar issues before submitting a new issue. **Describe the bug** A clear and concise description of the bug. **To Reproduce** Steps to reproduce the behavior: 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' 4. See error **Expected behavior** A clear and concise description of what you expected to happen. **Screenshots** If applicable, add screenshots to help explain the issue. **Additional context** Add any other context about the issue here. pastedeploy-2.1.0/.github/ISSUE_TEMPLATE/documentation.md000066400000000000000000000013651361553417100227740ustar00rootroot00000000000000--- name: Documentation Suggestion about: Create an issue to improve our documentation --- ## Get Support To get help or technical support, see [Get Support](https://pylonsproject.org/community-support.html). ## Documentation Suggestion Please [search the issue tracker](https://github.com/Pylons/pastedeploy/issues) for similar issues before submitting a new issue. **Describe the issue** A clear and concise description of the issue. **Include references** 1. Go to the URL '...' 2. Click on '....' 3. Scroll down to '....' **Describe the improvement** A clear and concise description of your suggestion. **Screenshots** If applicable, add screenshots to help explain the issue. **Additional context** Add any other context about the issue here. pastedeploy-2.1.0/.github/ISSUE_TEMPLATE/feature_request.md000066400000000000000000000014731361553417100233260ustar00rootroot00000000000000--- name: Feature Request about: Suggest an idea for this project --- ## Get Support To get help or technical support, see [Get Support](https://pylonsproject.org/community-support.html). ## Feature Request Please [search the issue tracker](https://github.com/Pylons/pastedeploy/issues) for similar issues before submitting a new issue. **Is your feature request related to an issue? Please describe.** A clear and concise description of the issue. Example: "I'm always frustrated when [...]". **Describe the solution you'd like** A clear and concise description of what you want to happen. **Describe alternatives you've considered** A clear and concise description of any alternative solutions or features you've considered. **Additional context** Add any other context or screenshots about the feature request here. pastedeploy-2.1.0/.gitignore000066400000000000000000000001201361553417100160320ustar00rootroot00000000000000.coverage .tox *.pyc PasteDeploy.egg-info coverage.xml htmlcov .eggs build dist pastedeploy-2.1.0/.hgignore000066400000000000000000000001721361553417100156540ustar00rootroot00000000000000syntax: glob *.egg-info/ *.egg/ *.pyc *.class dist/ build/ docs/_build/ .tox .project .pydevproject .settings __pycache__ pastedeploy-2.1.0/.travis.yml000066400000000000000000000007751361553417100161730ustar00rootroot00000000000000sudo: false dist: xenial language: python install: - pip install tox script: - tox matrix: include: - python: 2.7 env: TOXENV=py27 - python: 3.4 env: TOXENV=py34 - python: 3.5 env: TOXENV=py35 - python: 3.6 env: TOXENV=py36 - python: 3.7 env: TOXENV=py37 - python: pypy env: TOXENV=pypy dist: trusty - python: pypy3 env: TOXENV=pypy3 dist: trusty pastedeploy-2.1.0/MANIFEST.in000066400000000000000000000002261361553417100156070ustar00rootroot00000000000000include docs/*.txt include license.txt graft tests graft paste/deploy/paster_templates global-exclude __pycache__ *.py[cod] global-exclude .DS_Store pastedeploy-2.1.0/README.rst000066400000000000000000000010761361553417100155440ustar00rootroot00000000000000This tool provides code to load WSGI applications and servers from URIs. These URIs can refer to Python eggs for INI-style configuration files. `Paste Script `_ provides commands to serve applications based on this configuration file. The latest version is available on `GitHub `_ (or download a wheel or tarball from `PyPI `_). For the latest changes see the `news file `_. pastedeploy-2.1.0/contributing.md000066400000000000000000000023011361553417100170760ustar00rootroot00000000000000# Contributing All projects under the Pylons Project, including this one, follow the guidelines established at [How to Contribute](https://pylonsproject.org/community-how-to-contribute.html), [Coding Style and Standards](https://pylonsproject.org/community-coding-style-standards.html), and [Pylons Project Documentation Style Guide](https://docs.pylonsproject.org/projects/pastedeploy/). You can contribute to this project in several ways. * [File an Issue on GitHub](https://github.com/Pylons/pastedeploy/issues) * Fork this project, create a new branch, commit your suggested change, and push to your fork on GitHub. When ready, submit a pull request for consideration. [GitHub Flow](https://guides.github.com/introduction/flow/index.html) describes the workflow process and why it's a good practice. * Join the [IRC channel #pyramid on irc.freenode.net](https://webchat.freenode.net/?channels=pyramid). ## Running Tests and Building Docs Run `tox` from within your checkout. This will run the tests across all supported systems and attempt to build the docs. To run the tests for Python 3.7 only: $ tox -e py37 To build the docs: $ tox -e docs See the `tox.ini` file for details. pastedeploy-2.1.0/docs/000077500000000000000000000000001361553417100150015ustar00rootroot00000000000000pastedeploy-2.1.0/docs/.gitignore000066400000000000000000000000071361553417100167660ustar00rootroot00000000000000_build pastedeploy-2.1.0/docs/Makefile000066400000000000000000000074311361553417100164460ustar00rootroot00000000000000# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = -W SPHINXBUILD = sphinx-build PAPER = BUILDDIR = _build # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html text web pickle htmlhelp latex latexpdf xelatexpdf changes linkcheck epub doctest help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " text to make text files" @echo " pickle to make pickle files (usable by e.g. sphinx-web)" @echo " htmlhelp to make HTML files and a HTML help project" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " xelatexpdf to make LaTeX files and run them through xelatex" @echo " changes to make an overview over all changed/added/deprecated items" @echo " linkcheck to check all external links for integrity" @echo " epub to make an epub" @echo " doctest to run all doctests embedded in the documentation (if enabled)" clean: -rm -rf $(BUILDDIR)/* xelatexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through xelatex..." $(MAKE) PDFLATEX=xelatex -C $(BUILDDIR)/latex all-pdf @echo "xelatex finished; the PDF files are in $(BUILDDIR)/latex." html: mkdir -p $(BUILDDIR)/html $(BUILDDIR)/doctrees $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." text: mkdir -p $(BUILDDIR)/text $(BUILDDIR)/doctrees $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/text." pickle: mkdir -p $(BUILDDIR)/pickle $(BUILDDIR)/doctrees $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files or run" @echo " sphinx-web $(BUILDDIR)/pickle" @echo "to start the sphinx-web server." web: pickle htmlhelp: mkdir -p $(BUILDDIR)/htmlhelp $(BUILDDIR)/doctrees $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." latex: mkdir -p $(BUILDDIR)/latex $(BUILDDIR)/doctrees $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex cp _static/*.png $(BUILDDIR)/latex ./convert_images.sh cp _static/latex-warning.png $(BUILDDIR)/latex cp _static/latex-note.png $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make xelatexpdf' to build a PDF file from them." latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." $(MAKE) -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF file is in $(BUILDDIR)/latex." changes: mkdir -p $(BUILDDIR)/changes $(BUILDDIR)/doctrees $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." linkcheck: mkdir -p $(BUILDDIR)/linkcheck $(BUILDDIR)/doctrees $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." pastedeploy-2.1.0/docs/conf.py000066400000000000000000000111211361553417100162740ustar00rootroot00000000000000# -*- coding: utf-8 -*- # # Paste documentation build configuration file, created by # sphinx-quickstart on Tue Apr 22 22:08:49 2008. # # This file is execfile()d with the current directory set to its containing dir. # # The contents of this file are pickled, so don't put values in the namespace # that aren't pickleable (module imports are okay, they're removed automatically). # # All configuration values have a default value; values that are commented out # serve to show the default value. import datetime import pkg_resources import pylons_sphinx_themes # If your extensions are in another directory, add it here. #sys.path.append('some/directory') # General configuration # --------------------- # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.intersphinx', ] # Looks for objects in external projects intersphinx_mapping = { 'python': ('https://docs.python.org/3/', None), } # Add any paths that contain templates here, relative to this directory. # templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' # The master toctree document. master_doc = 'index' # General substitutions. thisyear = datetime.datetime.now().year project = 'Paste Deploy' copyright = '2011-%s, Ian Bicking and contributors' % thisyear # The default replacements for |version| and |release|, also used in various # other places throughout the built documents. # # The short X.Y version. version = pkg_resources.get_distribution('pastedeploy').version # The full version, including alpha/beta/rc tags. release = version # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. today_fmt = '%B %d, %Y' # List of documents that shouldn't be included in the build. #unused_docs = ['include/contact.txt', 'include/reference_header.txt'] # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # Options for HTML output # ----------------------- html_theme = 'pylons' html_theme_path = pylons_sphinx_themes.get_html_themes_path() html_theme_options = dict( canonical_url='https://docs.pylonsproject.org/projects/pastedeploy/en/latest/' ) # The style sheet to use for HTML and HTML Help pages. A file of that name # must exist either in Sphinx' static/ path, or in one of the custom paths # given in html_static_path. # html_style = 'default.css' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". # html_static_path = ['_static'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. html_last_updated_fmt = '%b %d, %Y' # Do not use smart quotes. smartquotes = False # Content template for the index page. #html_index = '' # Custom sidebar templates, maps document names to template names. # Control display of sidebars html_sidebars = { '**': [ 'localtoc.html', 'ethicalads.html', 'relations.html', 'sourcelink.html', 'searchbox.html', ] } # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_use_modindex = True # If true, the reST sources are included in the HTML build as _sources/. #html_copy_source = True # Output file base name for HTML help builder. htmlhelp_basename = 'PasteDeploydoc' # Options for LaTeX output # ------------------------ # The paper size ('letter' or 'a4'). #latex_paper_size = 'letter' # The font size ('10pt', '11pt' or '12pt'). #latex_font_size = '10pt' # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, document class [howto/manual]). #latex_documents = [] # Additional stuff for the LaTeX preamble. #latex_preamble = '' # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_use_modindex = True pastedeploy-2.1.0/docs/index.rst000066400000000000000000000542371361553417100166550ustar00rootroot00000000000000Paste Deployment ================ :author: Ian Bicking .. contents:: Documents: .. toctree:: :maxdepth: 1 news modules/loadwsgi modules/config modules/converters .. comment: The names used in sections should be more concrete, and it should be clearer that they are just arbitrary names. Introduction ------------ Paste Deployment is a system for finding and configuring WSGI applications and servers. For WSGI application consumers it provides a single, simple function (``loadapp``) for loading a WSGI application from a configuration file or a Python Egg. For WSGI application providers it only asks for a single, simple entry point to your application, so that application users don't need to be exposed to the implementation details of your application. The result is something a system administrator can install and manage without knowing any Python, or the details of the WSGI application or its container. Paste Deployment currently does not require other parts of `Paste `_, and is distributed as a separate package. To see updates that have been made to Paste Deploy see the :doc:`news file `. Paste Deploy is released under the `MIT license `_. Status ------ Paste Deploy has passed version 1.0. Paste Deploy is an actively maintained project. As of 1.0, we'll make a strong effort to maintain backward compatibility (this actually started happening long before 1.0, but now it is explicit). This will include deprecation warnings when necessary. Major changes will take place under new functions or with new entry points. Note that the most key aspect of Paste Deploy is the entry points it defines (such as ``paste.app_factory``). Paste Deploy is not the only consumer of these entry points, and many extensions can best take place by utilizing the entry points instead of using Paste Deploy directly. The entry points will not change; if changes are necessary, new entry points will be defined. Installation ------------ First make sure you have either `setuptools `_ or its modern replacement `distribute `_ installed. For Python 3.x you need distribute as setuptools does not work on it. Then you can install Paste Deployment using `pip `_ by running: .. code-block:: bash pip install PasteDeploy If you want to track development, do: .. code-block:: bash git clone https://github.com/Pylons/pastedeploy cd pastedeploy pip install -e . This will install the package locally, and will load the files in the checkout. You can also simply install ``PasteDeploy==dev``. For downloads and other information see the `PyPI PasteDeploy page `_. A complementary package is `Paste Script `_. To install that, use ``pip install PasteScript`` (or ``pip install PasteScript==dev``). From the User Perspective ------------------------- In the following sections, the Python API for using Paste Deploy is given. This isn't what users will be using (but it is useful for Python developers and useful for setting up tests fixtures). The primary interaction with Paste Deploy is through its configuration files. The primary thing you want to do with a configuration file is serve it. To learn about serving configuration files, see `the ``paster serve`` command `_. The Config File ~~~~~~~~~~~~~~~ A config file has different sections. The only sections Paste Deploy cares about have prefixes, like ``app:main`` or ``filter:errors`` -- the part after the ``:`` is the "name" of the section, and the part before gives the "type". Other sections are ignored. The format is a simple `INI format `_: ``name = value``. You can extend the value by indenting subsequent lines. ``#`` is a comment. Typically you have one or two sections, named "main": an application section (``[app:main]``) and a server section (``[server:main]``). ``[composite:...]`` signifies something that dispatches to multiple applications (example below). Here's a typical configuration file that also shows off mounting multiple applications: .. code-block:: ini [composite:main] use = egg:Paste#urlmap / = home /blog = blog /wiki = wiki /cms = config:cms.ini [app:home] use = egg:Paste#static document_root = %(here)s/htdocs [filter-app:blog] use = egg:Authentication#auth next = blogapp roles = admin htpasswd = /home/me/users.htpasswd [app:blogapp] use = egg:BlogApp database = sqlite:/home/me/blog.db [app:wiki] use = call:mywiki.main:application database = sqlite:/home/me/wiki.db I'll explain each section in detail now: .. code-block:: ini [composite:main] use = egg:Paste#urlmap / = home /blog = blog /cms = config:cms.ini That this is a ``composite`` section means it dispatches the request to other applications. ``use = egg:Paste#urlmap`` means to use the composite application named ``urlmap`` from the ``Paste`` package. ``urlmap`` is a particularly common composite application -- it uses a path prefix to map your request to another application. These are the applications like "home", "blog", "wiki" and "config:cms.ini". The last one just refers to another file ``cms.ini`` in the same directory. Next up: .. code-block:: ini [app:home] use = egg:Paste#static document_root = %(here)s/htdocs ``egg:Paste#static`` is another simple application, in this case it just serves up non-dynamic files. It takes one bit of configuration: ``document_root``. You can use variable substitution, which will pull variables from the section ``[DEFAULT]`` (case sensitive!) with markers like ``%(var_name)s``. The special variable ``%(here)s`` is the directory containing the configuration file; you should use that in lieu of relative filenames (which depend on the current directory, which can change depending how the server is run). Then: .. code-block:: ini [filter-app:blog] use = egg:Authentication#auth next = blogapp roles = admin htpasswd = /home/me/users.htpasswd [app:blogapp] use = egg:BlogApp database = sqlite:/home/me/blog.db The ``[filter-app:blog]`` section means that you want an application with a filter applied. The application being filtered is indicated with ``next`` (which refers to the next section). The ``egg:Authentication#auth`` filter doesn't actually exist, but one could imagine it logs people in and checks permissions. That last section is just a reference to an application that you probably installed with ``pip install BlogApp``, and one bit of configuration you passed to it (``database``). Lastly: .. code-block:: ini [app:wiki] use = call:mywiki.main:application database = sqlite:/home/me/wiki.db This section is similar to the previous one, with one important difference. Instead of an entry point in an egg, it refers directly to the ``application`` variable in the ``mywiki.main`` module. The reference consist of two parts, separated by a colon. The left part is the full name of the module and the right part is the path to the variable, as a Python expression relative to the containing module. So, that's most of the features you'll use. Basic Usage ----------- The basic way you'll use Paste Deployment is to load `WSGI `_ applications. Many Python frameworks now support WSGI, so applications written for these frameworks should be usable. The primary function is ``paste.deploy.loadapp``. This loads an application given a URI. You can use it like: .. code-block:: ini from paste.deploy import loadapp wsgi_app = loadapp('config:/path/to/config.ini') There's two URI formats currently supported: ``config:`` and ``egg:``. ``config:`` URIs ---------------- URIs that being with ``config:`` refer to configuration files. These filenames can be relative if you pass the ``relative_to`` keyword argument to ``loadapp()``. .. note:: Filenames are never considered relative to the current working directory, as that is an unpredictable location. Generally when a URI has a context it will be seen as relative to that context; for example, if you have a ``config:`` URI inside another configuration file, the path is considered relative to the directory that contains that configuration file. Config Format ~~~~~~~~~~~~~ Configuration files are in the INI format. This is a simple format that looks like:: [section_name] key = value another key = a long value that extends over multiple lines All values are strings (no quoting is necessary). The keys and section names are case-sensitive, and may contain punctuation and spaces (though both keys and values are stripped of leading and trailing whitespace). Lines can be continued with leading whitespace. Lines beginning with ``#`` (preferred) or ``;`` are considered comments. Applications ~~~~~~~~~~~~ You can define multiple applications in a single file; each application goes in its own section. Even if you have just one application, you must put it in a section. Each section name defining an application should be prefixed with ``app:``. The "main" section (when just defining one application) would go in ``[app:main]`` or just ``[app]``. There's two ways to indicate the Python code for the application. The first is to refer to another URI or name: .. code-block:: ini [app:myapp] use = config:another_config_file.ini#app_name # or any URI: [app:myotherapp] use = egg:MyApp # or a callable from a module: [app:mythirdapp] use = call:my.project:myapplication # or even another section: [app:mylastapp] use = myotherapp It would seem at first that this was pointless; just a way to point to another location. However, in addition to loading the application from that location, you can also add or change the configuration. The other way to define an application is to point exactly to some Python code: .. code-block:: ini [app:myapp] paste.app_factory = myapp.modulename:app_factory You must give an explicit *protocol* (in this case ``paste.app_factory``), and the value is something to import. In this case the module ``myapp.modulename`` is loaded, and the ``app_factory`` object retrieved from it. See `Defining Factories`_ for more about the protocols. Configuration ~~~~~~~~~~~~~ Configuration is done through keys besides ``use`` (or the protocol names). Any other keys found in the section will be passed as keyword arguments to the factory. This might look like: .. code-block:: ini [app:blog] use = egg:MyBlog database = mysql://localhost/blogdb blogname = This Is My Blog! You can override these in other sections, like: .. code-block:: ini [app:otherblog] use = blog blogname = The other face of my blog This way some settings could be defined in a generic configuration file (if you have ``use = config:other_config_file``) or you can publish multiple (more specialized) applications just by adding a section. Global Configuration ~~~~~~~~~~~~~~~~~~~~ Often many applications share the same configuration. While you can do that a bit by using other config sections and overriding values, often you want that done for a bunch of disparate configuration values. And typically applications can't take "extra" configuration parameters; with global configuration you do something equivalent to "if this application wants to know the admin email, this is it". Applications are passed the global configuration separately, so they must specifically pull values out of it; typically the global configuration serves as the basis for defaults when no local configuration is passed in. Global configuration to apply to every application defined in a file should go in a special section named ``[DEFAULT]``. You can override global configuration locally like: .. code-block:: ini [DEFAULT] admin_email = webmaster@example.com [app:main] use = ... set admin_email = bob@example.com That is, by using ``set`` in front of the key. Composite Applications ~~~~~~~~~~~~~~~~~~~~~~ "Composite" applications are things that act like applications, but are made up of other applications. One example would be a URL mapper, where you mount applications at different URL paths. This might look like: .. code-block:: ini [composite:main] use = egg:Paste#urlmap / = mainapp /files = staticapp [app:mainapp] use = egg:MyApp [app:staticapp] use = egg:Paste#static document_root = /path/to/docroot The composite application "main" is just like any other application from the outside (you load it with ``loadapp`` for instance), but it has access to other applications defined in the configuration file. Other Objects ~~~~~~~~~~~~~ In addition to sections with ``app:``, you can define filters and servers in a configuration file, with ``server:`` and ``filter:`` prefixes. You load these with ``loadserver`` and ``loadfilter``. The configuration works just the same; you just get back different kinds of objects. Filter Composition ~~~~~~~~~~~~~~~~~~ There are several ways to apply filters to applications. It mostly depends on how many filters, and in what order you want to apply them. The first way is to use the ``filter-with`` setting, like: .. code-block:: ini [app:main] use = egg:MyEgg filter-with = printdebug [filter:printdebug] use = egg:Paste#printdebug # and you could have another filter-with here, and so on... Also, two special section types exist to apply filters to your applications: ``[filter-app:...]`` and ``[pipeline:...]``. Both of these sections define applications, and so can be used wherever an application is needed. ``filter-app`` defines a filter (just like you would in a ``[filter:...]`` section), and then a special key ``next`` which points to the application to apply the filter to. ``pipeline:`` is used when you need apply a number of filters. It takes *one* configuration key ``pipeline`` (plus any global configuration overrides you want). ``pipeline`` is a list of filters ended by an application, like: .. code-block:: ini [pipeline:main] pipeline = filter1 egg:FilterEgg#filter2 filter3 app [filter:filter1] # ... Getting Configuration ~~~~~~~~~~~~~~~~~~~~~ If you want to get the configuration without creating the application, you can use the ``appconfig(uri)`` function, which is just like the ``loadapp()`` function except it returns the configuration that would be used, as a dictionary. Both global and local configuration is combined into a single dictionary, but you can look at just one or the other with the attributes ``.local_conf`` and ``.global_conf``. ``egg:`` URIs ------------- `Python Eggs `_ are a distribution and installation format produced by `setuptools `_ and `distribute `_ that adds metadata to a normal Python package (among other things). You don't need to understand a whole lot about Eggs to use them. If you have a :mod:`` ``setup.py`` script, just change: .. code-block:: python from distutils.core import setup to: .. code-block:: python from setuptools import setup Now when you install the package it will be installed as an egg. The first important part about an Egg is that it has a *specification*. This is formed from the name of your distribution (the ``name`` keyword argument to ``setup()``), and you can specify a specific version. So you can have an egg named ``MyApp``, or ``MyApp==0.1`` to specify a specific version. The second is *entry points*. These are references to Python objects in your packages that are named and have a specific protocol. "Protocol" here is just a way of saying that we will call them with certain arguments, and expect a specific return value. We'll talk more about the protocols later_. .. _later: `Defining Factories`_ The important part here is how we define entry points. You'll add an argument to ``setup()`` like: .. code-block:: python setup( name='MyApp', # ... entry_points={ 'paste.app_factory': [ 'main=myapp.mymodule:app_factory', 'ob2=myapp.mymodule:ob_factory'], }, ) This defines two applications named ``main`` and ``ob2``. You can then refer to these by ``egg:MyApp#main`` (or just ``egg:MyApp``, since ``main`` is the default) and ``egg:MyApp#ob2``. The values are instructions for importing the objects. ``main`` is located in the ``myapp.mymodule`` module, in an object named ``app_factory``. There's no way to add configuration to objects imported as Eggs. Defining Factories ------------------ This lets you point to factories (that obey the specific protocols we mentioned). But that's not much use unless you can create factories for your applications. There's a few protocols: ``paste.app_factory``, ``paste.composite_factory``, ``paste.filter_factory``, and lastly ``paste.server_factory``. Each of these expects a callable (like a function, method, or class). ``paste.app_factory`` ~~~~~~~~~~~~~~~~~~~~~~ The application is the most common. You define one like: .. code-block:: python def app_factory(global_config, **local_conf): return wsgi_app The ``global_config`` is a dictionary, and local configuration is passed as keyword arguments. The function returns a WSGI application. ``paste.composite_factory`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Composites are just slightly more complex: .. code-block:: python def composite_factory(loader, global_config, **local_conf): return wsgi_app The ``loader`` argument is an object that has a couple interesting methods. ``get_app(name_or_uri, global_conf=None)`` return a WSGI application with the given name. ``get_filter`` and ``get_server`` work the same way. A more interesting example might be a composite factory that does something. For instance, consider a "pipeline" application: .. code-block:: python def pipeline_factory(loader, global_config, pipeline): # space-separated list of filter and app names: pipeline = pipeline.split() filters = [loader.get_filter(n) for n in pipeline[:-1]] app = loader.get_app(pipeline[-1]) filters.reverse() # apply in reverse order! for filter in filters: app = filter(app) return app Then we use it like: .. code-block:: ini [composite:main] use = pipeline = egg:Paste#printdebug session myapp [filter:session] use = egg:Paste#session store = memory [app:myapp] use = egg:MyApp ``paste.filter_factory`` ~~~~~~~~~~~~~~~~~~~~~~~~~ Filter factories are just like app factories (same signature), except they return filters. Filters are callables that take a WSGI application as the only argument, and return a "filtered" version of that application. Here's an example of a filter that checks that the ``REMOTE_USER`` CGI variable is set, creating a really simple authentication filter: .. code-block:: python def auth_filter_factory(global_conf, req_usernames): # space-separated list of usernames: req_usernames = req_usernames.split() def filter(app): return AuthFilter(app, req_usernames) return filter class AuthFilter(object): def __init__(self, app, req_usernames): self.app = app self.req_usernames = req_usernames def __call__(self, environ, start_response): if environ.get('REMOTE_USER') in self.req_usernames: return self.app(environ, start_response) start_response( '403 Forbidden', [('Content-type', 'text/html')]) return ['You are forbidden to view this resource'] ``paste.filter_app_factory`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This is very similar to ``paste.filter_factory``, except that it also takes a ``wsgi_app`` argument, and returns a WSGI application. So if you changed the above example to: .. code-block:: python class AuthFilter(object): def __init__(self, app, global_conf, req_usernames): # ... Then ``AuthFilter`` would serve as a filter_app_factory (``req_usernames`` is a required local configuration key in this case). ``paste.server_factory`` ~~~~~~~~~~~~~~~~~~~~~~~~~ This takes the same signature as applications and filters, but returns a server. A server is a callable that takes a single argument, a WSGI application. It then serves the application. An example might look like: .. code-block:: python def server_factory(global_conf, host, port): port = int(port) def serve(app): s = Server(app, host=host, port=port) s.serve_forever() return serve The implementation of ``Server`` is left to the user. ``paste.server_runner`` ~~~~~~~~~~~~~~~~~~~~~~~~ Like ``paste.server_factory``, except ``wsgi_app`` is passed as the first argument, and the server should run immediately. Outstanding Issues ------------------ * Should there be a "default" protocol for each type of object? Since there's currently only one protocol, it seems like it makes sense (in the future there could be multiple). Except that ``paste.app_factory`` and ``paste.composite_factory`` overlap considerably. * ConfigParser's INI parsing is kind of annoying. I'd like it both more constrained and less constrained. Some parts are sloppy (like the way it interprets ``[DEFAULT]``). * ``config:`` URLs should be potentially relative to other locations, e.g., ``config:$docroot/...``. Maybe using variables from ``global_conf``? * Should other variables have access to ``global_conf``? * Should objects be Python-syntax, instead of always strings? Lots of code isn't usable with Python strings without a thin wrapper to translate objects into their proper types. * Some short-form for a filter/app, where the filter refers to the "next app". Maybe like: .. code-block:: ini [app-filter:app_name] use = egg:... next = next_app [app:next_app] # ... pastedeploy-2.1.0/docs/modules/000077500000000000000000000000001361553417100164515ustar00rootroot00000000000000pastedeploy-2.1.0/docs/modules/config.rst000066400000000000000000000005631361553417100204540ustar00rootroot00000000000000:mod:`paste.deploy.config` -- Configuration and Environment middleware ====================================================================== .. automodule:: paste.deploy.config Module Contents --------------- .. autoclass:: DispatchingConfig .. autoclass:: ConfigMiddleware .. autoclass:: PrefixMiddleware .. comment: FIXME: do something about CONFIG (manual docs?) pastedeploy-2.1.0/docs/modules/converters.rst000066400000000000000000000004611361553417100213760ustar00rootroot00000000000000:mod:`paste.deploy.converters` -- Conversion helpers for String Configuration ============================================================================= .. automodule:: paste.deploy.converters Module Contents --------------- .. autofunction:: asbool .. autofunction:: asint .. autofunction:: aslist pastedeploy-2.1.0/docs/modules/loadwsgi.rst000066400000000000000000000005141361553417100210140ustar00rootroot00000000000000:mod:`paste.deploy.loadwsgi` -- Load WSGI applications from config files ======================================================================== .. automodule:: paste.deploy.loadwsgi Module Contents --------------- .. autofunction:: loadapp .. autofunction:: loadserver .. autofunction:: loadfilter .. autofunction:: appconfig pastedeploy-2.1.0/docs/news.rst000066400000000000000000000116251361553417100165140ustar00rootroot00000000000000Paste Deployment News ===================== 2.1.0 ----- * pytest-runner removed, use tox to run tests. 2.0.0 ----- * Python 3 deprecation warning cleanups * Moved code to `GitHub `_ under the Pylons Project. * Moved documentation under the Pylons Project, hosted by Read the Docs at https://docs.pylonsproject.org/projects/pastedeploy/en/latest/ 1.5.2 ----- * Fixed Python 3 issue in paste.deploy.util.fix_type_error() 1.5.1 ----- * Fixed use of the wrong variable when determining the context protocol * Fixed invalid import of paste.deploy.Config to paste.deploy.config.Config * Fixed multi proxy IPs bug in X-Forwarded-For header in PrefixMiddleware * Fixed TypeError when trying to raise LookupError on Python 3 * Fixed exception reraise on Python 3 Thanks to Alexandre Conrad, Atsushi Odagiri, Pior Bastida and Tres Seaver for their contributions. 1.5.0 ----- * Project is now maintained by Alex Grönholm * Was printing extraneous data when calling setup.py * Fixed missing paster template files (fixes "paster create -t paste.deploy") * Excluded tests from release distributions * Added support for the "call:" protocol for loading apps directly as functions (contributed by Jason Stitt) * Added Python 3.x support * Dropped Python 2.4 support * Removed the ``paste.deploy.epdesc`` and ``paste.deploy.interfaces`` modules -- contact the maintainer if you actually needed them 1.3.4 ----- * Fix loadconfig path handling on Jython on Windows. 1.3.3 ----- * In :class:`paste.deploy.config.PrefixMiddleware` the headers ``X-Forwarded-Scheme`` and ``X-Forwarded-Proto`` are now translated to the key ``environ['wsgi.url_scheme']``. Also ``X-Forwarded-For`` is translated to ``environ['REMOTE_ADDR']`` * Also in PrefixMiddleware, if X-Forwarded-Host has multiple (comma-separated) values, use only the first value. 1.3.2 ----- * Added ``paste.deploy.converters.asint()``. * fixed use sections overwriting the config's __file__ value with the use'd filename. * ``paste.deploy.loadwsgi`` now supports variable expansion in the DEFAULT section of config files (unlike plain ConfigParser). 1.3.1 ----- * Fix ``appconfig`` config loading when using a config file with ``filter-with`` in it (previously you'd get TypeError: iteration over non-sequence) 1.3 --- * Added ``scheme`` option to ``PrefixMiddleware``, so you can force a scheme (E.g., when proxying an HTTPS connection over HTTP). * Pop proper values into ``environ['paste.config']`` in ``ConfigMiddleware``. 1.1 --- * Any ``global_conf`` extra keys you pass to ``loadapp`` (or the other loaders) will show up as though they were in ``[DEFAULT]``, so they can be used in variable interpolation. Note: this won't overwrite any existing values in ``[DEFAULT]``. * Added ``force_port`` option to ``paste.deploy.config.PrefixMiddleware``. Also the ``prefix`` argument is stripped of any trailing ``/``, which can't be valid in that position. 1.0 --- * Added some documentation for the different kinds of entry points Paste Deploy uses. * Added a feature to ``PrefixMiddleware`` that translates the ``X-Forwarded-Server`` header to ``Host``. 0.9.6 ----- * Added ``PrefixMiddleware`` which compensates for cases where the wsgi app is behind a proxy of some sort that isn't moving the prefix into the SCRIPT_NAME in advance. * Changed _loadconfig() so that it works with Windows absolute paths. * Make the error messages prettier when you call a function and fail to give an argument, like a required function argument. 0.5 --- * Made the ``paste_deploy`` template (used with ``paster create --template=paste_deploy``) more useful, with an example application and entry point. 0.4 --- * Allow filters to have ``filter-with`` values, just like applications. * Renamed ``composit`` to ``composite`` (old names still work, but aren't documented). * Added ``appconfig()`` to load along with ``loadapp()``, but return the configuration without invoking the application. 0.3 --- * Allow variable setting like:: get local_var = global_var_name To bring in global variables to the local scope. * Allow interpolation in files, like ``%(here)s``. Anything in the ``[DEFAULTS]`` section will be available to substitute into a value, as will variables in the same section. Also, the special value ``here`` will be the directory the configuration file is located in. 0.2 --- Released 26 August 2004 * Added a ``filter-with`` setting to applications. * Removed the ``1`` from all the protocol names (e.g., ``paste.app_factory1`` is not ``paste.app_factory``). * Added ``filter-app:`` and ``pipeline:`` sections. * Added ``paste.filter_app_factory1`` and ``paste.server_runner1`` protocols. * Added ``paste.deploy.converters`` module for handling the string values that are common with this system. 0.1 --- Released 22 August 2004 Initial version released. It's all new. pastedeploy-2.1.0/license.txt000066400000000000000000000020651361553417100162370ustar00rootroot00000000000000Copyright (c) 2006-2007 Ian Bicking and Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pastedeploy-2.1.0/paste/000077500000000000000000000000001361553417100151655ustar00rootroot00000000000000pastedeploy-2.1.0/paste/__init__.py000066400000000000000000000010511361553417100172730ustar00rootroot00000000000000# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php try: import pkg_resources pkg_resources.declare_namespace(__name__) except ImportError: # don't prevent use of paste if pkg_resources isn't installed from pkgutil import extend_path __path__ = extend_path(__path__, __name__) try: import modulefinder except ImportError: pass else: for p in __path__: modulefinder.AddPackagePath(__name__, p) pastedeploy-2.1.0/paste/deploy/000077500000000000000000000000001361553417100164615ustar00rootroot00000000000000pastedeploy-2.1.0/paste/deploy/__init__.py000066400000000000000000000003151361553417100205710ustar00rootroot00000000000000# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php from paste.deploy.loadwsgi import * pastedeploy-2.1.0/paste/deploy/compat.py000066400000000000000000000017011361553417100203150ustar00rootroot00000000000000# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php """Python 2<->3 compatibility module""" import sys def print_(template, *args, **kwargs): template = str(template) if args: template = template % args elif kwargs: template = template % kwargs sys.stdout.writelines(template) if sys.version_info < (3, 0): basestring = basestring from ConfigParser import ConfigParser from urllib import unquote iteritems = lambda d: d.iteritems() dictkeys = lambda d: d.keys() def reraise(t, e, tb): exec('raise t, e, tb', dict(t=t, e=e, tb=tb)) else: basestring = str from configparser import ConfigParser from urllib.parse import unquote iteritems = lambda d: d.items() dictkeys = lambda d: list(d.keys()) def reraise(t, e, tb): raise e.with_traceback(tb) pastedeploy-2.1.0/paste/deploy/config.py000066400000000000000000000257551361553417100203160ustar00rootroot00000000000000# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php """Paste Configuration Middleware and Objects""" import threading import re # Loaded lazily wsgilib = None local = None __all__ = ['DispatchingConfig', 'CONFIG', 'ConfigMiddleware', 'PrefixMiddleware'] def local_dict(): global config_local, local try: return config_local.wsgi_dict except NameError: config_local = threading.local() config_local.wsgi_dict = result = {} return result except AttributeError: config_local.wsgi_dict = result = {} return result class DispatchingConfig(object): """ This is a configuration object that can be used globally, imported, have references held onto. The configuration may differ by thread (or may not). Specific configurations are registered (and deregistered) either for the process or for threads. """ # @@: What should happen when someone tries to add this # configuration to itself? Probably the conf should become # resolved, and get rid of this delegation wrapper _constructor_lock = threading.Lock() def __init__(self): self._constructor_lock.acquire() try: self.dispatching_id = 0 while 1: self._local_key = 'paste.processconfig_%i' % self.dispatching_id if not self._local_key in local_dict(): break self.dispatching_id += 1 finally: self._constructor_lock.release() self._process_configs = [] def push_thread_config(self, conf): """ Make ``conf`` the active configuration for this thread. Thread-local configuration always overrides process-wide configuration. This should be used like:: conf = make_conf() dispatching_config.push_thread_config(conf) try: ... do stuff ... finally: dispatching_config.pop_thread_config(conf) """ local_dict().setdefault(self._local_key, []).append(conf) def pop_thread_config(self, conf=None): """ Remove a thread-local configuration. If ``conf`` is given, it is checked against the popped configuration and an error is emitted if they don't match. """ self._pop_from(local_dict()[self._local_key], conf) def _pop_from(self, lst, conf): popped = lst.pop() if conf is not None and popped is not conf: raise AssertionError( "The config popped (%s) is not the same as the config " "expected (%s)" % (popped, conf)) def push_process_config(self, conf): """ Like push_thread_config, but applies the configuration to the entire process. """ self._process_configs.append(conf) def pop_process_config(self, conf=None): self._pop_from(self._process_configs, conf) def __getattr__(self, attr): conf = self.current_conf() if conf is None: raise AttributeError( "No configuration has been registered for this process " "or thread") return getattr(conf, attr) def current_conf(self): thread_configs = local_dict().get(self._local_key) if thread_configs: return thread_configs[-1] elif self._process_configs: return self._process_configs[-1] else: return None def __getitem__(self, key): # I thought __getattr__ would catch this, but apparently not conf = self.current_conf() if conf is None: raise TypeError( "No configuration has been registered for this process " "or thread") return conf[key] def __contains__(self, key): # I thought __getattr__ would catch this, but apparently not return key in self def __setitem__(self, key, value): # I thought __getattr__ would catch this, but apparently not conf = self.current_conf() conf[key] = value CONFIG = DispatchingConfig() class ConfigMiddleware(object): """ A WSGI middleware that adds a ``paste.config`` key to the request environment, as well as registering the configuration temporarily (for the length of the request) with ``paste.CONFIG``. """ def __init__(self, application, config): """ This delegates all requests to `application`, adding a *copy* of the configuration `config`. """ self.application = application self.config = config def __call__(self, environ, start_response): global wsgilib if wsgilib is None: import pkg_resources pkg_resources.require('Paste') from paste import wsgilib popped_config = None if 'paste.config' in environ: popped_config = environ['paste.config'] conf = environ['paste.config'] = self.config.copy() app_iter = None CONFIG.push_thread_config(conf) try: app_iter = self.application(environ, start_response) finally: if app_iter is None: # An error occurred... CONFIG.pop_thread_config(conf) if popped_config is not None: environ['paste.config'] = popped_config if type(app_iter) in (list, tuple): # Because it is a concrete iterator (not a generator) we # know the configuration for this thread is no longer # needed: CONFIG.pop_thread_config(conf) if popped_config is not None: environ['paste.config'] = popped_config return app_iter else: def close_config(): CONFIG.pop_thread_config(conf) new_app_iter = wsgilib.add_close(app_iter, close_config) return new_app_iter def make_config_filter(app, global_conf, **local_conf): conf = global_conf.copy() conf.update(local_conf) return ConfigMiddleware(app, conf) make_config_middleware = ConfigMiddleware.__doc__ class PrefixMiddleware(object): """Translate a given prefix into a SCRIPT_NAME for the filtered application. PrefixMiddleware provides a way to manually override the root prefix (SCRIPT_NAME) of your application for certain, rare situations. When running an application under a prefix (such as '/james') in FastCGI/apache, the SCRIPT_NAME environment variable is automatically set to to the appropriate value: '/james'. Pylons' URL generating functions, such as url_for, always take the SCRIPT_NAME value into account. One situation where PrefixMiddleware is required is when an application is accessed via a reverse proxy with a prefix. The application is accessed through the reverse proxy via the the URL prefix '/james', whereas the reverse proxy forwards those requests to the application at the prefix '/'. The reverse proxy, being an entirely separate web server, has no way of specifying the SCRIPT_NAME variable; it must be manually set by a PrefixMiddleware instance. Without setting SCRIPT_NAME, url_for will generate URLs such as: '/purchase_orders/1', when it should be generating: '/james/purchase_orders/1'. To filter your application through a PrefixMiddleware instance, add the following to the '[app:main]' section of your .ini file: .. code-block:: ini filter-with = proxy-prefix [filter:proxy-prefix] use = egg:PasteDeploy#prefix prefix = /james The name ``proxy-prefix`` simply acts as an identifier of the filter section; feel free to rename it. Also, unless disabled, the ``X-Forwarded-Server`` header will be translated to the ``Host`` header, for cases when that header is lost in the proxying. Also ``X-Forwarded-Host``, ``X-Forwarded-Scheme``, and ``X-Forwarded-Proto`` are translated. If ``force_port`` is set, SERVER_PORT and HTTP_HOST will be rewritten with the given port. You can use a number, string (like '80') or the empty string (whatever is the default port for the scheme). This is useful in situations where there is port forwarding going on, and the server believes itself to be on a different port than what the outside world sees. You can also use ``scheme`` to explicitly set the scheme (like ``scheme = https``). """ def __init__(self, app, global_conf=None, prefix='/', translate_forwarded_server=True, force_port=None, scheme=None): self.app = app self.prefix = prefix.rstrip('/') self.translate_forwarded_server = translate_forwarded_server self.regprefix = re.compile("^%s(.*)$" % self.prefix) self.force_port = force_port self.scheme = scheme def __call__(self, environ, start_response): url = environ['PATH_INFO'] url = re.sub(self.regprefix, r'\1', url) if not url: url = '/' environ['PATH_INFO'] = url environ['SCRIPT_NAME'] = self.prefix if self.translate_forwarded_server: if 'HTTP_X_FORWARDED_SERVER' in environ: environ['SERVER_NAME'] = environ['HTTP_HOST'] = environ.pop('HTTP_X_FORWARDED_SERVER').split(',')[0] if 'HTTP_X_FORWARDED_HOST' in environ: environ['HTTP_HOST'] = environ.pop('HTTP_X_FORWARDED_HOST').split(',')[0] if 'HTTP_X_FORWARDED_FOR' in environ: environ['REMOTE_ADDR'] = environ.pop('HTTP_X_FORWARDED_FOR').split(',')[0] if 'HTTP_X_FORWARDED_SCHEME' in environ: environ['wsgi.url_scheme'] = environ.pop('HTTP_X_FORWARDED_SCHEME') elif 'HTTP_X_FORWARDED_PROTO' in environ: environ['wsgi.url_scheme'] = environ.pop('HTTP_X_FORWARDED_PROTO') if self.force_port is not None: host = environ.get('HTTP_HOST', '').split(':', 1)[0] if self.force_port: host = '%s:%s' % (host, self.force_port) environ['SERVER_PORT'] = str(self.force_port) else: if environ['wsgi.url_scheme'] == 'http': port = '80' else: port = '443' environ['SERVER_PORT'] = port environ['HTTP_HOST'] = host if self.scheme is not None: environ['wsgi.url_scheme'] = self.scheme return self.app(environ, start_response) def make_prefix_middleware( app, global_conf, prefix='/', translate_forwarded_server=True, force_port=None, scheme=None): from paste.deploy.converters import asbool translate_forwarded_server = asbool(translate_forwarded_server) return PrefixMiddleware( app, prefix=prefix, translate_forwarded_server=translate_forwarded_server, force_port=force_port, scheme=scheme) make_prefix_middleware.__doc__ = PrefixMiddleware.__doc__ pastedeploy-2.1.0/paste/deploy/converters.py000066400000000000000000000020711361553417100212250ustar00rootroot00000000000000# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php from paste.deploy.compat import basestring truthy = frozenset(['true', 'yes', 'on', 'y', 't', '1']) falsy = frozenset(['false', 'no', 'off', 'n', 'f', '0']) def asbool(obj): if isinstance(obj, basestring): obj = obj.strip().lower() if obj in truthy: return True elif obj in falsy: return False else: raise ValueError("String is not true/false: %r" % obj) return bool(obj) def asint(obj): try: return int(obj) except (TypeError, ValueError): raise ValueError("Bad integer value: %r" % obj) def aslist(obj, sep=None, strip=True): if isinstance(obj, basestring): lst = obj.split(sep) if strip: lst = [v.strip() for v in lst] return lst elif isinstance(obj, (list, tuple)): return obj elif obj is None: return [] else: return [obj] pastedeploy-2.1.0/paste/deploy/loadwsgi.py000066400000000000000000000623251361553417100206540ustar00rootroot00000000000000# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php from __future__ import with_statement import os import sys import re import pkg_resources from paste.deploy.compat import ConfigParser, unquote, iteritems, dictkeys from paste.deploy.util import fix_call, lookup_object __all__ = ['loadapp', 'loadserver', 'loadfilter', 'appconfig'] ############################################################ ## Utility functions ############################################################ def import_string(s): ep = pkg_resources.EntryPoint.parse("x=" + s) if hasattr(ep, 'resolve'): # this is available on setuptools >= 10.2 return ep.resolve() else: # this causes a DeprecationWarning on setuptools >= 11.3 return ep.load(False) def _aslist(obj): """ Turn object into a list; lists and tuples are left as-is, None becomes [], and everything else turns into a one-element list. """ if obj is None: return [] elif isinstance(obj, (list, tuple)): return obj else: return [obj] def _flatten(lst): """ Flatten a nested list. """ if not isinstance(lst, (list, tuple)): return [lst] result = [] for item in lst: result.extend(_flatten(item)) return result class NicerConfigParser(ConfigParser): def __init__(self, filename, *args, **kw): ConfigParser.__init__(self, *args, **kw) self.filename = filename if hasattr(self, '_interpolation'): self._interpolation = self.InterpolateWrapper(self._interpolation) read_file = getattr(ConfigParser, 'read_file', ConfigParser.readfp) def defaults(self): """Return the defaults, with their values interpolated (with the defaults dict itself) Mainly to support defaults using values such as %(here)s """ defaults = ConfigParser.defaults(self).copy() for key, val in iteritems(defaults): defaults[key] = self.get('DEFAULT', key) or val return defaults def _interpolate(self, section, option, rawval, vars): # Python < 3.2 try: return ConfigParser._interpolate( self, section, option, rawval, vars) except Exception: e = sys.exc_info()[1] args = list(e.args) args[0] = 'Error in file %s: %s' % (self.filename, e) e.args = tuple(args) e.message = args[0] raise class InterpolateWrapper(object): # Python >= 3.2 def __init__(self, original): self._original = original def __getattr__(self, name): return getattr(self._original, name) def before_get(self, parser, section, option, value, defaults): try: return self._original.before_get(parser, section, option, value, defaults) except Exception: e = sys.exc_info()[1] args = list(e.args) args[0] = 'Error in file %s: %s' % (parser.filename, e) e.args = tuple(args) e.message = args[0] raise ############################################################ ## Object types ############################################################ class _ObjectType(object): name = None egg_protocols = None config_prefixes = None def __init__(self): # Normalize these variables: self.egg_protocols = [_aslist(p) for p in _aslist(self.egg_protocols)] self.config_prefixes = [_aslist(p) for p in _aslist(self.config_prefixes)] def __repr__(self): return '<%s protocols=%r prefixes=%r>' % ( self.name, self.egg_protocols, self.config_prefixes) def invoke(self, context): assert context.protocol in _flatten(self.egg_protocols) return fix_call(context.object, context.global_conf, **context.local_conf) class _App(_ObjectType): name = 'application' egg_protocols = ['paste.app_factory', 'paste.composite_factory', 'paste.composit_factory'] config_prefixes = [['app', 'application'], ['composite', 'composit'], 'pipeline', 'filter-app'] def invoke(self, context): if context.protocol in ('paste.composit_factory', 'paste.composite_factory'): return fix_call(context.object, context.loader, context.global_conf, **context.local_conf) elif context.protocol == 'paste.app_factory': return fix_call(context.object, context.global_conf, **context.local_conf) else: assert 0, "Protocol %r unknown" % context.protocol APP = _App() class _Filter(_ObjectType): name = 'filter' egg_protocols = [['paste.filter_factory', 'paste.filter_app_factory']] config_prefixes = ['filter'] def invoke(self, context): if context.protocol == 'paste.filter_factory': return fix_call(context.object, context.global_conf, **context.local_conf) elif context.protocol == 'paste.filter_app_factory': def filter_wrapper(wsgi_app): # This should be an object, so it has a nicer __repr__ return fix_call(context.object, wsgi_app, context.global_conf, **context.local_conf) return filter_wrapper else: assert 0, "Protocol %r unknown" % context.protocol FILTER = _Filter() class _Server(_ObjectType): name = 'server' egg_protocols = [['paste.server_factory', 'paste.server_runner']] config_prefixes = ['server'] def invoke(self, context): if context.protocol == 'paste.server_factory': return fix_call(context.object, context.global_conf, **context.local_conf) elif context.protocol == 'paste.server_runner': def server_wrapper(wsgi_app): # This should be an object, so it has a nicer __repr__ return fix_call(context.object, wsgi_app, context.global_conf, **context.local_conf) return server_wrapper else: assert 0, "Protocol %r unknown" % context.protocol SERVER = _Server() # Virtual type: (@@: There's clearly something crufty here; # this probably could be more elegant) class _PipeLine(_ObjectType): name = 'pipeline' def invoke(self, context): app = context.app_context.create() filters = [c.create() for c in context.filter_contexts] filters.reverse() for filter in filters: app = filter(app) return app PIPELINE = _PipeLine() class _FilterApp(_ObjectType): name = 'filter_app' def invoke(self, context): next_app = context.next_context.create() filter = context.filter_context.create() return filter(next_app) FILTER_APP = _FilterApp() class _FilterWith(_App): name = 'filtered_with' def invoke(self, context): filter = context.filter_context.create() filtered = context.next_context.create() if context.next_context.object_type is APP: return filter(filtered) else: # filtering a filter def composed(app): return filter(filtered(app)) return composed FILTER_WITH = _FilterWith() ############################################################ ## Loaders ############################################################ def loadapp(uri, name=None, **kw): return loadobj(APP, uri, name=name, **kw) def loadfilter(uri, name=None, **kw): return loadobj(FILTER, uri, name=name, **kw) def loadserver(uri, name=None, **kw): return loadobj(SERVER, uri, name=name, **kw) def appconfig(uri, name=None, relative_to=None, global_conf=None): context = loadcontext(APP, uri, name=name, relative_to=relative_to, global_conf=global_conf) return context.config() _loaders = {} def loadobj(object_type, uri, name=None, relative_to=None, global_conf=None): context = loadcontext( object_type, uri, name=name, relative_to=relative_to, global_conf=global_conf) return context.create() def loadcontext(object_type, uri, name=None, relative_to=None, global_conf=None): if '#' in uri: if name is None: uri, name = uri.split('#', 1) else: # @@: Ignore fragment or error? uri = uri.split('#', 1)[0] if name is None: name = 'main' if ':' not in uri: raise LookupError("URI has no scheme: %r" % uri) scheme, path = uri.split(':', 1) scheme = scheme.lower() if scheme not in _loaders: raise LookupError( "URI scheme not known: %r (from %s)" % (scheme, ', '.join(_loaders.keys()))) return _loaders[scheme]( object_type, uri, path, name=name, relative_to=relative_to, global_conf=global_conf) def _loadconfig(object_type, uri, path, name, relative_to, global_conf): isabs = os.path.isabs(path) # De-Windowsify the paths: path = path.replace('\\', '/') if not isabs: if not relative_to: raise ValueError( "Cannot resolve relative uri %r; no relative_to keyword " "argument given" % uri) relative_to = relative_to.replace('\\', '/') if relative_to.endswith('/'): path = relative_to + path else: path = relative_to + '/' + path if path.startswith('///'): path = path[2:] path = unquote(path) loader = ConfigLoader(path) if global_conf: loader.update_defaults(global_conf, overwrite=False) return loader.get_context(object_type, name, global_conf) _loaders['config'] = _loadconfig def _loadegg(object_type, uri, spec, name, relative_to, global_conf): loader = EggLoader(spec) return loader.get_context(object_type, name, global_conf) _loaders['egg'] = _loadegg def _loadfunc(object_type, uri, spec, name, relative_to, global_conf): loader = FuncLoader(spec) return loader.get_context(object_type, name, global_conf) _loaders['call'] = _loadfunc ############################################################ ## Loaders ############################################################ class _Loader(object): def get_app(self, name=None, global_conf=None): return self.app_context( name=name, global_conf=global_conf).create() def get_filter(self, name=None, global_conf=None): return self.filter_context( name=name, global_conf=global_conf).create() def get_server(self, name=None, global_conf=None): return self.server_context( name=name, global_conf=global_conf).create() def app_context(self, name=None, global_conf=None): return self.get_context( APP, name=name, global_conf=global_conf) def filter_context(self, name=None, global_conf=None): return self.get_context( FILTER, name=name, global_conf=global_conf) def server_context(self, name=None, global_conf=None): return self.get_context( SERVER, name=name, global_conf=global_conf) _absolute_re = re.compile(r'^[a-zA-Z]+:') def absolute_name(self, name): """ Returns true if the name includes a scheme """ if name is None: return False return self._absolute_re.search(name) class ConfigLoader(_Loader): def __init__(self, filename): self.filename = filename = filename.strip() defaults = { 'here': os.path.dirname(os.path.abspath(filename)), '__file__': os.path.abspath(filename) } self.parser = NicerConfigParser(filename, defaults=defaults) self.parser.optionxform = str # Don't lower-case keys with open(filename) as f: self.parser.read_file(f) def update_defaults(self, new_defaults, overwrite=True): for key, value in iteritems(new_defaults): if not overwrite and key in self.parser._defaults: continue self.parser._defaults[key] = value def get_context(self, object_type, name=None, global_conf=None): if self.absolute_name(name): return loadcontext(object_type, name, relative_to=os.path.dirname(self.filename), global_conf=global_conf) section = self.find_config_section( object_type, name=name) defaults = self.parser.defaults() _global_conf = defaults.copy() if global_conf is not None: _global_conf.update(global_conf) global_conf = _global_conf local_conf = {} global_additions = {} get_from_globals = {} for option in self.parser.options(section): if option.startswith('set '): name = option[4:].strip() global_additions[name] = global_conf[name] = ( self.parser.get(section, option)) elif option.startswith('get '): name = option[4:].strip() get_from_globals[name] = self.parser.get(section, option) else: if option in defaults: # @@: It's a global option (?), so skip it continue local_conf[option] = self.parser.get(section, option) for local_var, glob_var in get_from_globals.items(): local_conf[local_var] = global_conf[glob_var] if object_type in (APP, FILTER) and 'filter-with' in local_conf: filter_with = local_conf.pop('filter-with') else: filter_with = None if 'require' in local_conf: for spec in local_conf['require'].split(): pkg_resources.require(spec) del local_conf['require'] if section.startswith('filter-app:'): context = self._filter_app_context( object_type, section, name=name, global_conf=global_conf, local_conf=local_conf, global_additions=global_additions) elif section.startswith('pipeline:'): context = self._pipeline_app_context( object_type, section, name=name, global_conf=global_conf, local_conf=local_conf, global_additions=global_additions) elif 'use' in local_conf: context = self._context_from_use( object_type, local_conf, global_conf, global_additions, section) else: context = self._context_from_explicit( object_type, local_conf, global_conf, global_additions, section) if filter_with is not None: filter_with_context = LoaderContext( obj=None, object_type=FILTER_WITH, protocol=None, global_conf=global_conf, local_conf=local_conf, loader=self) filter_with_context.filter_context = self.filter_context( name=filter_with, global_conf=global_conf) filter_with_context.next_context = context return filter_with_context return context def _context_from_use(self, object_type, local_conf, global_conf, global_additions, section): use = local_conf.pop('use') context = self.get_context( object_type, name=use, global_conf=global_conf) context.global_conf.update(global_additions) context.local_conf.update(local_conf) if '__file__' in global_conf: # use sections shouldn't overwrite the original __file__ context.global_conf['__file__'] = global_conf['__file__'] # @@: Should loader be overwritten? context.loader = self if context.protocol is None: # Determine protocol from section type section_protocol = section.split(':', 1)[0] if section_protocol in ('application', 'app'): context.protocol = 'paste.app_factory' elif section_protocol in ('composit', 'composite'): context.protocol = 'paste.composit_factory' else: # This will work with 'server' and 'filter', otherwise it # could fail but there is an error message already for # bad protocols context.protocol = 'paste.%s_factory' % section_protocol return context def _context_from_explicit(self, object_type, local_conf, global_conf, global_addition, section): possible = [] for protocol_options in object_type.egg_protocols: for protocol in protocol_options: if protocol in local_conf: possible.append((protocol, local_conf[protocol])) break if len(possible) > 1: raise LookupError( "Multiple protocols given in section %r: %s" % (section, possible)) if not possible: raise LookupError( "No loader given in section %r" % section) found_protocol, found_expr = possible[0] del local_conf[found_protocol] value = import_string(found_expr) context = LoaderContext( value, object_type, found_protocol, global_conf, local_conf, self) return context def _filter_app_context(self, object_type, section, name, global_conf, local_conf, global_additions): if 'next' not in local_conf: raise LookupError( "The [%s] section in %s is missing a 'next' setting" % (section, self.filename)) next_name = local_conf.pop('next') context = LoaderContext(None, FILTER_APP, None, global_conf, local_conf, self) context.next_context = self.get_context( APP, next_name, global_conf) if 'use' in local_conf: context.filter_context = self._context_from_use( FILTER, local_conf, global_conf, global_additions, section) else: context.filter_context = self._context_from_explicit( FILTER, local_conf, global_conf, global_additions, section) return context def _pipeline_app_context(self, object_type, section, name, global_conf, local_conf, global_additions): if 'pipeline' not in local_conf: raise LookupError( "The [%s] section in %s is missing a 'pipeline' setting" % (section, self.filename)) pipeline = local_conf.pop('pipeline').split() if local_conf: raise LookupError( "The [%s] pipeline section in %s has extra " "(disallowed) settings: %s" % (section, self.filename, ', '.join(local_conf.keys()))) context = LoaderContext(None, PIPELINE, None, global_conf, local_conf, self) context.app_context = self.get_context( APP, pipeline[-1], global_conf) context.filter_contexts = [ self.get_context(FILTER, name, global_conf) for name in pipeline[:-1]] return context def find_config_section(self, object_type, name=None): """ Return the section name with the given name prefix (following the same pattern as ``protocol_desc`` in ``config``. It must have the given name, or for ``'main'`` an empty name is allowed. The prefix must be followed by a ``:``. Case is *not* ignored. """ possible = [] for name_options in object_type.config_prefixes: for name_prefix in name_options: found = self._find_sections( self.parser.sections(), name_prefix, name) if found: possible.extend(found) break if not possible: raise LookupError( "No section %r (prefixed by %s) found in config %s" % (name, ' or '.join(map(repr, _flatten(object_type.config_prefixes))), self.filename)) if len(possible) > 1: raise LookupError( "Ambiguous section names %r for section %r (prefixed by %s) " "found in config %s" % (possible, name, ' or '.join(map(repr, _flatten(object_type.config_prefixes))), self.filename)) return possible[0] def _find_sections(self, sections, name_prefix, name): found = [] if name is None: if name_prefix in sections: found.append(name_prefix) name = 'main' for section in sections: if section.startswith(name_prefix + ':'): if section[len(name_prefix) + 1:].strip() == name: found.append(section) return found class EggLoader(_Loader): def __init__(self, spec): self.spec = spec def get_context(self, object_type, name=None, global_conf=None): if self.absolute_name(name): return loadcontext(object_type, name, global_conf=global_conf) entry_point, protocol, ep_name = self.find_egg_entry_point( object_type, name=name) return LoaderContext( entry_point, object_type, protocol, global_conf or {}, {}, self, distribution=pkg_resources.get_distribution(self.spec), entry_point_name=ep_name) def find_egg_entry_point(self, object_type, name=None): """ Returns the (entry_point, protocol) for the with the given ``name``. """ if name is None: name = 'main' possible = [] for protocol_options in object_type.egg_protocols: for protocol in protocol_options: pkg_resources.require(self.spec) entry = pkg_resources.get_entry_info( self.spec, protocol, name) if entry is not None: possible.append((entry.load(), protocol, entry.name)) break if not possible: # Better exception dist = pkg_resources.get_distribution(self.spec) raise LookupError( "Entry point %r not found in egg %r (dir: %s; protocols: %s; " "entry_points: %s)" % (name, self.spec, dist.location, ', '.join(_flatten(object_type.egg_protocols)), ', '.join(_flatten([ dictkeys(pkg_resources.get_entry_info(self.spec, prot, name) or {}) for prot in protocol_options] or '(no entry points)')))) if len(possible) > 1: raise LookupError( "Ambiguous entry points for %r in egg %r (protocols: %s)" % (name, self.spec, ', '.join(_flatten(protocol_options)))) return possible[0] class FuncLoader(_Loader): """ Loader that supports specifying functions inside modules, without using eggs at all. Configuration should be in the format: use = call:my.module.path:function_name Dot notation is supported in both the module and function name, e.g.: use = call:my.module.path:object.method """ def __init__(self, spec): self.spec = spec if not ':' in spec: raise LookupError("Configuration not in format module:function") def get_context(self, object_type, name=None, global_conf=None): obj = lookup_object(self.spec) return LoaderContext( obj, object_type, None, # determine protocol from section type global_conf or {}, {}, self, ) class LoaderContext(object): def __init__(self, obj, object_type, protocol, global_conf, local_conf, loader, distribution=None, entry_point_name=None): self.object = obj self.object_type = object_type self.protocol = protocol #assert protocol in _flatten(object_type.egg_protocols), ( # "Bad protocol %r; should be one of %s" # % (protocol, ', '.join(map(repr, _flatten(object_type.egg_protocols))))) self.global_conf = global_conf self.local_conf = local_conf self.loader = loader self.distribution = distribution self.entry_point_name = entry_point_name def create(self): return self.object_type.invoke(self) def config(self): conf = AttrDict(self.global_conf) conf.update(self.local_conf) conf.local_conf = self.local_conf conf.global_conf = self.global_conf conf.context = self return conf class AttrDict(dict): """ A dictionary that can be assigned to. """ pass pastedeploy-2.1.0/paste/deploy/paster_templates.py000066400000000000000000000023561361553417100224150ustar00rootroot00000000000000# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php import os from paste.script.templates import Template from paste.deploy.compat import print_ class PasteDeploy(Template): _template_dir = 'paster_templates/paste_deploy' summary = "A web application deployed through paste.deploy" egg_plugins = ['PasteDeploy'] required_templates = ['PasteScript#basic_package'] def post(self, command, output_dir, vars): for prereq in ['PasteDeploy']: command.insert_into_file( os.path.join(output_dir, 'setup.py'), 'Extra requirements', '%r,\n' % prereq, indent=True) command.insert_into_file( os.path.join(output_dir, 'setup.py'), 'Entry points', (' [paste.app_factory]\n' ' main = %(package)s.wsgiapp:make_app\n') % vars, indent=False) if command.verbose: print_('*' * 72) print_('* Run "paster serve docs/devel_config.ini" to run the sample application') print_('* on http://localhost:8080') print_('*' * 72) pastedeploy-2.1.0/paste/deploy/paster_templates/000077500000000000000000000000001361553417100220355ustar00rootroot00000000000000pastedeploy-2.1.0/paste/deploy/paster_templates/paste_deploy/000077500000000000000000000000001361553417100245255ustar00rootroot00000000000000pastedeploy-2.1.0/paste/deploy/paster_templates/paste_deploy/+package+/000077500000000000000000000000001361553417100262465ustar00rootroot00000000000000pastedeploy-2.1.0/paste/deploy/paster_templates/paste_deploy/+package+/sampleapp.py_tmpl000066400000000000000000000015101361553417100316330ustar00rootroot00000000000000import cgi from paste.deploy.config import CONFIG def application(environ, start_response): # Note that usually you wouldn't be writing a pure WSGI # application, you might be using some framework or # environment. But as an example... start_response('200 OK', [('Content-type', 'text/html')]) greeting = CONFIG['greeting'] content = [ b'%s\n' % greeting.encode('utf-8'), b'

%s!

\n' % greeting.encode('utf-8'), b'\n', ] items = environ.items() items = sorted(items) for key, value in items: content.append(b'\n' % (key.encode('utf-8'), cgi.escape(repr(value)).encode('utf-8'))) content.append(b'
%s%s
') return content pastedeploy-2.1.0/paste/deploy/paster_templates/paste_deploy/+package+/wsgiapp.py_tmpl000066400000000000000000000014441361553417100313310ustar00rootroot00000000000000from __future__ import absolute_import from paste.deploy.config import ConfigMiddleware from . import sampleapp def make_app( global_conf, # Optional and required configuration parameters # can go here, or just **kw; greeting is required: greeting, **kw): # This is a WSGI application: app = sampleapp.application # Here we merge all the keys into one configuration # dictionary; you don't have to do this, but this # can be convenient later to add ad hoc configuration: conf = global_conf.copy() conf.update(kw) conf['greeting'] = greeting # ConfigMiddleware means that paste.deploy.CONFIG will, # during this request (threadsafe) represent the # configuration dictionary we set up: app = ConfigMiddleware(app, conf) return app pastedeploy-2.1.0/paste/deploy/paster_templates/paste_deploy/docs/000077500000000000000000000000001361553417100254555ustar00rootroot00000000000000pastedeploy-2.1.0/paste/deploy/paster_templates/paste_deploy/docs/devel_config.ini_tmpl000066400000000000000000000007351361553417100316430ustar00rootroot00000000000000[filter-app:main] # This puts the interactive debugger in place: use = egg:Paste#evalerror next = devel [app:devel] # This application is meant for interactive development use = egg:${project} debug = true # You can add other configuration values: greeting = Aloha! [app:test] # While this version of the configuration is for non-iteractive # tests (unit tests) use = devel [server:main] use = egg:Paste#http # Change to 0.0.0.0 to make public: host = 127.0.0.1 port = 8080 pastedeploy-2.1.0/paste/deploy/util.py000066400000000000000000000041771361553417100200210ustar00rootroot00000000000000# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php import inspect import sys from paste.deploy.compat import reraise def fix_type_error(exc_info, callable, varargs, kwargs): """ Given an exception, this will test if the exception was due to a signature error, and annotate the error with better information if so. Usage:: try: val = callable(*args, **kw) except TypeError: exc_info = fix_type_error(None, callable, args, kw) raise exc_info[0], exc_info[1], exc_info[2] """ if exc_info is None: exc_info = sys.exc_info() if (exc_info[0] != TypeError or str(exc_info[1]).find('arguments') == -1 or getattr(exc_info[1], '_type_error_fixed', False)): return exc_info exc_info[1]._type_error_fixed = True argspec = inspect.formatargspec(*inspect.getargspec(callable)) args = ', '.join(map(_short_repr, varargs)) if kwargs and args: args += ', ' if kwargs: kwargs = sorted(kwargs.items()) args += ', '.join(['%s=...' % n for n, v in kwargs]) gotspec = '(%s)' % args msg = '%s; got %s, wanted %s' % (exc_info[1], gotspec, argspec) exc_info[1].args = (msg,) return exc_info def _short_repr(v): v = repr(v) if len(v) > 12: v = v[:8] + '...' + v[-4:] return v def fix_call(callable, *args, **kw): """ Call ``callable(*args, **kw)`` fixing any type errors that come out. """ try: val = callable(*args, **kw) except TypeError: exc_info = fix_type_error(None, callable, args, kw) reraise(*exc_info) return val def lookup_object(spec): """ Looks up a module or object from a some.module:func_name specification. To just look up a module, omit the colon and everything after it. """ parts, target = spec.split(':') if ':' in spec else (spec, None) module = __import__(parts) for part in parts.split('.')[1:] + ([target] if target else []): module = getattr(module, part) return module pastedeploy-2.1.0/pytest.ini000066400000000000000000000000331361553417100160760ustar00rootroot00000000000000[pytest] testpaths = tests pastedeploy-2.1.0/rtd.txt000066400000000000000000000000131361553417100153750ustar00rootroot00000000000000-e .[docs] pastedeploy-2.1.0/setup.cfg000066400000000000000000000000311361553417100156640ustar00rootroot00000000000000[wheel] universal = true pastedeploy-2.1.0/setup.py000066400000000000000000000046161361553417100155720ustar00rootroot00000000000000import os from setuptools import setup, find_packages here = os.path.dirname(__file__) readme_path = os.path.join(here, "README.rst") readme = open(readme_path).read() docs_extras = [ "Sphinx >= 1.7.5", # Read The Docs minimum version "pylons-sphinx-themes", ] setup( name="PasteDeploy", version="2.1.0", description="Load, configure, and compose WSGI applications and servers", long_description=readme, classifiers=[ "Development Status :: 6 - Mature", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Internet :: WWW/HTTP :: WSGI", "Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware", "Topic :: Software Development :: Libraries :: Python Modules", "Framework :: Paste", ], keywords="web wsgi application server", author="Ian Bicking", author_email="pylons-discuss@googlegroups.com", maintainer="Chris Dent", maintainer_email="pylons-discuss@googlegroups.com", url="https://pylonsproject.org/", project_urls={ "Documentation": "https://docs.pylonsproject.org/projects/pastedeploy/en/latest/", "Changelog": "https://docs.pylonsproject.org/projects/pastedeploy/en/latest/news.html", "Issue Tracker": "https://github.com/Pylons/pastedeploy/issues", }, license="MIT", namespace_packages=["paste"], packages=find_packages(exclude=["tests"]), include_package_data=True, zip_safe=False, extras_require={ "Config": [], "Paste": ["Paste"], "docs": docs_extras, }, entry_points=""" [paste.filter_app_factory] config = paste.deploy.config:make_config_filter [Config] prefix = paste.deploy.config:make_prefix_middleware [paste.paster_create_template] paste_deploy=paste.deploy.paster_templates:PasteDeploy """ ) pastedeploy-2.1.0/tests/000077500000000000000000000000001361553417100152135ustar00rootroot00000000000000pastedeploy-2.1.0/tests/__init__.py000066400000000000000000000004651361553417100173310ustar00rootroot00000000000000import os import sys here = os.path.dirname(__file__) base = os.path.dirname(here) sys.path.insert(0, base) # We can only import this after we adjust the paths import pkg_resources # Make absolutely sure we're testing *this* package, not # some other installed package pkg_resources.require('PasteDeploy') pastedeploy-2.1.0/tests/fake_packages/000077500000000000000000000000001361553417100177575ustar00rootroot00000000000000pastedeploy-2.1.0/tests/fake_packages/FakeApp.egg/000077500000000000000000000000001361553417100220275ustar00rootroot00000000000000pastedeploy-2.1.0/tests/fake_packages/FakeApp.egg/FakeApp.egg-info/000077500000000000000000000000001361553417100250305ustar00rootroot00000000000000pastedeploy-2.1.0/tests/fake_packages/FakeApp.egg/FakeApp.egg-info/PKG-INFO000066400000000000000000000002631361553417100261260ustar00rootroot00000000000000Metadata-Version: 1.0 Name: FakeApp Version: 1.0 Summary: UNKNOWN Home-page: UNKNOWN Author: UNKNOWN Author-email: UNKNOWN License: UNKNOWN Description: UNKNOWN Platform: UNKNOWN pastedeploy-2.1.0/tests/fake_packages/FakeApp.egg/FakeApp.egg-info/entry_points.txt000066400000000000000000000006101361553417100303230ustar00rootroot00000000000000[paste.app_factory] basic_app=fakeapp.apps:make_basic_app other=fakeapp.apps:make_basic_app2 configed=fakeapp.configapps:SimpleApp.make_app [paste.composit_factory] remote_addr=fakeapp.apps:make_remote_addr [paste.filter_app_factory] caps2=fakeapp.apps:CapFilter [paste.filter_factory] caps=fakeapp.apps:make_cap_filter pastedeploy-2.1.0/tests/fake_packages/FakeApp.egg/FakeApp.egg-info/top_level.txt000066400000000000000000000000101361553417100275510ustar00rootroot00000000000000fakeapp pastedeploy-2.1.0/tests/fake_packages/FakeApp.egg/fakeapp/000077500000000000000000000000001361553417100234365ustar00rootroot00000000000000pastedeploy-2.1.0/tests/fake_packages/FakeApp.egg/fakeapp/__init__.py000066400000000000000000000000021361553417100255370ustar00rootroot00000000000000# pastedeploy-2.1.0/tests/fake_packages/FakeApp.egg/fakeapp/apps.py000066400000000000000000000042501361553417100247540ustar00rootroot00000000000000############################################################ ## Apps ############################################################ def simple_app(response, environ, start_response): start_response('200 OK', [('Content-type', 'text/html')]) return ['This is ', response] def basic_app(environ, start_response): return simple_app('basic app', environ, start_response) def make_basic_app(global_conf, **conf): return basic_app def basic_app2(environ, start_response): return simple_app('basic app2', environ, start_response) def make_basic_app2(global_conf, **conf): return basic_app2 ############################################################ ## Composits ############################################################ def make_remote_addr(loader, global_conf, **conf): apps = {} addrs = {} for name, value in conf.items(): if name.startswith('app.'): apps[name[4:]] = loader.get_app(value, global_conf) elif name.startswith('addr.'): addrs[name[5:]] = value dispatcher = RemoteAddrDispatch() for name in apps: dispatcher.map[addrs[name]] = apps[name] return dispatcher class RemoteAddrDispatch(object): def __init__(self, map=None): self.map = map or {} def __call__(self, environ, start_response): addr = environ['REMOTE_ADDR'] app = self.map.get(addr) or self.map['0.0.0.0'] return app(environ, start_response) ############################################################ ## Filters ############################################################ def make_cap_filter(global_conf, method_to_call='upper'): def cap_filter(app): return CapFilter(app, global_conf, method_to_call) return cap_filter class CapFilter(object): def __init__(self, app, global_conf, method_to_call='upper'): self.app = app self.method_to_call = method_to_call self.global_conf = global_conf def __call__(self, environ, start_response): app_iter = self.app(environ, start_response) for item in app_iter: yield getattr(item, self.method_to_call)() if hasattr(app_iter, 'close'): app_iter.close() pastedeploy-2.1.0/tests/fake_packages/FakeApp.egg/fakeapp/configapps.py000066400000000000000000000007231361553417100261430ustar00rootroot00000000000000class SimpleApp(object): def __init__(self, global_conf, local_conf, name): self.global_conf = global_conf self.local_conf = local_conf self.name = name def __call__(self, environ, start_response): start_response('200 OK', [('Content-type', 'text/html')]) return ['I am: ', name] def make_app(cls, global_conf, **conf): return cls(global_conf, conf, 'basic') make_app = classmethod(make_app) pastedeploy-2.1.0/tests/fake_packages/FakeApp.egg/setup.py000066400000000000000000000011271361553417100235420ustar00rootroot00000000000000from setuptools import setup, find_packages setup( name="FakeApp", version="1.0", packages=find_packages(), entry_points={ 'paste.app_factory': """ basic_app=fakeapp.apps:make_basic_app other=fakeapp.apps:make_basic_app2 configed=fakeapp.configapps:SimpleApp.make_app """, 'paste.composit_factory': """ remote_addr=fakeapp.apps:make_remote_addr """, 'paste.filter_factory': """ caps=fakeapp.apps:make_cap_filter """, 'paste.filter_app_factory': """ caps2=fakeapp.apps:CapFilter """, }, ) pastedeploy-2.1.0/tests/fixture.py000066400000000000000000000011171361553417100172530ustar00rootroot00000000000000import os import sys import shutil test_dir = os.path.dirname(__file__) egg_info_dir = os.path.join(test_dir, 'fake_packages', 'FakeApp.egg', 'EGG-INFO') info_dir = os.path.join(test_dir, 'fake_packages', 'FakeApp.egg', 'FakeApp.egg-info') if not os.path.exists(egg_info_dir): try: os.symlink(info_dir, egg_info_dir) except: shutil.copytree(info_dir, egg_info_dir) sys.path.append(os.path.dirname(egg_info_dir)) from pkg_resources import * working_set.add_entry(os.path.dirname(egg_info_dir)) require('FakeApp') pastedeploy-2.1.0/tests/sample_configs/000077500000000000000000000000001361553417100202045ustar00rootroot00000000000000pastedeploy-2.1.0/tests/sample_configs/basic_app.ini000066400000000000000000000003231361553417100226240ustar00rootroot00000000000000[application:main] use = egg:FakeApp#basic_app [application:other] use = egg:FakeApp#other [composit:remote_addr] use = egg:FakeApp#remote_addr app.1 = main addr.1 = 127.0.0.1 app.2 = other addr.2 = 0.0.0.0 pastedeploy-2.1.0/tests/sample_configs/executable.ini000077500000000000000000000002411361553417100230260ustar00rootroot00000000000000#!/usr/bin/env paster [exe] sys.path = /fake/path/ /another/fake/path ../fake_packages/ [server] use = egg:PasteScript#cgi [app] use = egg:FakeApp#basic_app pastedeploy-2.1.0/tests/sample_configs/test_config.ini000066400000000000000000000011451361553417100232120ustar00rootroot00000000000000[DEFAULT] def1 = a def2 = b basepath = %(here)s [app:test1] use = egg:FakeApp#configed setting1 = foo setting2 = bar apppath = %(basepath)s/app [app:test2] use = egg:FakeApp#configed set def1 = test2 set another = TEST local conf = something [app:test3] use = test2 set def1 = test3 another = something more across several lines [app:test_foreign_config] use = config:test_config_included.ini set glob = override another = FOO [app:test_get] use = egg:FakeApp#configed set def2 = TEST get def1 = def1 get foo = def2 [app:test_global_conf] use = egg:FakeApp#configed test_interp = this:%(inherit)s pastedeploy-2.1.0/tests/sample_configs/test_config_included.ini000066400000000000000000000003251361553417100250600ustar00rootroot00000000000000[DEFAULT] def2 = from include def3 = c [app:main] # Equivalent to the egg reference, but just for kicks... paste.app_factory = fakeapp.configapps:SimpleApp.make_app set glob = orig bob = your uncle another = BAR pastedeploy-2.1.0/tests/sample_configs/test_error.ini000066400000000000000000000001641361553417100230760ustar00rootroot00000000000000[DEFAULT] def1 = a def2 = b [app:main] use = egg:FakeApp#configed setting1 = foo setting2 = %(does_not_exist)s/bar pastedeploy-2.1.0/tests/sample_configs/test_filter.ini000066400000000000000000000007131361553417100232320ustar00rootroot00000000000000[app:normal] use = egg:FakeApp#basic_app [pipeline:piped] pipeline = egg:FakeApp#caps normal [filter-app:filt] use = egg:FakeApp#caps method_to_call = lower next = normal [pipeline:piped2] pipeline = egg:FakeApp#caps2 normal [filter-app:filt2] use = egg:FakeApp#caps2 method_to_call = lower next = normal [app:inv] use = egg:FakeApp#basic_app filter-with = egg:FakeApp#caps [pipeline:piped3] pipeline = egg:FakeApp#caps normal extra_config_option = bad pastedeploy-2.1.0/tests/sample_configs/test_filter_with.ini000066400000000000000000000002651361553417100242670ustar00rootroot00000000000000[app:main] use = egg:FakeApp#basic_app example = test filter-with = filter1 [filter:filter1] use = egg:FakeApp#caps filter-with = filter2 [filter:filter2] use = egg:FakeApp#caps pastedeploy-2.1.0/tests/sample_configs/test_func.ini000066400000000000000000000003671361553417100227050ustar00rootroot00000000000000[application:main] use = call:fakeapp.apps:make_basic_app [application:other] use = call:fakeapp.apps:make_basic_app2 [composit:remote_addr] use = call:fakeapp.apps:make_remote_addr app.1 = main addr.1 = 127.0.0.1 app.2 = other addr.2 = 0.0.0.0pastedeploy-2.1.0/tests/test_basic_app.py000066400000000000000000000022271361553417100205500ustar00rootroot00000000000000from paste.deploy import loadapp from tests.fixture import * import fakeapp.apps here = os.path.dirname(__file__) def test_main(): app = loadapp('config:sample_configs/basic_app.ini', relative_to=here) assert app is fakeapp.apps.basic_app app = loadapp('config:sample_configs/basic_app.ini#main', relative_to=here) assert app is fakeapp.apps.basic_app app = loadapp('config:sample_configs/basic_app.ini', relative_to=here, name='main') assert app is fakeapp.apps.basic_app app = loadapp('config:sample_configs/basic_app.ini#ignored', relative_to=here, name='main') assert app is fakeapp.apps.basic_app def test_other(): app = loadapp('config:sample_configs/basic_app.ini#other', relative_to=here) assert app is fakeapp.apps.basic_app2 def test_composit(): app = loadapp('config:sample_configs/basic_app.ini#remote_addr', relative_to=here) assert isinstance(app, fakeapp.apps.RemoteAddrDispatch) assert app.map['127.0.0.1'] is fakeapp.apps.basic_app assert app.map['0.0.0.0'] is fakeapp.apps.basic_app2 pastedeploy-2.1.0/tests/test_config.py000066400000000000000000000123471361553417100201000ustar00rootroot00000000000000from paste.deploy import loadapp, appconfig from tests.fixture import * import fakeapp.configapps as fc import fakeapp.apps ini_file = 'config:sample_configs/test_config.ini' here = os.path.dirname(__file__) config_path = os.path.join(here, 'sample_configs') config_filename = os.path.join(config_path, 'test_config.ini') def test_config_egg(): app = loadapp('egg:FakeApp#configed') assert isinstance(app, fc.SimpleApp) def test_config1(): app = loadapp(ini_file, relative_to=here, name='test1') assert app.local_conf == { 'setting1': 'foo', 'setting2': 'bar', 'apppath': os.path.join(config_path, 'app')} assert app.global_conf == { 'def1': 'a', 'def2': 'b', 'basepath': config_path, 'here': config_path, '__file__': config_filename} def test_config2(): app = loadapp(ini_file, relative_to=here, name='test2') assert app.local_conf == { 'local conf': 'something'} assert app.global_conf == { 'def1': 'test2', 'def2': 'b', 'basepath': config_path, 'another': 'TEST', 'here': config_path, '__file__': config_filename} # Run this to make sure the global-conf-modified test2 # didn't mess up the general global conf test_config1() def test_config3(): app = loadapp(ini_file, relative_to=here, name='test3') assert isinstance(app, fc.SimpleApp) assert app.local_conf == { 'local conf': 'something', 'another': 'something more\nacross several\nlines'} assert app.global_conf == { 'def1': 'test3', 'def2': 'b', 'basepath': config_path, 'another': 'TEST', 'here': config_path, '__file__': config_filename} test_config2() def test_main(): app = loadapp('config:test_func.ini', relative_to=config_path) assert app is fakeapp.apps.basic_app app = loadapp('config:test_func.ini#main', relative_to=config_path) assert app is fakeapp.apps.basic_app app = loadapp('config:test_func.ini', relative_to=config_path, name='main') assert app is fakeapp.apps.basic_app app = loadapp('config:test_func.ini#ignored', relative_to=config_path, name='main') assert app is fakeapp.apps.basic_app def test_other(): app = loadapp('config:test_func.ini#other', relative_to=config_path) assert app is fakeapp.apps.basic_app2 def test_composit(): app = loadapp('config:test_func.ini#remote_addr', relative_to=config_path) assert isinstance(app, fakeapp.apps.RemoteAddrDispatch) assert app.map['127.0.0.1'] is fakeapp.apps.basic_app assert app.map['0.0.0.0'] is fakeapp.apps.basic_app2 def test_foreign_config(): app = loadapp(ini_file, relative_to=here, name='test_foreign_config') assert isinstance(app, fc.SimpleApp) assert app.local_conf == { 'another': 'FOO', 'bob': 'your uncle'} assert app.global_conf == { 'def1': 'a', # Note overwrite of DEFAULT value from foreign config 'def2': 'b', 'def3': 'c', 'basepath': config_path, 'glob': 'override', 'here': config_path, '__file__': os.path.join(config_path, 'test_config.ini')} def test_config_get(): app = loadapp(ini_file, relative_to=here, name='test_get') assert isinstance(app, fc.SimpleApp) assert app.local_conf == { 'def1': 'a', 'foo': 'TEST'} assert app.global_conf == { 'def1': 'a', 'def2': 'TEST', 'basepath': os.path.join(here, 'sample_configs'), 'here': config_path, '__file__': config_filename} def test_appconfig(): conf = appconfig(ini_file, relative_to=here, name='test_get') assert conf == { 'def1': 'a', 'def2': 'TEST', 'basepath': os.path.join(here, 'sample_configs'), 'here': config_path, '__file__': config_filename, 'foo': 'TEST'} assert conf.local_conf == { 'def1': 'a', 'foo': 'TEST'} assert conf.global_conf == { 'def1': 'a', 'def2': 'TEST', 'basepath': os.path.join(here, 'sample_configs'), 'here': config_path, '__file__': config_filename} def test_appconfig_filter_with(): conf = appconfig('config:test_filter_with.ini', relative_to=config_path) assert conf['example'] == 'test' def test_global_conf(): conf = appconfig(ini_file, relative_to=here, name='test_global_conf', global_conf={'def2': 'TEST DEF 2', 'inherit': 'bazbar'}) assert conf == { 'def1': 'a', # Note overwrite of DEFAULT value 'def2': 'TEST DEF 2', 'basepath': os.path.join(here, 'sample_configs'), 'here': config_path, 'inherit': 'bazbar', '__file__': config_filename, 'test_interp': 'this:bazbar', } assert conf.local_conf == { 'test_interp': 'this:bazbar'} def test_interpolate_exception(): try: appconfig('config:test_error.ini', relative_to=config_path) except Exception: e = sys.exc_info()[1] expected = "Error in file %s" % os.path.join(config_path, 'test_error.ini') assert str(e).split(':')[0] == expected else: assert False, 'Should have raised an exception' pastedeploy-2.1.0/tests/test_config_middleware.py000066400000000000000000000012071361553417100222660ustar00rootroot00000000000000import pytest from paste.deploy.config import ConfigMiddleware class Bug(Exception): pass def app_with_exception(environ, start_response): def cont(): yield b"something" raise Bug start_response('200 OK', [('Content-type', 'text/html')]) return cont() def test_error(): # This import is conditional due to Paste not yet working on py3k try: from paste.fixture import TestApp except ImportError: raise pytest.skip('unable to import TestApp') wrapped = ConfigMiddleware(app_with_exception, {'test': 1}) test_app = TestApp(wrapped) pytest.raises(Bug, test_app.get, '/') pastedeploy-2.1.0/tests/test_converters.py000066400000000000000000000007131361553417100210170ustar00rootroot00000000000000def test_asbool_truthy(): from paste.deploy.converters import asbool assert asbool('true') assert asbool('yes') assert asbool('on') assert asbool('y') assert asbool('t') assert asbool('1') def test_asbool_falsy(): from paste.deploy.converters import asbool assert not asbool('false') assert not asbool('no') assert not asbool('off') assert not asbool('n') assert not asbool('f') assert not asbool('0') pastedeploy-2.1.0/tests/test_filter.py000066400000000000000000000037121361553417100201140ustar00rootroot00000000000000from paste.deploy import loadapp from tests.fixture import * import fakeapp.apps here = os.path.dirname(__file__) def test_filter_app(): app = loadapp('config:sample_configs/test_filter.ini#filt', relative_to=here) assert isinstance(app, fakeapp.apps.CapFilter) assert app.app is fakeapp.apps.basic_app assert app.method_to_call == 'lower' def test_pipeline(): app = loadapp('config:sample_configs/test_filter.ini#piped', relative_to=here) assert isinstance(app, fakeapp.apps.CapFilter) assert app.app is fakeapp.apps.basic_app assert app.method_to_call == 'upper' def test_filter_app2(): app = loadapp('config:sample_configs/test_filter.ini#filt2', relative_to=here) assert isinstance(app, fakeapp.apps.CapFilter) assert app.app is fakeapp.apps.basic_app assert app.method_to_call == 'lower' def test_pipeline2(): app = loadapp('config:sample_configs/test_filter.ini#piped2', relative_to=here) assert isinstance(app, fakeapp.apps.CapFilter) assert app.app is fakeapp.apps.basic_app assert app.method_to_call == 'upper' def test_filter_app_inverted(): app = loadapp('config:sample_configs/test_filter.ini#inv', relative_to=here) assert isinstance(app, fakeapp.apps.CapFilter) assert app.app is fakeapp.apps.basic_app def test_filter_with_filter_with(): app = loadapp('config:sample_configs/test_filter_with.ini', relative_to=here) assert isinstance(app, fakeapp.apps.CapFilter) assert isinstance(app.app, fakeapp.apps.CapFilter) assert app.app.app is fakeapp.apps.basic_app def test_bad_pipeline(): try: app = loadapp('config:sample_configs/test_filter.ini#piped3', relative_to=here) except LookupError as err: assert 'has extra (disallowed) settings' in err.args[0] else: assert False, 'should have raised LookupError' pastedeploy-2.1.0/tests/test_load_package.py000066400000000000000000000003241361553417100212150ustar00rootroot00000000000000from pprint import pprint import sys import pkg_resources from paste.deploy.compat import print_ def test_load_package(): print_('Path:') pprint(sys.path) print_(pkg_resources.require('FakeApp')) pastedeploy-2.1.0/tox.ini000066400000000000000000000007341361553417100153700ustar00rootroot00000000000000[tox] envlist = py27, py34, py35, py36, py37, pypy, pypy3, docs [testenv] deps = # Paste works on Python 3 since Paste 2.0 Paste pytest pytest-cov commands = py.test --cov=paste/deploy --cov-report=xml --cov-report=html --cov-report=term-missing {posargs} [testenv:docs] # pin to 3.5 to match what RTD uses basepython = python3.5 whitelist_externals = make commands = make -C docs html epub BUILDDIR={envdir} "SPHINXOPTS=-W -E" extras = docs