l.s.webapp : package documentation

Part of lp.services

The webapp package contains infrastructure that is common across Launchpad that is to do with aspects such as security, menus, zcml, tales and so on.

This module also has an API for use by the application.

Module adapter No module docstring; 8/11 classes, 22/24 functions documented
Module authentication No module docstring; 2/3 classes, 2/2 functions documented
Module authorization No module docstring; 1/3 classes, 4/4 functions documented
Module batching No module docstring; 8/11 classes, 2/2 functions documented
Module breadcrumb Classes for creating navigation breadcrumbs.
Module canonicalurl Useful functions for dealing with Zope adapters.
Package doc Undocumented
Module error No module docstring; 5/12 classes documented
Module errorlog Error logging facilities.
Module escaping No module docstring; 3/3 functions documented
Module haproxy Implementation of the HAProxy probe URL.
Module initialization Initializes the application after ZCML has been processed.
Module interaction Methods dealing with interactions.
Module interfaces No module docstring; 15/19 classes, 31/38 interfaces documented
Module launchbag LaunchBag
Module login Stuff to do with logging in and logging out.
Module marshallers Undocumented
Module menu Menus and facets.
Module metazcml No module docstring; 3/11 classes, 6/12 functions, 14/15 interfaces documented
Module namespace No module docstring; 2/2 classes documented
Module notifications Browser notification messages
Module openid OpenID consumer configuration.
Module opstats XML-RPC interface for extracting real time stats from the appserver.
Module pgsession PostgreSQL server side session storage for Zope3.
Module preferredcharsets Preferred charsets.
Module publication No module docstring; 3/3 classes, 3/3 functions documented
Module publisher Publisher of objects as web pages.
Module servers Definition of the internet servers that Launchpad uses.
Module session Support for browser-cookie sessions.
Module sigdumpmem Undocumented
Module sighup Signal handler for SIGHUP.
Module sigusr1 A SIGUSR1 handler for the Launchpad Web App.
Module sigusr2 A SIGUSR2 handler for the Launchpad Web App.
Module snapshot Snapshot adapter for the Storm result set.
Module sorting This module contains sorting utility functions.
Package tests No package docstring; 24/41 modules documented
Module url Functions for working with URLs.
Module vhosts Virtual host handling for the Launchpad webapp.
Module vocabulary Vocabularies pulling stuff from the database.

From the __init__.py module:

Class GetitemNavigation Base class for navigation where fall-back traversal uses context[name].
Class StandardLaunchpadFacets The standard set of facets that most faceted content objects have.
Class ApplicationMenu Base class for application menus.
Class ContextMenu Base class for context menus.
Class FacetMenu Base class for facet menus.
Class LaunchpadView Base class for views in Launchpad.
Class LaunchpadXMLRPCView Base class for writing XMLRPC view code.
Class Navigation Base class for writing browser navigation components.
Class NavigationMenu Base class for navigation menus.
Class Utf8PreferredCharsets An IUserPreferredCharsets which always chooses utf-8.
Function canonical_name Return the canonical form of a name used in a URL.
Function canonical_url Return the canonical URL string for the object.
Class enabled_with_permission Function decorator that disables the output link unless the current
Function expand_numbers Return a copy of the string with numbers zero filled.
Function nearest Return the nearest object up the canonical url chain that provides
Class redirection A redirection is used for two related purposes.
Function sorted_dotted_numbers Sorts numbers inside strings numerically.
Function sorted_version_numbers Return a new sequence where 'newer' versions appear before 'older' ones.
Class stepthrough Add the decorated method to stepthrough traversals for a class.
Class stepto Add the decorated method to stepto traversals for a class.
Class structured Undocumented
Function urlappend Append the given path to baseurl.
Function urlparse Convert url to a str object and call the original urlparse function.
Function urlsplit Convert url to a str object and call the original urlsplit function.
def canonical_name(name):

Return the canonical form of a name used in a URL.

This helps us to deal with common mistypings of URLs. Currently only accounts for uppercase letters.

>>> canonical_name('ubuntu')
'ubuntu'
>>> canonical_name('UbUntU')
'ubuntu'
def canonical_url(obj, request=None, rootsite=None, path_only_if_possible=False, view_name=None, force_local_path=False):
Return the canonical URL string for the object.

If the canonical url configuration for the given object binds it to a particular root site, then we use that root URL.

(There is an assumption here that traversal works the same way on
different sites. When that isn't so, we need to specify the url in full in the canonical url configuration. We may want to register canonical url configuration for particular sites in the future, to allow more flexibility for traversal. I foresee a refactoring where we'll combine the concepts of sites, layers, URLs and so on.)

Otherwise, we attempt to take the protocol, host and port from the request. If a request is not provided, but a web-request is in progress, the protocol, host and port are taken from the current request.

ParametersrequestThe web request; if not provided, canonical_url attempts to guess at the current request, using the protocol, host, and port taken from the root_url given in launchpad.conf.
path_only_if_possibleIf the protocol and hostname can be omitted for the current request, return a url containing only the path.
view_nameProvide the canonical url for the specified view, rather than the default view.
force_local_pathStrip off the site no matter what.
RaisesNoCanonicalUrl if a canonical url is not available.
def nearest(obj, *interfaces):
Return the nearest object up the canonical url chain that provides one of the interfaces given.

The object returned might be the object given as an argument, if that object provides one of the given interfaces.

Return None is no suitable object is found or if there is no canonical_url defined for the object.

def expand_numbers(unicode_text, fill_digits=4):

Return a copy of the string with numbers zero filled.

>>> expand_numbers(u'hello world')
u'hello world'
>>> expand_numbers(u'0.12.1')
u'0000.0012.0001'
>>> expand_numbers(u'0.12.1', 2)
u'00.12.01'
>>> expand_numbers(u'branch-2-3.12')
u'branch-0002-0003.0012'
def sorted_dotted_numbers(sequence, key=_identity):

Sorts numbers inside strings numerically.

There are times where numbers are used as part of a string normally separated with a delimiter, frequently '.' or '-'. The intent of this is to sort '0.10' after '0.9'.

The function returns a new sorted sequence.

>>> bzr_versions = [u'0.9', u'0.10', u'0.11']
>>> for version in sorted_dotted_numbers(bzr_versions):
...   print version
0.9
0.10
0.11
>>> bzr_versions = [u'bzr-0.9', u'bzr-0.10', u'bzr-0.11']
>>> for version in sorted_dotted_numbers(bzr_versions):
...   print version
bzr-0.9
bzr-0.10
bzr-0.11
>>> class series:
...   def __init__(self, name):
...     self.name = unicode(name)
>>> bzr_versions = [series('0.9'), series('0.10'), series('0.11'),
...                 series('bzr-0.9'), series('bzr-0.10'),
...                 series('bzr-0.11'), series('foo')]
>>> from operator import attrgetter
>>> for version in sorted_dotted_numbers(bzr_versions,
...                                      key=attrgetter('name')):
...   print version.name
0.9
0.10
0.11
bzr-0.9
bzr-0.10
bzr-0.11
foo
def sorted_version_numbers(sequence, key=_identity):

Return a new sequence where 'newer' versions appear before 'older' ones.

>>> bzr_versions = [u'0.9', u'0.10', u'0.11']
>>> for version in sorted_version_numbers(bzr_versions):
...   print version
0.11
0.10
0.9
>>> bzr_versions = [u'bzr-0.9', u'bzr-0.10', u'bzr-0.11']
>>> for version in sorted_version_numbers(bzr_versions):
...   print version
bzr-0.11
bzr-0.10
bzr-0.9
>>> class series:
...   def __init__(self, name):
...     self.name = unicode(name)
>>> bzr_versions = [series('0.9'), series('0.10'), series('0.11'),
...                 series('bzr-0.9'), series('bzr-0.10'),
...                 series('bzr-0.11'), series('foo')]
>>> from operator import attrgetter
>>> for version in sorted_version_numbers(bzr_versions,
...                                       key=attrgetter('name')):
...   print version.name
0.11
0.10
0.9
bzr-0.11
bzr-0.10
bzr-0.9
foo
def urlappend(baseurl, path):

Append the given path to baseurl.

The path must not start with a slash, but a slash is added to baseurl (before appending the path), in case it doesn't end with a slash.

>>> urlappend('http://foo.bar', 'spam/eggs')
'http://foo.bar/spam/eggs'
>>> urlappend('http://localhost:11375/foo', 'bar/baz')
'http://localhost:11375/foo/bar/baz'
def urlparse(url, scheme='', allow_fragments=True):
Convert url to a str object and call the original urlparse function.

The url parameter should contain ASCII characters only. This function ensures that the original urlparse is called always with a str object, and never unicode.

>>> tuple(urlparse(u'http://foo.com/bar'))
('http', 'foo.com', '/bar', '', '', '')
>>> tuple(urlparse('http://foo.com/bar'))
('http', 'foo.com', '/bar', '', '', '')
>>> tuple(original_urlparse('http://foo.com/bar'))
('http', 'foo.com', '/bar', '', '', '')

This is needed since external libraries might expect that the original urlparse returns a str object if it is given a str object. However, that might not be the case, since urlparse has a cache, and treats unicode and str as equal. (http://sourceforge.net/tracker/index.php? func=detail&aid=1313119&group_id=5470&atid=105470)

def urlsplit(url, scheme='', allow_fragments=True):

Convert url to a str object and call the original urlsplit function.

The url parameter should contain ASCII characters only. This function ensures that the original urlsplit is called always with a str object, and never unicode.

>>> tuple(urlsplit(u'http://foo.com/baz'))
('http', 'foo.com', '/baz', '', '')
>>> tuple(urlsplit('http://foo.com/baz'))
('http', 'foo.com', '/baz', '', '')
>>> tuple(original_urlsplit('http://foo.com/baz'))
('http', 'foo.com', '/baz', '', '')
API Documentation for Launchpad, generated by pydoctor at 2018-08-21 00:00:07.