This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Overview

plone.subrequest provides a mechanism for issuing subrequests under Zope2.

Installation

Plone 4

An entry point is provided so no special installation is required past adding plone.subrequest to your instance’s eggs.

Zope 2.12 without Plone

Load this package’s ZCML in the usual manner.

Zope 2.10

You must install ZPublisherEventsBackport to use this package with Zope 2.10 and load both package’s ZCML. The tests require Zope 2.12 / Python 2.6 so will not run.

Usage

Basic usage

Call subrequest(url), it returns a response object.

>>> from plone.subrequest import subrequest
>>> response = subrequest('/folder1/@@url')
>>> response.getBody()
'http://nohost/folder1'

response.getBody() also works for code that calls response.write(data).

>>> response = subrequest('/@@response-write')
>>> response.getBody()
'Some data.\nSome more data.\n'

But in this case response.getBody() may only be called once.

>>> response.getBody()
Traceback (most recent call last):
    ...
ValueError: I/O operation on closed file

Accessing the response body as a file

Some code may call response.write(data).

>>> response = subrequest('/@@response-write')

In which case you may access response.stdout as file.

>>> response.stdout.seek(0, 0)
>>> list(response.stdout)
['Some data.\n', 'Some more data.\n']

You can test whether a file was returned using response._wrote.

>>> response._wrote
1

When you’re done, close the file:

>>> response.stdout.close()

Use response.outputBody() to ensure the body may be accessed as a file.

>>> from plone.subrequest import subrequest
>>> response = subrequest('/folder1/@@url')
>>> response._wrote
>>> response.outputBody()
>>> response._wrote
1
>>> response.stdout.seek(0, 0)
>>> list(response.stdout)
['http://nohost/folder1']

Relative paths

Relative paths are resolved relative to the parent request’s location:

>>> request = traverse('/folder1/@@test')
>>> response = subrequest('folder1A/@@url')
>>> response.getBody()
'http://nohost/folder1/folder1A'

This takes account of default view’s url.

>>> request = traverse('/folder1')
>>> request['URL'] == 'http://nohost/folder1/@@test'
True
>>> response = subrequest('folder1A/@@url')
>>> response.getBody()
'http://nohost/folder1/folder1A'

Virtual hosting

When virtual hosting is used, absolute paths are traversed from the virtual host root.

>>> request = traverse('/VirtualHostBase/http/example.org:80/folder1/VirtualHostRoot/')
>>> response = subrequest('/folder1A/@@url')
>>> response.getBody()
'http://example.org/folder1A'

Specifying the root

You may also set the root object explicitly

>>> app = layer['app']
>>> response = subrequest('/folder1A/@@url', root=app.folder1)
>>> response.getBody()
'http://nohost/folder1/folder1A'

Error responses

Subrequests may not be found.

>>> response = subrequest('/not-found')
>>> response.status
404

Or might raise an error.

>>> response = subrequest('/@@error')
>>> response.status
500

So check for the expected status.

>>> response = subrequest('/')
>>> response.status == 200
True

Handling subrequests

The parent request is set as PARENT_REQUEST onto subrequests.

Subrequests also provide the plone.subrequest.interfaces.ISubRequest marker interface.

Changelog

1.8 (2016-11-01)

New features:

  • Provide an exception-handler for rewriting Unauthorized to 401’s. [jensens]

1.7.0 (2016-05-04)

New:

  • Allow to pass a custom exception handler for the response. [jensens]

Fixes:

  • When a subrequest modified the DB (or prior to the subrequest the main request), the oids annotated to the requests were doubled with each subsequent subrequest. This resulted in out-of-memory errors when using lots of subrequests, such as it happens on Mosaic based sites with a certain amount of tiles. Fixed by only adding new oids, not already known by parent request. [jensens]
  • Housekeeping: isort imports, autopep8, minor manual cleanup (no zope.app. imports). [jensens]

1.6.11 (2015-09-07)

  • propagate IDisableCSRFProtection interface on subrequest to parent request object [vangheem]

1.6.10 (2015-08-14)

  • propagate registered safe writes from plone.protect to parent request object. [vangheem]

1.6.9 (2015-03-21)

  • Workaround for broken test because of missing dependency declaration in upstream package, see https://github.com/plone/plone.app.blob/issues/19 for details. [jensens]
  • Housekeeping and code cleanup (pep8, et al). [jensens]
  • Fix issue where new cookies from the main request.response are not passed to subrequests. [datakurre]
  • normalise request path_info so that string indexing works properly. [gweiss]

1.6.8 (2014-03-04)

  • Handle sub-requests which contain a doubled // in the path. [gweis]

1.6.7 (2012-10-22)

  • Ensure correct handling of bare virtual hosting urls. [elro]

1.6.6 (2012-06-29)

  • Log errors that occur handling a subrequest to help debug plone.app.theming errors including content from a different url [anthonygerrard]

1.6.5 (2012-04-15)

  • Ensure parent url is a string and not unicode. [davisagli]

1.6.4 - 2012-03-22

  • Fix problems with double encoding some unicode charse by not copying too many other variables. [elro]

1.6.3 - 2012-02-12

  • Copy other request variables such as LANGUAGE to subrequest. [elro]

1.6.2 - 2011-07-04

1.6.1 - 2011-07-04

  • Move tests to package directory to making testing possible when installed normally.

1.6 - 2011-06-06

  • Ensure url is a string and not unicode. [elro]

1.6b2 - 2011-05-20

  • Set PARENT_REQUEST and add ISubRequest interface to subrequests. [elro]

1.6b1 - 2011-02-11

  • Handle IStreamIterator. [elro]
  • Simplify API so response.getBody() always works. [elro]

1.5 - 2010-11-26

  • Merge cookies from subrequest response into parent response. [awello]

1.4 - 2010-11-10

  • First processInput, then traverse (fixes #11254) [awello]

1.3 - 2010-08-24

  • Fixed bug with virtual hosting and quoted paths. [elro]

1.2 - 2010-08-16

  • Restore zope.component site after subrequest. [elro]

1.1 - 2010-08-14

  • Virtual hosting, relative url and error response support. [elro]

1.0 - 2010-07-28

  • Initial release. [elro]
Release History

Release History

1.8

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.7.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.6.11

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.6.10

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.6.9

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.6.8

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.6.7

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.6.6

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.6.5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.6.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.6.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.6.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.6.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.6

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.6b2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.6b1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
plone.subrequest-1.8.tar.gz (21.6 kB) Copy SHA256 Checksum SHA256 Source Nov 1, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting