l.s.w.__init__ : module documentation

Part of lp.services.webapp

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.

Class structured Undocumented
Class ApplicationMenu Base class for application menus.
Class ContextMenu Base class for context menus.
Class enabled_with_permission Function decorator that disables the output link unless the current
Class FacetMenu Base class for facet menus.
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 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.
Function nearest Return the nearest object up the canonical url chain that provides
Class redirection A redirection is used for two related purposes.
Class stepthrough Add the decorated method to stepthrough traversals for a class.
Class stepto Add the decorated method to stepto traversals for a class.
Function expand_numbers Return a copy of the string with numbers zero filled.
Function sorted_dotted_numbers Sorts numbers inside strings numerically.
Function sorted_version_numbers Return a new sequence where 'newer' versions appear before 'older' ones.
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.
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.
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 2022-06-16 00:00:12.